2. (2005 Japan Mathematical Olympiad) For a natural number $n$, let $S(n)$ denote the sum of its digits, for example, $S(611)=6+1+1=8$. Let $a, b, c$ be three-digit numbers such that $a+b+c=2005$, and let $M$ be the maximum value of $S(a)+S(b)+S(c)$. How many triples $(a, b, c)$ satisfy $S(a)+S(b)+S(c)=M$?
2. Let $a=100 a_{3}+10 a_{2}+a_{1}$,
O
$b=100 b_{3}+10 b_{2}+b_{1}$,
$c=100 c_{3}+10 c_{2}+c_{1}$,
$\left(1 \leqslant a_{3}, b_{3}, c_{3} \leqslant 9,0 \leqslant a_{2}, b_{2}, c_{2}, a_{1}, b_{1}, c_{1} \leqslant 9\right)$.
Let $i=a_{1}+b_{1}+c_{1}, j=a_{2}+b_{2}+c_{2}, k=a_{3}+b_{3}+c_{3}$.
Given that $i+10 j+100 k=2005$, and $i, j, k \leqslant 27$, hence $(i, j, k)=(5,0,20),(5,10,19),(5,20,18)$, $(15,9,19),(15,19,18),(25,8,19),(25,18,18)$.
Therefore, when $(i, j, k)=(25,18,18)$,
$S(a)+S(b)+S(c)=i+j+k$ is the largest.
When $i=25$, the possible pairs of $\left(a_{1}, b_{1}, c_{1}\right)$ are $(7,9,9),(8,8,9)$ and their permutations, so there are $3 \times 2=6$ possible pairs.
When $j=18$, the possible pairs of $\left(a_{2}, b_{2}, c_{2}\right)$ are $(0,9,9),(1,8,9),(2,7,9),(2,8,8),(3,6,9),(3,7,8),(4,5,9),(4,6,8),(4,7,7),(5,5,8),(5,6,7),(6,6,6)$ and their permutations, so there are $6 \times 7+3 \times 4+1=55$ possible pairs.

When $k=18$, the possible pairs of $\left(a_{3}, b_{3}, c_{3}\right)$ are the same as those of $\left(a_{2}, b_{2}, c_{2}\right)$, but $(0,9,9)$ and its permutations must be excluded, so there are $55-3=52$ possible pairs of $\left(a_{3}, b_{3}, c_{3}\right)$.
Therefore, the number of $(a, b, c)$ that satisfy the conditions is
$$
6 \times 55 \times 52=17160 \text {. }
$$