help to solve problem

can anyone help me to solve this problem???
http://www.e-olimp.com/en/problems/3239

//