A positive integer is called "balanced" if it has four digits, and one of these digits is equal to the average of the other three. For example: the number 2631 is balanced because 3 is the average of 2, 6, and 1; 4444 is also balanced because 4 is the average of 4, 4, and 4.

a) Find the three smallest balanced numbers.

b) How many balanced numbers are there that are less than 2014?
Solution

A four-digit number is balanced when one of its digits, say $a$, is the average of the other three digits, say $b, c$ and $d$, that is, when $(b+c+d) / 3=a$ or, equivalently, when $(a+b+c+d) / 4=a$. We see thus that a four-digit number $N$ is balanced when it satisfies the following two conditions:

(i) The sum of its digits, say $S$, is divisible by 4;

(ii) $S / 4$ is one of the digits of $N$.

(a) Of the numbers of the form $\overline{100 x}$, the only ones that satisfy condition i) are 1003 and 1007, and of these two numbers, the only one that satisfies (ii) is 1003. Of the numbers of the form $\overline{101 x}$, the only ones that satisfy (i) are 1012 and 1016, and of these two, the only one that satisfies (ii) is 1012. Of the numbers of the form $\overline{102 x}$, the only ones that satisfy (i) are 1021, 1025 and 1029, and of these three, the ones that satisfy (ii) are 1021 and 1025. In conclusion, the three smallest balanced numbers are

$$
1003, \quad 1012 \text { and } 1021
$$

(b) Let's first analyze the balanced numbers of the form $\overline{1 x y z}$. By conditions (i) and (ii), we must have $1+x+y+z$ divisible by $4$ and $(1+x+y+z) / 4$ must coincide with one of the digits $1, x, y$ or $z$. Suppose the digits $x, y$ and $z$ satisfy these conditions.

- If $x, y$ and $z$ are distinct, we can form the 6 balanced numbers $\overline{1 x y z}, \overline{1 x z y}$, $\overline{1 y x z}, \overline{1 y z x}, \overline{1 z x y}$ and $\overline{1 z y x}$.
- If $x=y$ and $z$ are distinct, we can form the 3 balanced numbers $\overline{1 x x z}$, $\overline{1 x z x}$ and $\overline{1 z x x}$.
- If $x=y=z$, we can form only the balanced number $\overline{1 x x x}$.

Note now that $1=1+0+0+0 \leq 1+x+y+z \leq 1+9+9+9=28$. Then the sum $1+x+y+z$ can only take the values $4,8,12,16,20,24$ and 28. We will separate into cases according to the values that the sum $x+y+z$ can take.

- If $x+y+z=27$ : In this case, we must have $x=y=z=9$, but the number 1999 does not satisfy (ii), and thus is not balanced. Therefore, we have no balanced numbers.
- If $x+y+z=23$ : In this case, one of the digits must be equal to $(1+x+y+z) / 4=$ 6. Then the set $\{x, y, z\}$ must be $\{6,9,8\}$, and since the digits 6,9 and 8 are distinct, we have 6 balanced numbers.
- If $x+y+z=19$ : One of the digits must be equal to $(1+x+y+z) / 4=5$. Then the set $\{x, y, z\}$ must be $\{5,9,5\},\{5,8,6\}$ or $\{5,7,7\}$. If the set $\{x, y, z\}$ is $\{5,9,5\}$, we have 3 balanced numbers, if it is $\{5,8,6\}$ we have 6 balanced numbers, and if it is $\{5,7,7\}$, we have 3 balanced numbers. Thus, we have a total of $3+6+3=12$ balanced numbers.
- If $x+y+z=15$ : One of the digits must be equal to $(1+x+y+z) / 4=4$. Then the set $\{x, y, z\}$ must be $\{4,9,2\},\{4,8,3\},\{4,7,4\}$ or $\{4,6,5\}$. We then have $6+6+3+6=21$ balanced numbers.
- If $x+y+z=11$ : One of the digits must be equal to $(1+x+y+z) / 4=3$. Therefore, the set $\{x, y, z\}$ must be $\{3,8,0\},\{3,7,1\},\{3,6,2\},\{3,5,3\}$ or $\{3,4,4\}$. We then have $6+6+6+3+3=24$ balanced numbers.
- If $x+y+z=7$ : One of the digits must be equal to $(1+x+y+z) / 4=2$. Then the set $\{x, y, z\}$ must be $\{2,5,0\},\{2,4,1\}$ or $\{2,3,2\}$. We then have $6+6+3=15$ balanced numbers.
- If $x+y+z=3$ : One of the digits must be equal to $(1+x+y+z) / 4=1$. Then the set $\{x, y, z\}$ must be $\{1,2,0\},\{1,1,1\}$, or $\{3,0,0\}$. We then have $6+1+3=10$ balanced numbers.

Finally, it is easy to see that of the numbers $2000,2001, \ldots, 2013$, the only ones that satisfy conditions i) and ii) are 2006 and 2011. Therefore, the number of balanced numbers less than 2014 is

$$
6+12+21+24+15+10+2=90
$$