old updated
a count count aux
0 412 0 0 01 0 410
1 012 1 1 123 1 101
2 101 2 2 34567 2 201
3 432 3 4 7 3 412
4 302 4 0 7 4 012
5 201 5 0 7 5 432
6 410 6 0 7 6 302
. . .
. . .
9 0 7
For the last step, copy aux back into a.