Five notebooks - blue, gray, brown, red, and yellow - were lying in a stack in a certain order. They were laid out on the table in two stacks: first the top notebook, then the next one, and so on. As a result, in the first stack: on the table - the red notebook, on it - the yellow one, on top - the gray one; in the second: on the table - the brown notebook, on it - the blue one. Then the notebooks were collected into one stack in the previous order and laid out on the table again, taking them off the top of the stack in the same order. This time, in the first stack: on the table - the brown notebook, on it - the red one; in the second: on the table - the yellow notebook, on it - the gray one, on top - the blue one. In what order did the notebooks lie in the stack originally?
Can the gray notebook lie above the yellow one, and the yellow one above the red one in the original stack?

## Solution

From how the notebooks were laid out the first time, it follows that in the original stack, the gray notebook could not have been above the yellow one, and the yellow one could not have been above the red one. From the second layout, it is clear that the red notebook could not have been above the brown one, and the blue one could not have been above the yellow and gray ones. Thus, the only possible sequence of notebooks in the stack is: brown, red, yellow, gray, blue.

## Answer

Brown, red, yellow, gray, blue notebooks.