codeforces; solve "Team" from Round #143 (Div. 2)