5. Emperor Pea has a worm in one of his rejuvenating apples. He has 13 apples in total, and they are arranged in a circle in a special box for rejuvenating apples. To find the worm, Emperor Pea decided to use a balance scale. He knows that all the apples weigh the same, except for the one with the worm, which is heavier. There is a small problem, however, in that after each weighing, the apples must be returned to the box, each to the exact spot where it was before. After Emperor Pea returns the apples to the box, the worm immediately and unnoticed crawls into one of the two adjacent apples (and stays there until the next weighing). Help Emperor Pea find the wormy apple. (That is, after some weighing, Emperor Pea can accurately determine which apple the worm is currently inside before putting the apples back in the box. Minimizing the number of weighings is not necessary.)
# Solution.

Let's number the apples clockwise. The neighboring apples will be numbered 1 and 2, 2 and 3, ..., 12 and 13, 13 and 1.

Weigh apples 1, 2, 3, 4, 5, 6 against 7, 8, 9, 10, 11, 12.

If they are equal, then the worm is in apple 13.

Suppose 1, 2, ..., 6 are heavier.

Then after the apples are put back and the worm crawls somewhere, it can be in one of the apples numbered 13, 1, 2, 3, 4, 5, 6, 7.

Weigh 13, 1, 2, 3 against 4, 5, 6, 7.

Suppose 13, 1, 2, 3 are heavier.

After the worm crawls, it can be in one of the apples: 12, 13, 1, 2, 3, 4.

Weigh 12, 13, 1 against 2, 3, 4.

Suppose 12, 13, 1 are heavier.

After the worm crawls, it can be in one of the apples: 11, 12, 13, 1, 2.

Weigh 11, 12 against 1, 2.

If they are equal, then the worm is in apple 13.

Suppose 11, 12 are heavier. Then after the worm crawls, it is in one of the apples 10, 11, 12, 13.

Weigh 11 and 12.

If they are not equal, the worm is in the heavier one.

Otherwise, it is in 10 or 13 and after crawling in one of 9, 11, 12, 1.

Weigh 9 and 11.

If they are not equal, the worm is in the heavier one. Otherwise, it is in 12 or 1, after crawling in 11, 13, or 2.

Weigh 11 and 13. If they are not equal, the worm is in the heavier one. If they are equal, it is in 1.