Pepík came up with the following problem:

$$
M+A+M+R+A+D+M+A+T+E+M+A+T+I+K+U=?
$$

He replaced different letters with different digits from 1 to 9 and found out what the result was.

a) What is the largest result Pepík could have obtained?

b) Could he have obtained a result of 50? If so, how?

c) Could he have obtained a result of 59? If so, determine all possible values that the sum $M+A+M$ could have.

(M. Smitková)

Hint. How many times does each letter repeat?
The letters $M$ and $A$ are represented four times in Pepík's problem, $T$ twice, and the other letters once each. For any substitution of digits for letters, the sum of distinct digits is equal to $1+2+3+4+5+6+7+8+9=45$. Therefore, the given problem can be simplified as

$$
3 M+3 A+T+45=?
$$

(Swapping $M$ and $A$ does not affect the overall sum, and we do not distinguish between these possibilities in further steps.)
a) To achieve the maximum possible sum, the most frequent letters must be replaced by the largest possible digits. Thus, for $M=9$, $A=8$, and $T=7$, we get

$$
3 \cdot 9+3 \cdot 8+7+45=103
$$

b) The sum of 50 is not possible, as the substitution with the smallest possible sum is $M=1$, $A=2$, and $T=3$, which gives

$$
3 \cdot 1+3 \cdot 2+3+45=57.
$$

c) To achieve a sum of 59, $3 M+3 A+T$ must equal 14, or $3(M+A)=14-T$. The substitution for $T$ must be such that the difference $14-T$ is divisible by three. Among the numbers from 1 to 9, we have the following three possibilities:

- For $T=2$, we get $M+A=4$. Thus, it can be either $M=1$ and $A=3$, or $M=3$ and $A=1$. The desired sum $M+A+M$ is either 5 or 7.
- For $T=5$, we get $M+A=3$. Thus, it can be either $M=1$ and $A=2$, or $M=2$ and $A=1$. The desired sum $M+A+M$ is either 4 or 5.
- For $T=8$, we get $M+A=2$. For this value, it is not possible to replace $M$ and $A$ with distinct digits.

The total sum of 59 is possible; the partial sum $M+A+M$ can be 4, 5, or 7.