Thank you!
Can someone tell me how to solve B? I think I almost get it, yet I can't arrive at a full-fledged reasoning.
Codeforces Round 1094 Solution Discussion