Painter problem

my code is running on given test case but giving wrong answer on hidden test cases.I have also tried to return the answer 10^7+3 but still not working.What to do?

Pls share your code by saving on ide so tht I could check it…