When I was in a lecture, my students tried to troll me and asked the question that was banned from codeforces because of being NP hard. I did not know anything about that problem and I have tried to solve it. I struggled a lot but finally, I solved the problem in O($$$N*N$$$) complexity. I will not share my full solution because I do not want to give opportunities to people who will use this solution for bad ideas. I know you will not believe me but I will share some pictures while I was solving the problem. (It is up to you to believe...) (Also I do not believe that the world is a fair place, so I know I will not gain anything if I share my solution because I am a Turkish person and it is sad, but many of the population of the world do not love Turkish people.)