Solved problem A in contest Codeforces Round #284 (Div. 2)