Four. (50 points) Let $n$ be a positive integer, and let $S_{n}$ be a subset of the set $A_{n}=\left\{m \mid m \in \mathbf{N}_{+}\right.$, and $\left.m \leqslant n\right\}$. Moreover, the difference between any two numbers in $S_{n}$ is not equal to 4 or 7. If the maximum number of elements in $S_{n}$ is denoted by $M_{n}$ (for example, $M_{1}=1, M_{2}$ =2), find $\sum_{n=1}^{2012} M_{n}$.
It is known that the difference between any two numbers among $1,4,6,7,9$ is not 4 or 7. Adding 11 to each of these numbers gives $12, 15, 17, 18, 20$, which clearly also have the same property, and the difference between any of these numbers and any of the first five numbers is also not 4 or 7. By this reasoning, for any fixed positive integer $n$, in each set of 11 consecutive numbers, five numbers can be chosen, and from the remaining $i=n-11 \times \left[\frac{n}{11}\right]$ numbers, $R_{i}$ numbers can be chosen, forming the set $S_{n}$ (where $[x]$ denotes the greatest integer not exceeding the real number $x$).

We now prove that $S_{n}$ cannot contain more numbers.
If this were not the case, then in the set $S_{n}$, at least one of the groups of 11 numbers could have six numbers chosen such that the difference between any two of them is not 4 or 7.

Consider the numbers $1,2, \cdots, 11$ and divide them into five groups:
$$
(1,8),(2,6),(3,10),(5,9),(4,7,11),
$$
where at least one group must have two numbers chosen. Clearly, from the first four groups, no more than one number can be chosen from each, so the only possibility is to choose 4 and 7 from the fifth group $(4,7,11)$.

Thus, from $(1,8)$, only 1 can be chosen, from $(5,9)$, only 9 can be chosen, and from $(2,6)$, only 6 can be chosen.

This means that from $(3,10)$, neither 3 nor 10 can be chosen, making it impossible to select a sixth number. Therefore,
$$
M_{n}=5 \times \left[\frac{n}{11}\right]+R_{i}.
$$

When $i=0, 1, 2, 3$, $R_{i}=i$;
When $i=4, 5, 6, 7, 8$, for example, if $i=8$, consider the remaining numbers $1,2, \cdots, 8$ and divide them into four groups:
$$
(1,5),(2,6),(3,7),(4,8),
$$
one number can be chosen from each group, totaling 4 numbers, so $R_{i}=4$;
When $i=9, 10$, for example, if $i=9$, consider the remaining numbers $1,2, \cdots, 9$ and divide them into five groups:
$$
(1,5),(2,6),(3,7),(4,8),(9),
$$
the numbers 1, 3, 4, 6, 9 can be chosen, so $R_{i}=5$.
Since $2012=11 \times 182+10$, we have
$$
\begin{array}{l}
\sum_{n=1}^{2012} M_{n}=\sum_{k=0}^{182} \sum_{i=0}^{10} M_{11 k+i} \\
=\sum_{k=0}^{182}(11 \times 5 k+1+2+3+4 \times 5+5 \times 2) \\
=55 \times \frac{182 \times 183}{2}+183 \times 36 \\
=922503 .
\end{array}
$$