http://www.e-olimp.com/ua/problems/314