This page is still under construction.

Parts of this page are still being built. What you see may change.

Fighting for Triangles

Time limit2sMemory limit512 MB

Summary
On a triangular board with some edges already drawn, two players alternate adding edges, claiming a unit triangle when their edge completes it. Decide the winner with optimal play.
Level

Medium7 of 10

Topics
Game theory, Graph, Simulation, Backtracking
Solved
No attempts yet

Problem

Andy and Ralph are playing a two-player game on a triangular board like the one below.

On each turn, a player must choose two adjacent vertices and draw the line segment (edge) that connects them. If the newly drawn edge completes a triangle on the board — only the smallest unit triangles count — the player claims that triangle and immediately draws another edge. Otherwise the turn ends and the other player moves. Each player tries to claim as many triangles as possible. Andy always moves first.

For example, suppose it is Andy's turn and the board already has the five edges shown below. If Andy draws edge 66, he completes the triangle formed by edges 44, 55, and 66, claims it, and keeps playing.

Given a board that already has some edges drawn on it, determine the winner assuming both players play optimally. Note that if a triangle is already present on the board before the first move, neither player claims it.

Input

The input consists of several test cases. Each test case begins with a line containing an integer NN (5≤N≤105 \le N \le 10), the number of edges already drawn on the board before the game begins. The next line contains NN integers, the indices of those edges. The input ends with a line containing N=0N = 0.

Output

For each test case, print a single line with the result of the game. Print Andy wins if Andy claims more triangles, Ralph wins if Ralph claims more, or Draw if both players claim the same number of triangles.

Examples2

  1. Example 1

    Input
    6
    1 2 3 4 5 6
    5
    4 5 6 7 8
    0
    
    Expected output
    Andy wins
    Ralph wins
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    0
    
    Expected output
    Andy wins