Codeforces-1006B-Polycarp-s-Practice Link: https://codeforces.com/problemset/problem/1006/B Algorithm