Suppose each point in Z X Z is colored with one of n given colors.

Find the Smallest k and l such that in any k x l grid one is guaranteed to find four monochromatic points that are vertices of a rectangle.

For the case of n=1, smallest (k,l) would be obviously (2,2)

For the case of n=2, I had found 4 X 4 colored grid which still not making any monochromatic rectangle :

$baba\aabb\abaa\bbab $

Is there any computational way to make it automatically searched?

I need your advice

(I only knows python for reference)