Testcases for this question seems to be broken. I tried few times and unable to get the correct answer.
Then I copy pasted TESTER’s(link) solution(link) to check the same and still WA.
Please check the same.
The test cases are okay. However the tester’s solution is wrong.
Tester’s solution used “%d” format specifier and converts the elements to int while printing it.
But during the operations, the value of A[i] can be greater than INT_MAX. For example, see the comment by @betlista in the following link.
https://discuss.codechef.com/questions/42550/rrstone-editorial
So, just change the “%d” format specifier to “%lld” and do not type cast the elements to int.
I changed the tester’s solution, to get AC. See the following link for the correct tester’s code.