Solution:
To find an appropriate estimate, we will lower bound the number of rectangles. Let P(R) be the probability a random 3 by 4 grid will have a rectangle with all the same color in the grid. Let P(r) be the probability that a specific rectangle in the grid will have the same color. Note P(r)=343=271. Observe that there are (24)(23)=18 rectangles in the grid. Hence, we know that P(R)≤18⋅P(r)=2718=32. Thus, 1−P(R), the probability no such rectangle is in the grid, is at most 31. This implies that our answer should be at least 3312=311, which is enough for around half points. Closer estimations can be obtained by using more values of Inclusion-Exclusion.
n}=
cnt = 0
for i in range( }3**(3*n))
mask = i
a= [[], [], []]
for x in range(3):
for y in range(n):
a[x].append(mask % 3)
mask //= 3
pairs = [set() for i in range(3)]
works = True
for i in range(n):
for j,k in [(0,1), (0,2), (1,2)]:
if a[j]* == a[k]*:
if (j,k) in pairs[a[j]*]:
works = False
else:
pairs[a[j]*].add((j , k))
if works:
cnt += 1
print(cnt)