logic behind this problem anya and the ghosts
link to the problem:-https://codeforces.me/contest/508/problem/C
please explain the logic behind this problem.
ICPC NA North Central and South Division