Problem - 883K - Codeforces

Can anyone explain the logic behind this problem?