The solution was much simpler than what I expected, I should just accept that some problems is just brute force...
Just my solution for some beecrowd problems.