A square paper of side $n$ is divided into $n^2$ unit square cells. A maze is drawn on the paper with unit walls between some cells in such a way that one can reach every cell from every other cell not crossing any wall. Find, in terms of $n$, the largest possible total length of the walls.
1. **Understanding the Problem:**
   - We have a square paper of side length \( n \), divided into \( n^2 \) unit square cells.
   - A maze is drawn with unit walls between some cells.
   - The maze must be such that one can reach every cell from every other cell without crossing any wall.
   - We need to find the largest possible total length of the walls in terms of \( n \).

2. **Graph Theory Interpretation:**
   - Consider the \( n \times n \) grid as a graph where each cell is a vertex.
   - Each edge between vertices represents a potential wall.
   - The condition that one can reach every cell from every other cell implies that the graph must be connected.

3. **Minimum Spanning Tree (MST):**
   - To ensure the graph is connected with the maximum number of walls, we need to consider the concept of a Minimum Spanning Tree (MST).
   - An MST of a graph with \( n^2 \) vertices has \( n^2 - 1 \) edges.
   - The total number of possible edges in the \( n \times n \) grid is \( 2n(n-1) \) (each cell has 2 potential walls: right and down).

4. **Calculating the Maximum Number of Walls:**
   - The maximum number of walls is the total number of possible edges minus the number of edges in the MST.
   - Total possible edges: \( 2n(n-1) \).
   - Edges in the MST: \( n^2 - 1 \).

   Therefore, the maximum number of walls is:
   \[
   2n(n-1) - (n^2 - 1)
   \]

5. **Simplifying the Expression:**
   \[
   2n(n-1) - (n^2 - 1) = 2n^2 - 2n - n^2 + 1 = n^2 - 2n + 1 = (n-1)^2
   \]

6. **Conclusion:**
   - The largest possible total length of the walls is \( (n-1)^2 \).

The final answer is \( \boxed{ (n-1)^2 } \)