4. Given a three-digit number $\overline{a b c}$, the last three digits of its square are also $\overline{a b c}$. Then, the sum of all such three-digit numbers is $\qquad$

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
4.1001 .

Let $x=\overline{a b c}$, then the last three digits of $x^{2}-x$ are all 0. Therefore, $x(x-1)$ is a multiple of 1000.

Since $1000=2^{3} \times 5^{3}$, and $x$ and $x-1$ are coprime, thus, $x-1$ is a multiple of $5^{3}$ or $x$ is a multiple of $5^{3}$.

When $x-1=125,125 \times 3,125 \times 5,125 \times 7$, checking shows that only $x-1=125 \times 3$, i.e., $x=376$ meets the condition;

When $x=125,125 \times 3,125 \times 5,125 \times 7$, checking shows that only $x=125 \times 5=625$ meets the condition.
Therefore, the sum of all the required three-digit numbers is $376+625=1001$.