codeforces; solve "Dreamoon and WiFi" from Round #272 (Div. 2)