4. Petya has a total of 28 classmates. Any two of the 28 have a different number of friends in this class. How many friends does Petya have?
4. Petya's classmates can have $0,1,2, \ldots, 28$ friends - a total of 29 options. However, if someone is friends with everyone, then everyone has at least one friend. Therefore, either there is someone who is friends with everyone, or there is someone who is not friends with anyone. In both cases, there are 28 options left: $1,2, \ldots, 28$ or $0,1, \ldots, 27$.

Let's denote the person with the most friends as $A$, and the person with the fewest friends as $B$. In the first case, $A$ is friends with everyone, and $B$ is only friends with one person, i.e., only with $A$. In the second case, $B$ is not friends with anyone, and $A$ is friends with everyone except one, i.e., with everyone except $B$.

Thus, in each case, $A$ is friends with Petya, and $B$ is not. We will transfer $A$ and $B$ to another class. As we have already seen, $A$ is friends with everyone left, and $B$ is not friends with anyone left. Therefore, after the transfer, each of the remaining classmates has one fewer friend (among classmates). This means that the remaining classmates of Petya will again have a different number of friends among classmates.

Now, we will again transfer the most "friendly" and the most "unsociable" to another class, and so on.

By repeating these arguments 14 times, we will transfer 14 pairs of students to another class, in each of which exactly one is Petya's friend. Thus, Petya has 14 friends.

Commentary. $1^{\circ}$. Several ideas are at work in the solution: the symmetry of friendship, the principle of the extreme, and inductive descent.

$2^{\circ}$. There is a very short but incorrect solution: let Petya have $x$ friends. Let's make all friends quarrel, and those who were not friends become friends, then Petya's classmates will again have a different number of friends, and thus Petya will again have $x$ friends. We get the equation $x=28-x$. Where is the mistake? If it were proven that the answer in the problem is unique, then the reasoning would be correct. Nevertheless, this reasoning allows us to guess the answer.

$3^{\circ}$. Solve the problem if Petya has 27 classmates.

$4^{\circ}$. This problem is a continuation of another well-known problem: prove that in any company, there will be two people who have the same number of friends in this company (possibly none).