Help me out in this problem

https://cses.fi/problemset/task/1746
can anyone tell me how to approach this with recursion??