Before shuffling a deck of cards, you notice that the card on the bottom of the deck is an ace.
Thinking that it may be advantageous to know where this ace ends up, you decide to keep track of its position in the deck while shuffling.
The shuffles will be given as a list of integers.
A shuffle characterized by a positive integer, n, is performed as follows. The deck is split into two halves of equal size, a top half and a bottom half. n cards are dropped (in order) from the bottom of the bottom half of the deck. Then, starting with the top half, cards are dropped one at a time from the bottom of each half, alternating between halves of the deck, until every card in the bottom half has been dropped. At this point, there are n cards remaining in the top half of the deck, which are dropped in order.
A shuffle characterized by a negative integer is performed similarly, with the bottom and top halves of the deck reversed.
The following figures depict shuffles with values of 3 and 4, respectively, of a 12card deck:
Given cards, the number of cards in the deck, and shuffles, a int[] characterizing each of the shuffles you perform, return the final position of the ace. (A value of 0 indicates the bottom of the deck, and a value of cards1 indicates the top of the deck.)
