Codechef Jan 2017 long challenge "CapitalMove"
Is there a way to solve this problem other than brute force!!
Codeforces Round 1098 Solution Discussion