[Qualifying round of the Championship of the North-West of Russia and Moscow ICPC 2019](https://codeforces.com/gym/102375) problem link: [https://codeforces.com/gym/102375/problem/J](https://codeforces.com/gym/102375/problem/J)