Can anyone explain the logic behind this problem ?
(https://atcoder.jp/contests/abc196/tasks/abc196_d)
CodeChef Starters 136 Solution Discussion
CF Edu Round 166 Solution Discussion