codeforces; solve "Queue at the School" from Round #163 (Div. 2)