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