I am solving this question from codeforces…
https://codeforces.com/problemset/problem/1315/B
This is my solution… I thought it won’t generated Memory limit excedded error…
https://codeforces.com/problemset/submission/1315/96348998
Please check this…
Getting error in submission
Hoogaya accept …
Sorry… I am repeating the same mistake…