codeforces; solve "HQ9+" from Beta Round #96 (Div. 2)