Topcoder SRM 674
https://community.topcoder.com/tc?module=MatchDetails&rd=16624
Codeforces Round 1137 Solution Discussion