The Question is -> https://codeforces.net/contest/2013/problem/D
My approach is as follows :
My Approach
If someone could help me out it would be greatly appreciated.
My submission for ref -> https://codeforces.net/contest/2013/submission/297131396
Thanks!!