Getting runtime error

Hello …
I am doing this question from codeforces…
https://codeforces.com/problemset/problem/362/B
I have come with the solution… But it is showing runtime error…
Not able to find where it is wrong.
Please look at this solution…
https://codeforces.com/contest/362/submission/98240618
Thanks