Try this
1
2
10
There should be one card sequence for two cards. The 10 shouldn’t be processed, but this is what I get. And of course, there is no card 0 in the sequence for 2.
0 1
9 1 8 5 2 4 7 6 3 10
9 1 8 5 2 4 7 6 3 10
At a guess, I’d say you were writing outside the bounds of an array.