4. Dana wrote a three-digit number on paper, which when divided by seven gives a remainder of 2. By swapping the first two digits, a three-digit number was formed that when divided by seven gives a remainder of 3. The number formed by swapping the last two digits of the original number gives a remainder of 5 when divided by seven. What remainder will the number, which is formed by swapping the first and last digits of Dana's number, have when divided by seven?
SOLUTION. Let's denote the digits of Dana's number as $a, b, c$. The information about the remainders when divided by seven from the problem can be rewritten into equations

$$
\begin{aligned}
& 100 a+10 b+c=7 x+2, \\
& 100 b+10 a+c=7 y+3, \\
& 100 a+10 c+b=7 z+5 .
\end{aligned}
$$

The digits $a$ and $b$ cannot be zero, because both the first and the second number in the problem are three-digit numbers; thus, $a, b \in\{1,2, \ldots, 9\}, c \in\{0,1,2, \ldots, 9\}$ and $x, y$ and $z$ are integers.

Now we will try to find the remainders of the digits $a, b, c$ when divided by seven. This will give us at most two possibilities for each digit. Looking at the coefficients in equations (1)-(3), we see that by a suitable subtraction, we can eliminate two digits $a$ and $c$ at once if we subtract equation (3) from ten times equation (2). We will then simplify the result step by step to find the remainder of the digit $b$ when divided by seven

$$
\begin{aligned}
10(100 b+10 a+c)-(100 a+10 c+b) & =10(7 y+3)-(7 z+5), \\
999 b & =70 y-7 z+25, \\
5 b & =70 y-7 z-7 \cdot 142 b+7 \cdot 3+4, \\
15 b & =3(70 y-7 z-7 \cdot 142 b+7 \cdot 3)+3 \cdot 4, \\
b & =3(70 y-7 z-7 \cdot 142 b+7 \cdot 3)-7 \cdot 2 b+12 .
\end{aligned}
$$

Since all terms on the right side of the last equation are divisible by seven except for the number 12, $b$ gives the same remainder when divided by seven as the number 12, and the only suitable digit $b$ is $b=5$.

By subtracting equation (3) from equation (1), we get the equation $9 c-9 b=7(z-x)+3$, and after substituting $b=5$ we get

$$
\begin{aligned}
9 c-9 \cdot 5 & =7(z-x)+3, \\
2 c & =7(z-x-c)+48, \\
8 c & =4 \cdot 7(z-x-c+6)+4 \cdot 6, \\
c & =4 \cdot 7(z-x-c+6)-7 c+7 \cdot 3+3 .
\end{aligned}
$$

From the divisibility of individual terms by seven, we get $c=3$.

Finally, by substituting $b=5$ and $c=3$ into the first equation, we can easily calculate the value of $a$:

$$
\begin{aligned}
100 a+10 b+c & =7 x+2, \\
100 a+53 & =7 x+2 \quad(53=7 \cdot 8-3,98=7 \cdot 14), \\
2 a & =7 x+2-7 \cdot 8+3-7 \cdot 14 a, \\
a & =4(7 x-7 \cdot 8-7 \cdot 14 a)+4 \cdot 5-7 a,
\end{aligned}
$$

from which it follows that the digit $a$ gives the same remainder when divided by seven as the number $20=7 \cdot 2+6$, and thus $a=6$.

Dana therefore wrote the number 653 on the paper, so the number formed by swapping the first and last digit is $356=7 \cdot 50+6$ and gives a remainder of 6 when divided by seven.