Let us index the unit squares of the board by pairs of integers (a,b) with 1≤a,b≤2n. We prove that the largest possible number of pretty sets is n4.
For the upper bound, consider coloring all the unit squares (a,b) with a,b≤n or a,b≥n+1 blue, and all the other unit squares red. It is straightforward to verify that this coloring yields n4 pretty sets. Thus we are left with proving that no coloring yields more pretty sets.
Call an unordered pair of distinct unit squares {A,B} *mixed* if A and B are in the same row and A and B have different colors. Clearly, if a row contains a blue squares and b red squares (a+b=2n), then it contains ab≤n2 mixed pairs. Therefore, there are at most 2n3 mixed pairs in total.
Let every mixed pair {A,B} *charge* the unordered pair {i,j} of distinct columns such that A is in column i and B is in column j. Denote by charge(i,j) the number of times the pair of columns {i,j} is charged.
Obviously, every pair of columns is charged at most 2n times, i.e., charge(i,j)≤2n. Moreover, since there are at most 2n3 mixed pairs in total, we have ∑{i,j}charge(i,j)≤2n3 where the summation is over pairs of distinct columns {i,j}.
Observe that if a pair of distinct columns {i,j} is charged k=charge(i,j) times, then there are at most 4k2 pretty sets with squares contained in these columns. This is because for some a,b with a+b=k there are a red-blue and b blue-red mixed pairs within these columns, yielding ab≤4k2 pretty sets. Therefore, the total number of pretty sets is at most
41{i,j}∑charge(i,j)2≤2n⋅{i,j}∑charge(i,j)≤n4,
where again the summation is over unordered pairs of distinct columns. This concludes the proof. □