I have done this problem and got AC when i did not include the staments for fast i/o operations :- ios_base::sync_with_stdio(false);cin.tie(NULL);
after i included the above statement i got WA.
Please help me out .
Link to submission :- AC submission (without statement)