Here is the solution link.
https://codeforces.net/contest/1798/submission/201240362
But suddenly Codeforces was giving "wrong output format Unexpected end of file — int32 expected (test case 4481)". I'm not familiar with this. Can anyone plz explain it ??
It means exactly what is says:
This is one test case where your code fails:
Your code outputs nothing for the above test case. Can you see why this happens? I can help you more if you can't find the cause of this.
Thanks a lot. I've got my mistake.
I wrote "return 0" in the loop instead of "break".