Can anyone explain the logic behind this problem ?
(https://atcoder.jp/contests/abc196/tasks/abc196_d)