A railway line is $77.7 \mathrm{~km}$ long. Along the track, there is a stone at the end of every whole hectometer segment, and on it is displayed the distance from the two endpoints in km, for example: $0,0 \star 77,7$, or $1,2 \star 76,5$.

a) How many stones are there on which only two different digits appear?

b) How many stones are there on which no two digits are the same?[^0]


[^0]:    ${ }^{1}$ Under no circumstances should the contestants write down all the numbers on the stones, even those of the appropriate stones. We will not review such solutions, considering them "not in accordance with the competition rules."
The distance data displayed in hectometers should be considered with regard to the decimal point only in that the 0 and single-digit numbers are supplemented with 0 to be written as two-digit numbers.

a) The last digits of the two numbers are different, since the sum of identical digits is even and thus cannot give the last digit of 777. According to our condition, only these two digits can appear in both distance data. Let's denote these by $A$ and $B$. A carry from the tens place cannot occur, as this would only result from the sum $8+9$ or $9+8$, but then there would be a three-digit distance data with 8 or 9 as the first digit, which is not possible. Similarly, there cannot be a carry from the tens place, as only the digits $A$ and $B$ can stand there, and they cannot be 8 and 9. Thus, the sum of the digits must give 7 at each place value; and since only the digits $A$ and $B$ can appear, and their sum is 7, $A$ must stand in one number and $B$ in the other at each place.

If one number is two-digit, the other starts with 7, but then the 7 and 0 sum must also result in 7 at the other places, and thus the two-digit number, even when written as a three-digit number, still only has two different digits.

The distance markers that meet the condition can have the digit $A$ as any of the digits $0,1, \ldots, 7$. This already determines $B$; at the tens and hundreds places, $A$ and $B$ must also stand, only the order can be different in both places. Thus, on $8 \cdot 2 \cdot 2=32$ stones, only two different digits appear. (On each such stone, the two different digits appear 3 times each, except for 0, which appears 2 times, because in the examples, the 0 was not written in the first column.)

b) Let the distance of the stones containing all different digits from the two endpoints be $\overline{A B C}$ and $\overline{D E F}$, so $A B C+D E F=777$. The number of those stones, for which there is no carry in the addition, can be obtained similarly to the above. We note that even then, if one distance is a two-digit number, for example the first, we can think of writing 0 in place of $A$, because it cannot appear elsewhere, otherwise the digit in the same column would also be 7, and $D$ would be 7.

In each column, the sum of the two digits is 7, and 8 and 9 cannot appear. Thus, $C$ can have 8 different values, and this determines $F$, and $F \neq C$. $B$ can be any of the 6 remaining digits after $C$ and $F$ are filled, and the resulting $E=7-B$ is different from $B, C, F$, because $B+E$ is odd, and if, for example, $E$ were equal to $C$, then $B$ would also be equal to $F$, which we excluded by choosing $B$. Finally, similarly, $A$ can be any of the 4 remaining digits after $B$ and $E$ are filled, from which $D$ is determined, and it is different from all previous digits. Thus, the number of such stones is $8 \cdot 6 \cdot 4=192$.

If there is a carry from the units place in the addition of the data of the stone, then there cannot be a carry from the tens place, because the first carry can only result from $C+F=8+9$ or $9+8$, and thus $1+B+E$ can be at most $1+7+6=14$, while 7 is written from it. Therefore, only two types of additions are possible:
α) $C+F=17$,
$B+E=6$,
β) $C+F=7$,
$A+D=7$,
$B+E=17$,
$A+D=6$.

Disregarding the order within the pairs for the time being, the possible decompositions of the desired sums are as follows:

$$
\begin{aligned}
17 & =9+8 \\
7 & =7+0=6+1=5+2=4+3 \\
6 & =6+0=5+1=4+2
\end{aligned}
$$

Thus, 17 can only be decomposed in one way, and the two digits used do not reduce the number of possible decompositions of 7 and 6. The digit 0 can appear in the decompositions of 7 and 6, and it ends up in the hundreds place in both cases, where the 0 is not written, so the digit 0 can appear in both pairs. Thus, to the first decomposition of 7, we can attach all 3 decompositions of 6, to the next two, only 1, 1, and to the last one, 2. Thus, the three pairs of digits can be chosen in $3+1+1+2=7$ ways. The order of their members can be chosen independently in 2 ways in each column, so the $\alpha$) and $\beta$) cases each give $7 \cdot 2 \cdot 2 \cdot 2=56$ solutions.

Thus, the number of stones containing all different digits is $192+56+56=304$. (Among them, on $8+8=16$ stones, only 5 digits appear, on the $76,8 * 0,9$ and $68,7 * 9,0$ and the ones resulting from swapping the columns.)

András Csikvári (Budapest, Berzsenyi D. g. II. o. t.)

Note. We accepted solutions that gave 288 $(304-8-8)$ as the answer to the b) question as full value. However, we would have been pleased if more people had noticed the additional 16 stones resulting from the subtlety.