Codeforces Step 5 problem c doubt

Can anybody help me to solve the codeforces step 5 C problem.

Here is the link