dont worry dude curiosity is always good its a great community out here
well i just corrected your solution so you understand what YOU did wrong, i didnot try to make it the a fully correct one.
Here is the full solution : Solution: 43324840 | CodeChef
If you read the thread i mentioned above, you can read about what subtasks are and why they are provided, so go read that first.
Now, if you look at the constraints given,
1 <= T <= 10^5
1 <= N <= 10^6
for subtask 1,
1 <= T, N <= 25
now you see, your solution required you to do all the operations over every element of an array over all test cases.
so your time complexity is O(T * N).
T * N = 10^11
Python takes 5 sec to run 10^8 operations (this is taken as the standard, but im sure it does more), meaning your code in the worst case would take 10^11 / 10^8 s or 1000s.
but for the subtask, it will take 25 * 25 = 625 operations <<< 10^8, so pretty much no time needed. This allows the first and second cases to get accepted, since they have lower input numbers.
Now, 1000s is CLEARLY greater than 5s which is the time limit. Hence the TLE(Time Limit Exceeded).
Now it is time to improve the solution, which will just take basic observation.
If you see, the numbers donot change for the same input(meaning if N = 3, numbers will always be 1, 2, 3)
so if you start from the beginning, and perform the operations on the first 2 elements and so on, the answer will proceed this way.
1 * 2 + 1 + 2 = 5.
5 * 3 + 5 + 3 = 23
therefor for N = 3, your ans is 23. Remember this.
Now for N = 4, you get 1, 2, 3, 4
so 1 * 2 + 1 + 2 = 5
5 * 3 + 5 + 3 = 23
and now 23 * 4 + 23 + 4 = 119
although this took you 3 operations, you can see that the answer of 3 came somewhere in the solution of 4. This will always be true.
The solution for N will always be the solution of N-1 * n + n-1 + n
This is called DP(Dynamic Programing), where you store the solutions to previous questions to calculate the subsequent answers.
Now using this method, you can simply first calculate the solution for every number from 1 to 10^6+1(since 1 <= N <= 10^6), and then simply return the corresponding solution to whatever the test case asks.
You can look at my solution for how its done. Dont be afraid of asking for any clarification if needed
Hope this helps,