Not all testcases passing

https://codeforces.com/contest/858/problem/D