Can you help me find the logic? Thanks in advance!!
_
CF Edu Round 166 Solution Discussion
Codeforces Round 949 Solution Discussion