Codeforces 877D

codeforces

#1

Can Anybody give a better explanation to this problem http://codeforces.com/contest/877/problem/D