https://codeforces.com/contest/1705/problem/D