Need help with the question

https://codeforces.com/contest/1103/problem/B
Can anyone tell me approach for the question

You can follow the tutorial. Its always the best way to understand. :slight_smile: