4. Triples of natural numbers $\left(a_{i}, b_{i}, c_{i}\right)$, where $i=1,2, \ldots, n$ satisfy the following conditions:
1) $a_{i}+b_{i}+c_{i}=2017$ for all $i=1,2, \ldots, n$;
2) if $i \neq j$, then $a_{i} \neq a_{j}, b_{i} \neq b_{j}$ and $c_{i} \neq c_{j}$. What is the maximum possible value of $n$? (M. Popov)
Answer: 1343.

Solution: Note that

$$
\sum_{i=1}^{n} a_{i} \geqslant \sum_{i=1}^{n} i=\frac{n(n+1)}{2} .
$$

A similar inequality is written for the sums $b_{i}$ and $c_{i}$. Adding the three obtained inequalities, we get

$$
\begin{gathered}
3 \cdot \frac{n(n+1)}{2} \leqslant \sum_{i=1}^{n} a_{i}+\sum_{i=1}^{n} b_{i}+\sum_{i=1}^{n} c_{i}= \\
=\sum_{i=1}^{n}\left(a_{i}+b_{i}+c_{i}\right)=2017 n .
\end{gathered}
$$

Thus, we obtain the upper bound

$$
\frac{3(n+1)}{2} \leqslant 2017 \Longrightarrow n \leqslant 1343
$$

Now let's provide an example where this bound is achieved ( $n=1343$ )

| $a_{i}$ | $b_{i}$ | $c_{i}$ |
| :---: | :---: | :---: |
| 1 | 672 | 1344 |
| 2 | 673 | 1342 |
| $\vdots$ | $\vdots$ | $\vdots$ |
| 672 | 1343 | 2 |
| 673 | 1 | 1343 |
| 674 | 2 | 1341 |
| $\vdots$ | $\vdots$ | $\vdots$ |
| 1343 | 671 | 3 |