58. Along a circle, there are $n$ coins, each lying heads or tails up. If two adjacent coins lie the same way (both heads or both tails), it is allowed to flip both. How many arrangements of coins are there that cannot be obtained from each other by applying such operations?
58. Answer: 2 variants for odd $n$ and $n+1$ variants for even $n$.

Notice that the operation is reversible. For odd $n$, we will show that all coins can be oriented in the same direction. Divide the coins into groups of consecutive coins with the same orientation. If there are at least two groups, they alternate, so there is an even number of them. Therefore, at least one group has an even number of coins. By flipping these coins, we reduce the number of groups. By sequentially reducing the number of groups with such actions, we can make only one group and, thus, turn all the coins in the same direction. Therefore, there are no more than two variants of coin placement that cannot be obtained from each other. Since the operation does not change the parity of the number of heads, the placement with all heads cannot be translated into the placement with all tails. Therefore, there are exactly two variants.

Now let's move on to the case of even $n$. We will learn how to translate coin placements into the simplest possible configuration and then count the number of such simple configurations that cannot be obtained from each other. Mark a point near any of the coins on the circle. Divide the coins into groups of consecutive coins with the same orientation. We will flip groups with an even number of coins until such groups disappear or only one group remains. If several groups remain, they are all odd. Note that if there are at least three coins in some group, two of them can be moved to the neighboring group. Indeed, this can be done with the replacements

$$
\mathrm{OP} \mathrm{OO} \mathrm{O} \rightarrow \text { OPPPO. }
$$

Thus, we will reduce everything to a configuration where there is one large group, and the rest of the coins alternate. Moreover, we can assume that the first coin of the large group is near the marked point. Therefore, the configurations differ only in the number of coins in the large group and their orientation. If there is only one group, the orientation does not matter, since all the coins can be flipped.

We will show that all other configurations cannot be obtained from each other. Indeed, our operation does not change the difference between the number of heads in even positions and the number of heads in odd positions. When the large group consists of one head, i.e., when all heads are in odd positions and tails are in even positions, this difference is $n / 2$. Increasing the number of heads in the large group reduces this difference by 1, so all differences from 0 to $n / 2$ are possible. Similarly, when the large group consists of tails, differences from -1 to $-n / 2$ are obtained. In total, we get $n+1$ different configurations.