Karpov D.V.

In a deck of $n$ cards, some of them are face down, and the rest are face up. In one move, it is allowed to take several cards from the top, flip the obtained stack, and place it back on top of the deck. What is the minimum number of moves required to ensure that all cards are face down, regardless of the initial arrangement of the cards?
In $n$ moves. First, we prove that all cards can always be placed face down in no more than $n$ moves. If all cards are initially face down, the statement is proven. Otherwise, we divide the deck into groups of consecutive cards lying the same way (i.e., all cards in each group are either face up or face down). We flip the topmost group. This will reduce the number of groups by one. We will continue this procedure until only one group remains, i.e., all cards in the deck will lie the same way. Since there were initially no more than $n$ groups, this will take no more than $n-1$ moves. The resulting group can, if necessary, be flipped in one move to ensure that all cards are face down. Now we show that there exists a card arrangement in which the required card layout in the deck cannot be achieved in fewer than $n$ moves. Since each move, as is easily verified, reduces the number of groups by no more than one, a deck containing $n$ groups can be reduced to one group in a minimum of $n-1$ moves. Consider a deck where the bottom card is face up, the second from the bottom is face down, and so on. If each move reduces the number of groups, the entire deck has not been flipped, so after $n-1$ moves, such a deck will be reduced to one group where all cards are face up (i.e., as the bottom card initially lay). Therefore, it will take an $n$-th move to flip all the cards and place them as required by the problem. If, in addition to the $n-1$ moves that reduce the number of groups, some moves are made that do not reduce the number of groups, then, obviously, a total of no fewer than $n$ moves will be made. Thus, the specified deck cannot be reduced to one group in fewer than $n$ moves.

## Answer

In $n$ moves.