Codeforcess Round #788 (Div. 2) Problem B.

Here is the problem link.

I have used O(n) complexity code in my code, but I got TLE on test 35.

While my friend during the contest solved the problem has a total number of test cases 34.

This is my submission and I got TLE on test case no. 35.

And this is the last case for my friend's submission.

What is the problem??