Codeforces, round 221, task C
codeforces round 180, task C