While I was solving problem, I have encountered this problem: https://www.acmicpc.net/problem/17111
(Description is written in English, so you can see it.)
How can I solve this problem? I do not have any idea of solving it, and thought that Codeforces community is helpful.