5. Given a positive integer $n$ greater than 2004, fill the numbers $1,2,3, \cdots, n^{2}$ into an $n \times n$ chessboard (consisting of $n$ rows and $n$ columns of squares) such that each square contains exactly one number. If a square contains a number that is greater than the numbers in at least 2004 squares in its row and at least 2004 squares in its column, then this square is called a “good square”. Find the maximum number of “good squares” on the chessboard.
5. 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 in each row, the 2004 cells with the smallest numbers are not row-dominant, there are \( n-2004 \) cells in each row that are row-dominant. A cell that is "dominant" must be 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 (where \( 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 \( 2004 n \) cells with "*", and fill the numbers \( 2004 n+1, 2004 n+2, 2004 n+3, \cdots, n^2 \) into the cells without "*". Then, the numbers in the cells without "*" are all greater than the numbers in the cells with "*", so all the cells without "*" are "dominant", totaling \( n(n-2004) \) cells.
At this time, each row has 2004 cells with "*", and each column also has 2004 cells with "*". As shown in the figure.
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 \geqslant 2004 \), the \( i \)-th column has "*" in the rows \( i-2003, i-2002, \cdots, i \). Therefore, each row has 2004 cells with "*", and each column also has 2004 cells with "*". Thus, the maximum number of "dominant" cells on the chessboard is \( n(n-2004) \).