Tokarev S.i.

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

Let $A$ have the most friends, and $B$ have the least. In the first case, $A$ is friends with everyone, and $B$ is only friends with $A$. In the second case, $B$ is not friends with anyone, and $A$ is friends with everyone except $B$. In each case, $A$ is friends with Petya, and $B$ is not. Let's transfer $A$ and $B$ to another class. As we have already seen, $A$ is friends with all of the remaining, and $B$ is not friends with any of the remaining. Therefore, after the transfer, each of the remaining has one less friend (among classmates). Thus, the remaining Petya's classmates will again have a different number of friends among classmates.

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.