Difference in online output and output on my local system

https://codeforces.com/contest/1217/problem/C

my submission: https://codeforces.com/contest/1217/submission/60127372

code is giving correct output for testcases on my local system but it fails on submission.
any help is highly appreciated.