codeforces; solve "String Task" from Beta Round #89 (Div. 2)