Simple example of invariants The combinatorics textbook I'm reading introduces invariants with the following example: 

There are three piles with $n$ tokens each. In every step we are allowed
  to choose two piles, take one token from each of those two piles and add a token to
  the third pile. Using these moves, is it possible to end up having only one token?

Solution: To the tokens in the first pile we can assign the pair $(0, 1)$, to the tokens
in the second pile the pair $(1, 0)$ and to the tokens in the third pile the pair $(1, 1)$.
Notice that the sum modulo $2$ of any two of these pairs give us the third one. Thus,
in every step the sum modulo $2$ of all the assigned pairs is the same. However, the
sum of all the assigned pairs in the beginning is $(2n, 2n)$, which is equal to $(0, 0)$
modulo $2$. Since this pair was not assigned to any pile, it is not possible to end up
with only one token.
Although I already knew what invariants are, I do not understand how they're applied in this specific case, what is the meaning of the pairs that are assigned to each pile, and how is a pair affected by a step?
 A: The solution can be simplified. The invariant is the condition that all three piles have the same parity of tokens. The initial state is all three piles have $\,n\,$ tokens which implies the invariant condition is true. In each step, the parity of each pile is changed from even to odd or odd to even, and therefore if the invariant condition is true before the step, then it is true after the step. By induction, the invariant condition always is true. Thus, if there is only one token left, the three parities are even, even, and odd and the invariant condition is false.
A: Let $a,b,c$ be the number of tokens in the first, second and third pile. Observe that in each step, the parity of $a+b$, $a+c$ are preserved after the operation. Let us make this observation formal. We have $2$ dimensional data $$(a+b,a+c)=a(1,1)+b(1,0)+c(0,1).$$ Since we are tracking its parity, we have this vector in $\Bbb Z_2\times \Bbb Z_2$, i.e. in modulo $2$. This gives us the introduced invariant
$$
I=a(1,1)+b(1,0)+c(0,1)\quad(\text{mod }2).
$$
