There are $n$ boxes $A_1, ..., A_n$ with non-negative number of pebbles inside it(so it can be empty). Let $a_n$ be the number of pebbles in the box $A_n$. There are total $3n$ pebbles in the boxes. From now on, Alice plays the following operation.

In each operation, Alice choose one of these boxes which is non-empty. Then she divide this pebbles into $n$ group such that difference of number of pebbles in any two group is at most 1, and put these $n$ group of pebbles into $n$ boxes one by one. This continues until only one box has all the pebbles, and the rest of them are empty. And when it's over, define $Length$ as the total number of operations done by Alice.

Let $f(a_1, ..., a_n)$ be the smallest value of $Length$ among all the possible operations on $(a_1, ..., a_n)$. Find the maximum possible value of $f(a_1, ..., a_n)$ among all the ordered pair $(a_1, ..., a_n)$, and find all the ordered pair $(a_1, ..., a_n)$ that equality holds.
1. **Initial Setup and Definitions:**
   - We have \( n \) boxes \( A_1, A_2, \ldots, A_n \) with non-negative numbers of pebbles.
   - Let \( a_i \) be the number of pebbles in box \( A_i \).
   - The total number of pebbles is \( 3n \).
   - Alice performs operations where she redistributes pebbles from a non-empty box into \( n \) groups such that the difference in the number of pebbles between any two groups is at most 1.
   - The goal is to find the maximum possible value of \( f(a_1, \ldots, a_n) \), the smallest number of operations needed to end with all pebbles in one box.

2. **Key Observations:**
   - The final configuration will have all \( 3n \) pebbles in one box, say \( A_n \), and all other boxes empty.
   - At each step, the box \( A_n \) (the box that will eventually contain all pebbles) will receive either 1 or 2 pebbles.
   - For \( A_n \) to receive 3 pebbles in one operation, some box \( A_j \) must have at least \( 2n+1 \) pebbles, which is impossible since the total number of pebbles is \( 3n \).

3. **Upper Bound Construction:**
   - Consider the initial configuration \( (3, 3, \ldots, 3) \).
   - We will show that \( f(3, 3, \ldots, 3) \leq 3n - 4 \).

4. **Step-by-Step Construction:**
   - **Step 1:** Use \( n-3 \) operations to redistribute pebbles such that \( a_1 = a_2 = \ldots = a_{n-3} = 0 \) and \( a_{n-2} = a_{n-1} = a_n = n \).
   - **Step 2:** Use one operation to redistribute pebbles from \( A_{n-2} \) such that \( a_1 = a_2 = \ldots = a_{n-2} = 1 \) and \( a_{n-1} = a_n = n+1 \).
   - **Step 3:** Use one operation to redistribute pebbles from \( A_{n-1} \) such that \( a_1 = a_2 = \ldots = a_{n-2} = 2 \), \( a_{n-1} = 1 \), and \( a_n = n+3 \).
   - **Step 4:** Each subsequent operation will add one pebble to \( A_n \). We need \( 3n - (n+3) = 2n - 3 \) more operations.
   - **Total Operations:** \( (n-3) + 1 + 1 + (2n-3) = 3n - 4 \).

5. **Lower Bound Argument:**
   - Assume for contradiction that \( f(3, 3, \ldots, 3) \leq 3n - 5 \).
   - This would imply that \( A_n \) must receive at least two pebbles in some operations.
   - However, if \( A_n \) receives two pebbles, then the sum of pebbles in the other boxes must be less than \( 2n-3 \), which contradicts the requirement that each box must have at least one pebble before redistributing.

6. **Conclusion:**
   - The maximum possible value of \( f(a_1, \ldots, a_n) \) is \( 3n - 4 \).
   - This value is achieved only by the configuration \( (3, 3, \ldots, 3) \).

The final answer is \( \boxed{ 3n - 4 } \) and the configuration is \( (3, 3, \ldots, 3) \).