An interesting problem from Codeforces Beta Round #93
Hi, guys! I wonder if someone could explain to me the solution of http://codeforces.me/contest/126/problem/D.