Codeforces problem: Alternate thinking

Can someone please help stating the recursive approach for this problem.