codeforces; solve "Towers" from Round #274 (Div. 2)