Let $n \geq 2$ be an integer. Switzerland and Liechtenstein are performing their annual festive show. There is a field divided into $n \times n$ squares, in which the bottom-left square contains a red house with $k$ Swiss gymnasts, and the top-right square contains a blue house with $k$ Liechtensteiner gymnasts. Every other square only has enough space for a single gymnast at a time. Each second either a Swiss gymnast or a Liechtensteiner gymnast moves. The Swiss gymnasts move to either the square immediately above or to the right and the Liechtensteiner gymnasts move either to the square immediately below or to the left. The goal is to move all the Swiss gymnasts to the blue house and all the Liechtensteiner gymnasts to the red house, with the caveat that a gymnast cannot enter a house until all the gymnasts of the other nationality have left. Determine the largest $k$ in terms of $n$ for which this is possible. 

1. **Determine the largest possible value of \( k \) for which the goal is achievable:**

   The largest possible value is \( k = (n-1)^2 \). This is achievable because the \((n-1)^2\) squares in the top-left portion of the grid can contain all \((n-1)^2\) Liechtensteiner gymnasts while the Swiss gymnasts enter the blue house (one at a time) by moving along the empty squares.

2. **Consider \( k > (n-1)^2 \):**

   Without loss of generality (WLOG), assume the first gymnast to enter a new house is Swiss. To reach the goal, there must be a point in time where all \( k \) Liechtensteiner gymnasts are in neither house. This must occur before the first Swiss gymnast enters the blue house. Furthermore, all \( k \) Swiss gymnasts must leave the red house before any of the Liechtensteiner gymnasts can enter.

3. **Claim:**

   Suppose some Swiss gymnast leaves the red house while all \( k \) Liechtensteiner gymnasts are in neither house. Then, as long as the red house is not empty, it is impossible for this gymnast to reach the blue house.

   **Proof:**

   Since none of the Liechtensteiner gymnasts can enter the red house, there are at most 
   \[
   (n^2 - 2) - k \le 2n - 4
   \]
   unoccupied squares on the grid. 

   Since all paths from the red house to the blue house require \( 2(n-1) \) moves, any Swiss gymnast must pass through \( 2n-3 \) unoccupied squares along the way. This is a contradiction because there are not enough unoccupied squares for the Swiss gymnast to reach the blue house. Hence, the claim follows. 

4. **Define the set \( T \):**

   Let \( T \) denote the set containing all \( k \) Liechtensteiner gymnasts and all Swiss gymnasts that were still in the red house right after the last Liechtensteiner gymnast left the blue house. Because no Swiss gymnast can enter the blue house until all \( k \) Liechtensteiner gymnasts have exited, there are at least 
   \[
   k - [(n^2 - 2) - k] = 2k + 2 - n^2
   \]
   Swiss gymnasts in \( T \).

5. **Analyze the set \( T \):**

   No gymnasts in \( T \) can enter a new house until all Swiss gymnasts in the set have exited the red house. This implies that at some point in time, there must have been no gymnasts in \( T \) inside a house. Therefore, 
   \[
   |T| \le n^2 - 2
   \]
   must hold. Hence, 
   \[
   n^2 - 2 \ge |T| \ge k + (2k + 2 - n^2) = 3k + 2 - n^2
   \]
   must hold. Substituting \( k = (n-1)^2 \), we get:
   \[
   n^2 - 2 \ge 3(n-1)^2 + 2 - n^2
   \]
   Simplifying, we get:
   \[
   n^2 - 2 \ge 3(n^2 - 2n + 1) + 2 - n^2
   \]
   \[
   n^2 - 2 \ge 3n^2 - 6n + 3 + 2 - n^2
   \]
   \[
   n^2 - 2 \ge 2n^2 - 6n + 5
   \]
   \[
   0 \ge n^2 - 6n + 7
   \]
   This is a contradiction because \( n^2 - 6n + 7 \) is always positive for \( n \ge 2 \). Therefore, the goal is impossible for \( k > (n-1)^2 \).

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