Problem Link:- https://mirror.codeforces.com/contest/1355/problem/C My submission:- https://mirror.codeforces.com/contest/1355/submission/80683918
I have tried my best to cover up all cases I am considering via comments in my code. Thanks in advance!!!