Can anyone explain the logic behind this problem ?
(https://atcoder.jp/contests/abc196/tasks/abc196_d)
Codeforces Round 952 Solution Discussion
CodeChef Starters 128 Solution Discussion