Hi,

I was working on white-sheet from code forces and I used a brute-force method to solve the problem. I wasn’t really sure how to create a faster algorithm, to solve the problem. I was hoping someone could help me with that or give me a hint on how to solve the problem. My algorithm is O(n^2) right now.

**Problem Link**: Problem - C - Codeforces

Thanks.