How to decompose a permutation into a pair of labeled Dyck paths by playing a game

We give a bijection between permutations of length 2n and certain pairs of Dyck paths with labels on the down steps. The bijection arises from a game in which two players alternate selecting from a set of 2n items: the permutation encodes the players' preference ordering of the items, and the Dyck paths encode the order in which items are selected under optimal play. We enumerate permutations by certain statistics, AA inversions and BB inversions, which have natural interpretations in terms of the game. We give new proofs of classical identities such as \sum_p \prod_{i=1}^n q^{h_i -1} [h_i]_q = [1]_q [3]_q ... [2n-1]_q where the sum is over all Dyck paths p of length 2n, and the h_i are the heights of the down steps of p.