For an integer n≥2, let us consider the number of ways of filling the n boxes lined up from left to right by putting n balls one-by-one into the boxes starting from the left-most one, assuming that any of the balls can have any of the three colors. Denote by an the possible number of ways of filling the boxes so as to satisfy the condition of the problem, starting with a red ball going into the left-most box. We see that the number of ways will be the same an if we start with a blue ball instead of a red one, and this is true also if we start with a yellow one.
Next, suppose n≥4, and we start with a red ball, and count how many red balls were used before the first non-red ball is put into a box. Call this number k. Then by the assumption of the problem, k≥2. Now consider the following two cases:
(1) When k=2: In this case, either a blue or a yellow ball has to go into the third box, and in either case the number of ways of filling the remaining n−2 boxes so as to satisfy the condition of the problem is an−2, and therefore there are 2an−2 ways of filling the n boxes so as to satisfy the condition.
(2) When k≥3: In this case, if we remove the left-most box (containing a red ball), the left-most box for the remaining n−1 boxes has a red ball and the number of ways of filling the remaining n−2 boxes must be an−1 in order to satisfy the condition.
Thus we get the recurrence formula: an=an−1+2an−2.
When n=2,3 the only way to fill boxes starting with a red ball and satisfying the condition is to use red balls only, so we have a2=1 and a3=1.
If we use the recurrence formula above repeatedly, we obtain a12=683, and therefore, the desired answer is 3×683=2049.