Each of the $n^2$ cells of an $n \times n$ grid is colored either black or white. Let $a_i$ denote the number of white cells in the $i$-th row, and let $b_i$ denote the number of black cells in the $i$-th column. Determine the maximum value of $\sum_{i=1}^n a_ib_i$ over all coloring schemes of the grid.

[i]Proposed by Alex Zhai[/i]
1. **Understanding the Problem:**
   We are given an \( n \times n \) grid where each cell is either black or white. We need to maximize the sum \( \sum_{i=1}^n a_i b_i \), where \( a_i \) is the number of white cells in the \( i \)-th row and \( b_i \) is the number of black cells in the \( i \)-th column.

2. **Rearrangement Inequality:**
   The rearrangement inequality states that for two sequences \( a_1 \geq a_2 \geq \cdots \geq a_n \) and \( b_1 \geq b_2 \geq \cdots \geq b_n \), the sum \( \sum_{i=1}^n a_i b_i \) is maximized when the sequences are similarly ordered. This means that to maximize \( \sum_{i=1}^n a_i b_i \), we should arrange the sequences \( a_i \) and \( b_i \) in non-increasing order.

3. **Top-Heavy Grid:**
   We can transform any grid into a "top-heavy" grid where the row and column lists are non-increasing. This transformation does not change the sum \( \sum_{i=1}^n a_i b_i \) because it only involves rearranging rows and columns.

4. **Induction Hypothesis:**
   We will use induction to prove that the maximum value of \( \sum_{i=1}^n a_i b_i \) is \( 2 \binom{n+1}{3} \).

   - **Base Case:**
     For \( n = 1 \), the grid is a single cell which can be either black or white. In both cases, \( \sum_{i=1}^1 a_i b_i = 0 \). This matches \( 2 \binom{2}{3} = 0 \).

   - **Induction Step:**
     Assume that for an \( (n-1) \times (n-1) \) grid, the maximum value of \( \sum_{i=1}^{n-1} a_i b_i \) is \( 2 \binom{n}{3} \). We need to show that for an \( n \times n \) grid, the maximum value is \( 2 \binom{n+1}{3} \).

5. **Maximizing \( a_1 \) and \( b_1 \):**
   Consider the top-heavy grid where \( a_1 \geq a_2 \geq \cdots \geq a_n \) and \( b_1 \geq b_2 \geq \cdots \geq b_n \). To maximize \( \sum_{i=1}^n a_i b_i \), we should maximize \( a_1 \) and \( b_1 \).

   - The maximum value of \( a_1 \) is \( n \) (all cells in the first row are white).
   - The maximum value of \( b_1 \) is \( n-1 \) (all cells in the first column except one are black).

6. **Calculating the Sum:**
   - The contribution from the first row and first column is \( a_1 b_1 = n \cdot (n-1) = n^2 - n \).
   - The remaining grid is an \( (n-1) \times (n-1) \) grid, which by the induction hypothesis has a maximum sum of \( 2 \binom{n}{3} \).

   Therefore, the total maximum sum is:
   \[
   S(G) = n^2 - n + 2 \binom{n}{3}
   \]

7. **Simplifying the Expression:**
   \[
   2 \binom{n}{3} = 2 \cdot \frac{(n-1)(n-2)}{2} = (n-1)(n-2)
   \]
   \[
   S(G) = n^2 - n + (n-1)(n-2)
   \]
   \[
   S(G) = n^2 - n + n^2 - 3n + 2
   \]
   \[
   S(G) = 2n^2 - 4n + 2
   \]
   \[
   S(G) = 2 \left( \frac{n(n+1)(n-1)}{3} \right) = 2 \binom{n+1}{3}
   \]

Thus, the maximum value of \( \sum_{i=1}^n a_i b_i \) is \( 2 \binom{n+1}{3} \).

The final answer is \( \boxed{ 2 \binom{n+1}{3} } \)