17. (2004 China Southeast Mathematical Olympiad) Given a positive integer $n$ greater than 2004, fill the numbers $1, 2, 3, \cdots, n^2$ into an $n \times n$ chessboard (composed of rows and columns of squares) such that each square contains exactly one number. If a number in a square is greater than at least 2004 numbers in its row and at least 2004 numbers in its column, then this square is called an "excellent square". Find the maximum number of "excellent squares" on the chessboard.
17. For the convenience of narration, if a number in a cell is greater than the numbers in at least 2004 other cells in its row, then this cell is called row-dominant. Since the 2004 smallest numbers in each row are not row-dominant, there are \( n-2004 \) row-dominant cells in each row. A cell is a "dominant cell" if it is row-dominant, so the number of "dominant cells" on the chessboard is no more than \( n(n-2004) \).

On the other hand, fill the cells in the \( i \)-th row (for \( i=1,2,3, \cdots, n \)) and the \( i, i+1, \cdots, i+2003 \) (take the remainder when greater than \( n \) modulo \( n \)) columns with " * ". Fill the numbers \( 1,2,3, \cdots, 2004 n \) into the cells with " * ", and fill the remaining numbers into the cells without " * ". The numbers in the cells without " * " are greater than any number in the cells with " * ", so all the cells without " * " are "dominant cells", totaling \( n(n-2004) \).

At this point, each row has 2004 cells with " * ", and each column also has 2004 cells with " * ", as shown in the figure below. In fact, when \( 1 \leqslant i \leqslant 2003 \), the \( i \)-th column has " * " in the rows \( 1,2, \cdots, i, n+i-2003, n+i-2002, \cdots, n \). When \( i \leqslant 2004 \), the \( i \)-th column has " * " in the rows \( i-2003, i-2002, \cdots, i \), so each row has 2004 cells with " * ", and each column also has 2004 cells with " * ". Therefore, the maximum number of "dominant cells" on the chessboard is \( n(n-2004) \).