5. A teacher fills in the cells of a class journal of size $7 \times 8$ (7 rows, 8 columns). In each cell, she puts one of three grades: 3, 4, or 5. After filling in the entire journal, it turns out that in each row, the number of threes is not less than the number of fours and not less than the number of fives, and in each column, the number of fours is not less than the number of fives and not less than the number of threes. How many fives could the teacher have put?
Answer: 8 fives.

## Solution.

First step.

In each row, there are no fewer threes than fours, so in the entire journal, there are no fewer threes than fours. In each column, there are no fewer fours than threes, so in the entire journal, there are no fewer fours than threes. Therefore, the number of threes and fours in the journal is the same.

Second step.

Suppose in some column, there are more fours than threes. Since in the other columns, there are no fewer fours than threes, we would get that in the entire journal, there are more fours than threes. This is a contradiction. Therefore, in each column, the number of fours and threes is the same.

Third step.

Consider all possible distributions of threes, fours, and fives in a column: 1) $0,0,7 ; 2) 1,1,5 ; 3) 2,2,3$ - these do not work, as then there would be more fives. The only remaining case is $3,3,1$. Then, in the entire journal, there can be 8 fives.

Fourth step.

Such a distribution is possible (we need to consider that in the rows, the number of fours and threes is also the same),

| $\mathbf{5}$ | $\mathbf{5}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{5}$ | $\mathbf{5}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ |
| $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{5}$ | $\mathbf{5}$ | $\mathbf{4}$ | $\mathbf{3}$ |
| $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{5}$ | $\mathbf{5}$ |
| $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ |
| $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ |
| $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ | $\mathbf{3}$ | $\mathbf{4}$ |

see the example in the figure.

Criteria. If the solution is incorrect - 0 points.

If only the correct example is given - 3 points.

If only the correct estimate is given - 4 points.

If the solution is correct (any correct example and justification of the estimate) - 7 points.