Alright! It's possible for all $n \geq 5.$ The underlying trick is actually pretty neat and simple, but we have to apply small tweaks for $4$ cases, depending on the remainder of $n/4.$ Because of this, I'm going to give a short sketch first.
The big idea is that we only actually need $2$ bins until the very last move. (it's easy to see the last move must always go from $(n, 0, 2n)$ or $(2n, 0, n)$ to $(n,n,n).$ Make sure you see why!) Once we've reduced it to two bins, the $i$th move must either take $i$ balls from one bin and put them in the other, or the opposite. It also means that if I tell you how many balls are in one bin, you automatically know how many are in the other. In my solutions/examples, I'll always pretend the two bins are the first (A) and the last (C). Now, let's look at what happens to $C$ over many steps. Say $T_i(n)$ is the number of balls in bin $C$ after $i$ steps. Then we have the following
$$T_0(n) = 0$$
$$T_i(n) = T_{i-1}(n) \pm i$$
Ie, solutions correspond to sums of $1, 2, \ldots , (n-1)$ with a choice of signs! $$T_{n-1}(n) = \pm 1 \pm 2 \pm 3 \ldots \pm (n-1).$$
We have additional constraints, like $T_i(n)$ (the $i$th partial sum of the above) must always be positive, and always less than $3n.$ We've got a solution if $T_{n-1}(n)$ is either $n$ or $2n.$ Otherwise, we can always convert from this running total of the number of balls in bin C to an actual solution.
So here's the recipe:
- Start with a special sum $S$ of the form $\pm 1 \pm 2 \ldots$ that
ignores the magnitude constraints.
- Change the first few terms of $S$ so that it meets the magnitude constraints, but now sums to something too big.
- Change some intermediate term, and the final term of $S$ so that we return to the right value.
After this, we just have to check we're respecting the upper and lower bounds required. Then convert back into a solution to the original balls/bins problem. First, I'll introduce the special sum $S$ in the case where $n$ is odd. We'll deal with the even $n$ case later.
Assume for the moment that $n = 2k+1,$ ie $n$ is odd.
Let $$S(n) = 1 + 2 - 3 + 4 - 5 + 6 - \ldots + (n-6) - (n-5) + (n-4) - (n-3) + (n-2) + (n-1),$$ ie the sum of $1, \cdots, n-1$ with the following signs:
$a$ and $n-a$ have the same sign
for even $ a < n/2,$ $a$ has a positive sign
for odd $1 < a < n/2,$ $a$ has a negative sign
$1$ has a positive sign.
This gives a series with $n-1$ terms, $S(n).$ Note that since $a$ and $n-a$ have the same sign, we can combine them to get $S(n) = n + n - n + n - n + \ldots$ where we have a total of $k$ terms. If $k$ is odd, this totals to $n,$ while if $k$ is even, this totals to $2n.$ Let $S_i(n)$ denote the partial sums of $S(n),$ so that $S_2(n) = 1 + 2, S_4(n) = 1 + 2 - 3 + 4,$ and so on.
Fact 1: $S_i(n) > -n.$ This follows from rewriting $S_i(n)$ as $1 + (2-3) + (4-5) + \ldots,$ in the first half of the series, with the pattern flipping at the midpoint. So our minimum is achieved at either $i=k-1$ or $i=k+1,$ (Recall $k = (n-1)/2)$ depending on weather the sign on $k$ is positive or negative. We get slightly more than $-k/2$ over the first half, and an additional $-(k+1)$ in the worst case, which is all greater than $-n.$
Fact 2: $S_i(n) \leq 2n.$ This follows very similarly. We bracket $S_i(n)$ as $1 + 2 + (-3 + 4) + (-5+6) \ldots,$ and note that in the first half we're gaining at most $3 + k/2.$ At the midpoint we may spike up to $k + 4 + k/2,$ after which we descend until the very last few steps $(n-2) + (n-1),$ where we go from $3$ to $2n$ or something much smaller to $n,$ depending on if $k$ is even or odd.
We'll also need the fact that these bounds are sharper on the first half of the sequence ($i < k$), where we'll have an approximately $k/2$ bound either way. Depending on if $k$ is even or odd, this may be tight. Further, our upper bound is actually $3k/2$ except at these final steps.
Now, let's begin with the odd cases.
ODD CASES
$$n= 4m + 3$$
(While I realize the order I'm doing cases in is a bit unorthodox, I promise the cases are roughly in order of difficulty.)
In this case, $k=2m+1$ is odd, and hence $S(n) = n.$ We alter $S(n)$ so that the partial sums are all positive without changing the final total. Call $E(j) = 3 + 5 + 7 + 9 + \ldots + j$ the error of $j,$ because this is the amount $S_i(n)$ will change by if we set the signs of all numbers up to $j$ to positive. Find the smallest odd $j$ such that $E(j) \geq k$ and $E(j)$ is odd.
If $n$ is large enough (see appendix for a sketch of how large), then we can modify $S(n)$ as follows:
we change all signs of numbers $\leq j$ to positive.
we change the sign of $n-1-E(j)$ from negative to positive. (we're assuming $n-1-E(j) < k$)
we change the sign of $n-1$ from positive to negative.
Call this $T(n),$ with partial sums $T_i(n)$ defined just like for $S_i(n).$ Note that the $T_i(n)$ is always positive, because we are only adding values until step $j,$ after which we have $T_i(n) - S_i(n) > 2E(j) > n-1$ for $i \in [j, n-2],$ which means $T_i(n)$ is greater than $n-1 + S_i(n) \geq 0$ (we're using our lower bound on $S(n)$). Further, since $k$ is odd $S_i(n) \leq n,$ which implies $T(n)$ is never larger than $n + 2 (n-1) < 3n.$ So $T(n)$ is valid, and we've done it! $T(n)$ gets converted, as we discussed in the intro, into a solution for distributing the $3n$ balls!
EXAMPLE
Since we've abstracted things pretty far from the original setting, let's try it with $n=31.$ We compute:
$E(3) = 3, E(5) = 8, E(7) = 15$
so $j=7$ in this case, which has the happy accident that $E(7) = k.$ Since $n-1 = 30,$ we will also need to put a plus sign on $30-E(7) = 15.$ Finally, we'll put a minus sign on $30$ itself. This gives our answer series as:
$1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 - 9 + 10 - 11 + 12 - 13 + 14 +15 - 16 + 17 - 18 + 19 - 20 + \ldots + 27 - 28 + 29 - 30$
which in turn corresponds to the solution
$(93, 0, 0) \rightarrow_{1-8} (57,0,36) \rightarrow_{9-14} (54,0,39) \rightarrow_{15} (39,0,54) \rightarrow_{16-29} (32,0,61) \rightarrow_{30} (62, 0, 31) \rightarrow_{31} (31,31,31)$
(subscripts indicate what steps are happening during each arrow, I've grouped away the repetitive steps, much like the bracketing used for the upper and lower bounds).
$$n = 1 + 4m$$
We'll use the same notation as before, but now $k=2m$ is even and so $S(n) = 2n.$ Note that for $i \in [k, n-2]$ the sign of $i$ is positive if $i$ is odd, and otherwise negative. This time we'll chose the smallest $j$ so that $E(j) > m$ and $E(j)$ is odd.
We modify $S(n)$ exactly as before to make $T(n).$ This time, $S_i(n)$ is always at least $-k/2,$ so the lower bound $T_i(n) > 0$ is trivial. For the upper bound, because $n$ is large enough we have
$$T_i(n) \leq S_i(n) + 2 E(j) \leq 3m + 1 + 8m \leq 12m = 3n$$ for $i < n-2.$ We know a lot about the last few terms (most things in S(n) have canceled at this point), so a little arithmetic tells us
$$T_{n-2}(n) = T_{n-3}(n) + n-2 = S_{n-3}(n) + 2(n-1) + n-2= 3n-1 < 3n$$ and
$$T_{n-1} = 3n-1 - (n-1) = 2n$$ as desired! So we've got a valid sequence for all odd $n$ now!
What about even $n$?
It turns out (see the Errata at the bottom of the post) that we can't quite use this same strategy for all even $n,$ but a very small tweak fixes things. They key observation is the following set of moves:
$$(3n, 0, 0) \rightarrow_1 (3n-1, 1, 0) \rightarrow_2 (3n-3, 3, 0) \rightarrow_3 (3n-3, 0, 3) $$
it's as though we skipped the third move! We've gone from a bin with 3n-3 balls in it and a bin with 3 balls in it to exactly the same setup, but now our next move will move $4$ balls. The same trick can be used for any $c = a + b,$ we can move $a$ and $b$ into the middle bin on their respective moves, then move the $c$ balls in the middle bin to wherever $a,b$ should have gone. For us, this means that whenever $a,b$ both have the same sign, we can use the trick to remove the $\pm c$ term from the sum.
And there's one step in particular that we'd really like to remove: $\frac n 2$ (which we'll call $k$ in this section). When $n$ is even, $n-1$ is odd, and we have broken the nice pairing symmetry (ie, $a$ and $n-a)$) we used to make the sequence $S(n),$ because there's nothing left to pair with $k.$ We'll have a little extra case work depending on if $k$ is even or odd.
With this trick in mind, we'll define $S'(n)$ and $S'_i(n)$ as with $S(n),$ except that $S'(n)$ will omit $k$ from the sum. For sanity reasons, we'll say $S'_k(n) = S'_{k-1}(n)$ (so that $S'_i(n)$ still denotes the total number of balls in the second bin after $i$ steps). Note that all our bounds from before still work just as well, and we have
$S'(n) = n$ if
$$n-1= 1 + 2(2m-1) = 4m$$
($n-1$ terms, arranged with $1$ middle guy we're skipping, and an odd number on each side so that everything but 1 + (n-1) cancels) while $S'(n) = 2n$ if $$n-1 = 1 + 2(2m) = 2 + 4m.$$
$$n = 4m$$
First, let's deal with our new trick. In this case, $k = 2m$ is even, so we can write $k= (m+1) + (m-1),$ and rest assured these two have the same sign. Perform our trick so that we do not have a $k$th summand. Now, define $E(j) = 3 + 5 + 7 + \ldots + j$ as before, and choose the smallest $j$ so that $E(j) > 3m$ and $E(j)$ is odd.
We get $T(n)$ from $S'(n)$ by performing the (now familiar) alternations:
Take a positive sign for all $i < j.$
Change the sign of $n-1-E(j)$ from negative to positive.
Change the sign of $n-1$ from positive to negative.
For our lower bound, again $T_i(n)$ is $2E(j)$ larger than $S'_i(n),$ until $i > m-1.$ Then, since we're storing $m-1$ and $m+1$ for later, we may be as much as $2m=k$ smaller than expected. Hence our choice of $E(j) > 3m,$ so that we still have $$T_i(n) - S'_i(n) \geq 4m - S'_i(n) > 0.$$ For the upper bound, since $S'_i(n) \leq 4m$ ($k$ even case way above) and $$T_i(n) - S'_i(n) \leq 8m$$ (our total gain over $S'$ is at most $2(n-1)$), we have $$T_i(n) \leq 12m = 3n,$$ as desired. So this case works too!
Final Case
$$n = 4m + 2$$
Alright, we've made it to the final case. This time, $k=2m+1$ is odd, and we're forced to take exactly this decomposition. Ie, we'll be moving $2m$ and $1$ into the middle bin, both of which have positive signs in $S'(n),$ and then move them into the third bin on the $k$th step.
This time, we're picking the minimum $j$ so that $E(j) > m$ and $E(j)$ is odd. We get $T(n)$ exactly as before.
It remains to check the upper and lower bounds. The lower bound is nice in this case, since $S'_i(n) \geq -m$ and our decomposition doesn't change much (we have $1$ ball in the middle bin until the $k-1$st step, where we get $k$ balls in the middle bin and then immediately evict them).
For the upper bound, our two local maxima for $S'_i(n)$ are at $i = k+1$ and $i > n-2,$ with both $S'$ and $T$ decreasing between the two. The $n-2$ case is identical to before, while $S'_{k+1}(n) = 2m + 1 + m + 3$ and $T_i(n) - S'_i(n) \leq 8m-2,$ so $T_i(n) \leq 8m-2 + 3m + 4 < 12m.$
This does it!
Example 2
I'll conclude with another example when $n$ is even, for added clarity. Take $n=50,$ so we'll need $j= 11$ (hence $E(j) = 35$ and $n-1-E(j) = 15). The sequence $T(n)$ will be:
$$1 + 2 + 3 + \ldots + 9 + 10 + 11 + 12 - 13 + 14 + 15+ 16 -17 + 18 - 19 + \ldots + 24 + 0 + 26 - 27 + \ldots - 47 + 48 -49$$
which corresponds to the sequence of balls in bins:
$$(150, 0, 0) \rightarrow_1 (149, 1, 0) \rightarrow_{2-12} (72, 1, 77) \rightarrow_{13-14} (71, 1, 78) \rightarrow_{15} (56, 1, 93) \rightarrow_{16-24} (39, 25, 87)\rightarrow_{25} ( 39, 0, 111) \rightarrow_{26-47} (49, 0, 101) \rightarrow_{48} (1, 0, 149) \rightarrow_{49} (50, 0, 100)$$
Appendix
Here I'm collecting miscellaneous results, and some annoying inequalities, that I didn't want to include above.
A short proof that $n=2 + 4m$ cannot be done with only $2$ bins until the last step:
Consider the bins mod $2.$ Since $n$ is even, after $n-1$ steps we must end up with all bins having an even number of balls in them. Since we're only using $2$ of the bins, every move changes the number of balls in both bins by $\pm i.$ Modulo $2,$ the sign does not matter. So, we must have
$$0 = \sum_i i (mod 2) = \sum_{i=1, odd}^{4m+2} 1 (mod 2) = 2m+1 (mod 2) = 1$$
a contradiction. So we're forced to do something with the third bin in this case.
(Here I'm putting the precise meaning of '$n$ large enough.' It's not terribly insightful in my opinion, but I'm including it for completeness.)
For the n = 3 mod 4 case:
Our transformation needs the following inequality in order to be well defined:
$j < n-1-E(j) $
Since $E(j)$ grows quadratically with $j,$ eventually $j < \epsilon E(j)$ for any $\epsilon > 0.$ since $j$ is also how much $E(j)$ differs from $E(j-2),$ this means that for $n$ large enough, $E(j)$ is a good approximation for $k;$ it can only differ by $j \approx \epsilon E(j).$ Taking $\epsilon ~\frac 1 8$ suffices, and a short computation shows that this is reached for $n > 50.$ As the examples above show, smaller $n$ often work. A computation confirms that it's always possible for $n<50,$ though I do not want to copy over valid sequences for each...
One might also worry that $E(j)$ could end up greater than $n-1,$ but the same argument shows this can't happen for $n > 14.$
Finally, I note that an extremely similar series actually works for $n>10,$ but we must occasionally take $j$ smaller, and make sure that $n-1-E(j)$ has a negative sign. I chose to take the less general algorithm for simplicity of exposition.