http://codeforces.com/contest/337/submission/5920476 : Accepted