codeforces; solve "Petya and Strings" from Beta Round #85 (Div. 2)