Codeforces Round 1047 (Div. 3) Upsolving (finished)