Let be a grid of squares. The rows of have distinct labels taken from the set , and the columns of have distinct labels taken from the set .
An is placed in each position of the grid where the row and column have the same label. For each in the grid, a line segment is drawn connecting it to any other that is in an adjacent row or an adjacent column, or both.
Over all possible labeling of the rows and columns, what is the largest number of distinct lines segments that can be drawn by this process?
Details and assumptions
The row labels are distinct from each other, but not distinct from the column labels.
As an explicit example, if we have a grid and label the rows and columns as follows, we will place 's as such:
This will result in 5 line segments being drawn. Note that the labelled with and the labelled with will not have a line segment drawn between them, as they are neither in an adjacent row, nor in an adjacent column. All the other pairs of 's will have a line segment drawn between them.