5. Solution: Let Masha have $x$ rubles, and Petya have $y$ rubles, then

$n(x-3)=y+3$
$x+n=3(y-n)$

Express $x$ from the second equation and substitute it into the first:

$n(3 y-4 n-3)=y+3$,

$3 n y-y=4 n^{2}+3 n+3$,

$y=\left(4 n^{2}+3 n+3\right):(3 n-1)$

For $y$ to be an integer, $\left(4 n^{2}+3 n+3\right)$ must be divisible by (3n-1)

$\left(4 n^{2}+3 n+3\right):(3 n-1)$

$3\left(4 n^{2}+3 n+3\right)-4 n(3 n-1):(3 n-1)$

$13 n+9:(3 n-1)$

$3(13 n+9)-13(3 n-1):(3 n-1)$

$40:(3 n-1)$

(3n-1) is a divisor of 40 only when $n=1 ; 2 ; 3 ; 7$

Let's check if $x$ and $y$ are natural numbers.

$n=1, y=5, x=11$

$n=2, y=5, x=7$

$n=3, y=6, x=6$

$n=7, y=11, x=5$
Answer: $1 ; 2 ; 3 ; 7$.

| 20 points | Complete justified solution |
| :--- | :--- |
| 15 points | Values of n are found, it is proven that there are no other values, but it is not shown why these values meet the condition of the problem. |
| 12 points | Correct approach to the solution, one value of n is lost. |
| 10 points | Correct approach to the solution, there are significant advances, but the values of n are not found or are found incorrectly. |
| 5 points | Correct solutions are found, but it is not shown that there are no other values of n. |
| 0 points | Other solutions that do not meet the criteria listed above |