Painter problem

all the testcases are showing wrong answer.pls tell the correct code.