Ilya's logical tests
This is a more difficult version of the Ali-baba problem than the one that was offered at the Moscow Institute of Physics & Technology math olympiad (8th grade).
Ali-baba is standing in front of the treasure cave. By the entrance he finds a four-sectional rotating table, each section having a plus sign on one side and a minus sign on another side. The signs have been painted in a magical invisible ink. Ali-baba may place his two hands on two sections of the table and flip none, one or both sections, whichever he decides. After that, he must withdraw his hands. If, at that point, all four sections have the same sign facing up, the cave with treasures will open. Otherwise, the table quickly rotates and then stops. Rotation is so fast that Ali-baba does not know the new positions of the sections relative to their old positions. Once the table stops, Ali-baba may repeat the whole process. It is known that the magic cave makes anyone trying to open it extremely unlucky. The old legend says that one needs not luck but wisdom to get all the signs aligned. Help Ali-baba.