5. On the table, there are empty glasses standing in a row. Petya and Vasya take turns (starting with Petya) to fill them with drinks: Petya - lemonade, Vasya - compote. In one move, a player can fill one empty glass of their choice so that after their move, no two adjacent glasses contain the same drink. If all the glasses are filled as a result of the players' actions, the game ends in a draw. Otherwise, the player who cannot make a move loses. For which p will Vasya win regardless of Petya's actions?
Answer: $n \notin\{1,2,4,6\}$.

Solution. Number the glasses from left to right with numbers from 1 to $n$. For $n=1$ and $n=2$, a draw is obvious. If $n$ is 4 or 6, Petya first fills the first glass with lemonade. For $n=4$, Petya can then fill one of the two last glasses and, thus, will not lose. For $n=6$, Petya fills the last glass (if it is empty) on the second move, and then one of the two middle glasses; if the last glass was filled by Vasya, Petya fills the third glass, and then the fifth. In any case, Petya will not lose.

Now consider $n \notin\{1,2,4,6\}$. We will prove two statements.

1) If Vasya fills the glass with number 1 on his first move, he will always have a move. Let's call a segment a set of glasses standing between two consecutive glasses with lemonade. By the condition, each segment is non-empty, and any glass in the segment is either empty or contains compote. Let $k \geqslant 2$. After Petya's $k$-th move, $k-1$ segments are formed. By this point, Vasya has filled $k-1$ glasses, including the first one, which does not belong to any segment. Therefore, there will be a segment where all the glasses are empty. Vasya can then fill one of them with compote.
2) If Vasya fills the glass with number 1 on his first move, he cannot lose. Indeed, by 1), Vasya will always have a move and, thus, will achieve at least a draw.

Let's describe Vasya's winning strategy. On his first move, Vasya always fills the edge glass (let's assume it is the first one; otherwise, we can renumber the glasses in reverse order). By 2), it is sufficient to show that Vasya can avoid a draw. Consider two cases.
a) $n$ is odd. Vasya can play arbitrarily. A draw is impossible because in this case, the last glass would have been filled by Petya, which contradicts 1).

b) $n=2 m n p u ~ m \geqslant 4$. On his second move, Vasya must fill a glass with an even number greater than 2. This is possible because there are at least three glasses with such numbers, and thus one of them is empty. Vasya can then play arbitrarily. Suppose the game ends in a draw. Then $m$ glasses with lemonade are placed in positions $2,3, \ldots, 2 m$. They must be on even positions, as no two glasses stand next to each other. But this is impossible, as there are only $m$ even positions, and one of them has already been used by Vasya.