Winner of the Bubble Game
Time limit2sMemory limit512 MB
Two players alternately swap adjacent out-of-order pairs until the permutation is sorted; the one who cannot move loses. Decide the winner.
- Level
Medium5 of 10
- Topics
- Combinatorics, Game theory, Math
- Solved
- No attempts yet
Problem
Andrea, Carlos and Marcelo spend every weekend at the pool. While Andrea sunbathes, the other two play a game called Bubbles. Andrea studies computer science and tells them she does not see why such a simple game takes them so long.
On Andrea's laptop the two players generate a random integer and a random permutation of .
The players move in turn and Marcelo always starts.
A move is to pick a pair of consecutive elements of the sequence that are out of order and swap the two elements. For the sequence a player may swap 5 and 3, or swap 4 and 2, but may not swap 3 and 4, and may not swap 5 and 2. Swapping 5 and 3 turns the sequence into .
Sooner or later the sequence ends up sorted in increasing order. The player who has no move on their turn loses.
Andrea says with some disdain that a coin flip would settle it just as well. Given the initial sequence, decide who wins.
Input
The input contains several test cases. Each test case is given on a single line, with the integers separated by one space. Each line starts with an integer (), followed by the initial sequence of pairwise distinct integers, where for every .
The last line of the input contains a single .
Output
For each test case print one line holding the name of the winner, either Carlos or Marcelo, with no extra spaces.