In Mr. Goat's garden, several cherry trees were in bloom. On each cherry tree, three sparrows were sitting, and one more was sitting on the fence. Mr. Goat's dog scared them away and the sparrows flew off. After a while, they all returned and settled on the cherry trees. The cherry tree under which the dog was sleeping remained empty, and on each of the others, four sparrows settled. How many cherry trees does Mr. Goat have and how many sparrows were there in the garden?
Let $x$ be the number of cherries in the garden and $y$ be the number of sparrows. If we know that all the sparrows perched on the cherries in groups of three and one remained on the fence, we can set up the following equation:

$$
y=3 x+1
$$

After the sparrows returned to the cherries, they occupied all the cherries except one, where a dog was lying, in groups of four. Again, we can set up the equation:

$$
y=4(x-1) \text {. }
$$

Since the number of sparrows remains the same, $y$ must be equal to the same number in both equations. Then we get:

$$
\begin{aligned}
3 x+1 & =4(x-1), \\
5 & =x .
\end{aligned}
$$

By substituting into $y=3 x+1$, we calculate that there were 16 sparrows.

Mr. Goat has a total of 5 cherries and 16 sparrows flew into the garden.

[1 point for setting up each equation, 2 points for solving the equation, 2 points for the correct answer]