It doesn’t work like this, simply throwing out the code and asking to find the error. You could have simply given the link to your submission, for that matter. You are expected to tell what you tried, and what is your question accordingly.
However the idea was to choose 2 numbers from all numbers, and subtract the combinations that you can get when you choose 2 numbers from all such numbers whose magnitude is 2. So, if gt represents number of numbers greater than 2, and t represents number of numbers equal to 2, then (gt + t) C 2 - t C 2 will be the answer, i.e. e*(e-1)/2 - t*(t-1)/2 where e = gt + t
I tested your code on most test simple test cases and it worked fine. The mistake in your code is that the value of n can be upto 10^5 so n * (n-1 ) will be around 10^10 which will exceed the range of int data type. I would suggest you replace int by long long and submit.
P.S. Using o as a variable is a heinous crime !! It becomes very difficult to differentiate between 0 and o making debugging hard.
Can you retry writing std::ios_base::sync_with_stdio(false) as the first line in main. There are 3 major reasons for time out I have encountered. Incorrect condition in loop (for, while), non-converging condition in some special case of recursion and slow IO. My suggestion would try to handle third case that I suspect.