eolymp
bolt
Try our new interface for solving problems
Problems

Fighting for Triangles

Fighting for Triangles

Andy and Ralph are playing a two-player game on a triangular board that looks like the following: \includegraphics{https://static.e-olymp.com/content/39/39eb4fe8cd7f10e8a5383fc4ba20d9ec0fb66f78.jpg} At each turn, a player must choose two adjacent vertices and draw a line segment that connects them. If the newly drawn edge results in a triangle on the board (only the smallest ones count), then the player claims the triangle and draws another edge. Otherwise, the turn ends and the other player plays. The objective of the game is to claim as many triangles as possible. For example, assume that it is Andy’s turn, where the board has fives edges as shown in the picture below. If Andy draws edge \textbf{6}, then he will claim the triangle formed by edge \textbf{4}, \textbf{5}, and \textbf{6}, and continue playing. \includegraphics{https://static.e-olymp.com/content/6c/6c1ca351c52c8a0c08e918fc8cc5c44bef0a1f85.jpg} Given a board that already has some edges drawn on it, decide the winner of the game assuming that both Andy and Ralph play optimally. Andy always goes first. Note that if a triangle exists on the board before the first move, neither player claims it. \InputFile The input consists of multiple test cases. Each test case begins with a line containing an integer \textbf{N}, \textbf{5} ≤ \textbf{N} ≤ \textbf{10}, which indicates the number of edges that are already present on the board before the game begins. The next line contains \textbf{N} integers, indicating the indices of these edges. The input terminates with a line with \textbf{N = 0}. \OutputFile For each test case, print out a single line that contains the result of the game. If Andy wins, then print out "\textbf{Andy wins}". If Ralph wins, then print out "\textbf{Ralph wins"}. If both players get the same number of triangles, then print out "\textbf{Draw}". Quotation marks are used for clarity and should not be printed.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6
1 2 3 4 5 6
5
4 5 6 7 8
0
Output example #1
Andy wins
Ralph wins
Source 2011 Stanford Local ACM Programming Contest, Saturday, October 8th, 2011