codeforces; solve "Way Too Long Words" from Beta Round #65 (Div. 2)