Here’s a nifty invariant problem that we did in WOOT. I had trouble with it for a while but after reviewing stuff last night it magically made sense suddenly.
The sides of a 99-gon are initially colored so that consecutive sides are red, blue, red, blue,
red, blue, yellow. We make a sequence of modifications in the coloring, changing the color of one side at a time to one of the three given colors (red, blue, yellow), under the constraint that no two adjacent sides may be the same color. By making a sequence of such modifications, is it possible to arrive at the coloring in which consecutive sides
are red, blue, red, blue, red, blue,
red, yellow, blue?
(USAMO 1994, #2)
This was when the USAMO was only 5 problems in one session, instead of 6 problems split into two sessions, so this should be viewed as around a 1/4 difficulty level, as opposed to a 2/5.
Since we’re dealing with a problem where we are changing things, the first thing to do is to look for an invariant. That is, something that remains consistent, no matter what we change. A first natural step is to replace the colors with numbers. Lets say Red = 1, Blue = 2, Yellow = 3. Then we have the sequence:
1, 2, 1, 2, 1, 2 ….., 1, 2, 3
Which we want to transform to
1, 2, 1, 2 ,1, 2, …., 1, 3, 2
An easy way to look for an invariant is to make a move on our original sequence, and compare the resulting sequence to the original. For example, we can make the following change:
1, 2, 1, 2, 1, 2 ….., 1, 2, 3
->
1, 2, 3, 2, 1, 2 ….., 1, 2, 3
Now we begin searching for an invariant. It’s natural to only look at the area we changed:
2, 1, 2
->
2, 3, 2
It’s fairly obvious that the sum and product isn’t constant. Considering that the desired end state doesn’t vary in sum or product, it’s probably not worth investigating. Keeping in mind that it’s a rearrangement, and conjecturing that the end state won’t be reachable, we should look at an invariant which relates consecutive terms.
Looking at the original sequence and the altered sequence, one possible variant is the number of increases and decreases. For example, as we go from 2 ,to 1, to 2, we have one decrease and one increase in the value of the terms. As we go from 2 to 3 to 2, we also have one decrease and one increase. This is a possible invariant, and thus it should be checked if it applies to all such alterations. We will list all such ways of altering a triple by changing the second term of it. We may assume that the first and third terms are the same. If they weren’t, then it would not be possible to alter it, as it would result in two consecutive sides being the same color. All possible triple moves are:
(1, 2 ,1) (1, 3, 1)
(2, 1, 2) (2, 3, 2)
(3, 1, 3) (3, 2, 3)
Now we can see that our invariant holds for all possible moves. So we need a way of relating this to the entire sequence. I did this as follows:
Define a function f(a,b) = 1 if b > a , and -1 if b < a
Define the oscillating sum of a 99-gon labeled with numbers to be:

where
is the number corresponding with the ith side. Because of the invariant we discovered, making a legal move does not affect this oscillating sum.
It's easy to see that the oscillating sum for the beginning state is 1, while the oscillating sum for the desired stage is -1. Thus, it cannot be achieved through through the legal moves described.