Problem: For each positive integer $n$ , let $S(n)$ denote the sum of the digits of $n.$ For how many values of $n$ is $n + S(n) + S(S(n)) = 2007?$
$\mathrm{(A)}\ 1 \qquad \mathrm{(B)}\ 2 \qquad \mathrm{(C)}\ 3 \qquad \mathrm{(D)}\ 4 \qquad \mathrm{(E)}\ 5$

Solution: Claim. The only positive integers $n$ that satisfy the condition are perfect multiples of $3$
Proof of claim:
We examine the positive integers mod $9$ . Here are the cases.
Case 1. $n \equiv 1 \pmod 9$ . Now, we examine $S(n)$ modulo $9$ .
Case 1.1. The tens digit of $n$ is different from the tens digit of the largest multiple of $9$ under $n$ . (In other words, this means we will carry when adding from the perfect multiple of $9$ under $n$ .)
Observe that when we carry, i.e. Add $1$ onto $1989$ to obtain $1990$ , the units digit decreases by $9$ while the tens digit increases by $1$ . This means that the sum of the digits decreases by $8$ in total, and we have $-8 \equiv 1 \pmod 9$ , so the "mod 9" of the sum increases by $1$ . This means that, regardless of whether the sum carries or not, the modulo 9 of the sum of the digits always increases by $1$
Case 1.2. The tens digits are the same, which is trivial since the units digit just increases by $1$ which means that the sum is also equivalent to $1 \pmod 9$
This means that $S(n) \equiv 1 \pmod 9$ and similarly letting the next $n=S(n)$ $S(S(n)) \equiv 1 \pmod 9$ . Summing these, we have $n+S(n)+S(S(n)) \equiv 3 \pmod 9$ . Clearly, no integers of this form will satisfy the condition because $2007$ is a perfect multiple of $9$
Case 2. $n \equiv 2 \pmod 9$
In this case, we apply exactly the same argument. There is at most one carry, which means that the sum of the digits will always be congruent to $2$ mod $9$ . Then we can apply similar arguments to get $S(n) \equiv 2 \pmod 9$ and $S(S(n)) \equiv 2 \pmod 9$ , so adding gives $n+S(n)+S(S(n)) \equiv 6 \pmod 9$
It is trivial to see that for $n \equiv k \pmod 9$ , for $0 \leq k \leq 8$ , we must have $n+S(n)+S(S(n)) \equiv 3k \pmod 9$ . Only when $k=0, 3, 6$ is $3k$ a multiple of $9$ , which means that $n$ must be a multiple of $3$
Now, we find the integers. Again, consider two cases: Integers that are direct multiples of $9$ and integers that are multiples of $3$ but not $9$
Case 1. $n$ is a multiple of $9$ . An integer of the form $\overline{20ab}$ will not work since the least such integer is $2007$ which already exceeds our bounds. Thus, we need only consider the integers of the form $\overline{19ab}$ . The valid sums of the digits of $n$ are $18$ and $27$ in this case.
Case 1.1. The sum of the digits is $18$ . This means that $S(n)=18, S(S(n))=9$ , so $n=2007-18-9=1980$ . Clearly this number satisfies our constraints.
Case 1.2. The sum of the digits is $27$ . This means that $S(n)=27, S(S(n))=9$ , ,so $n=2007-27-9=1971$ . Since the sum of the digits of $1971$ is not $27$ , this does not work.
This means that there is $1$ integer in this case.
Case 2. $n$ is a multiple of $3$ , not $9$ .
.
Case 2.1. Integers of the form $\overline{20ab}$ . Then $S(n)=3$ or $S(n)=6$ ; it is trivial to see that $S(n)=6$ exceeds our bounds, so $S(n)=3$ and $n=2007-6=2001$
Case 2.2. Integers of the form $\overline{19ab}$ . Then $S(n)=12, 15, 21, 24$ and we consider each case separately.
Case 2.2.1. Integers with $S(n)=12$ . That means $n=2007-12-3=1992$ which clearly does not work.
Case 2.2.2. Integers with $S(n)=15$ . That means $n=2007-15-6=1986$ which also does not work
Case 2.2.3. Integers with $S(n)=21$ . That means $n=2007-21-3=1983$ which is valid.
Case 2.2.4. Integers with $S(n)=24$ . That means $n=2007-24-6=1977$ which is also valid.
We have considered every case, so there are $\boxed{4}$ integers that satisfy the given condition.

Answer:  4