All problems

Problem 499

Tic-Tac-Toe Winner

Easy · 10 pts · Array, Matrix, Simulation

Problem

Two players, A and B, play tic-tac-toe on a 3 x 3 grid. A always moves first, and they alternate. You are given the list of moves as (row, column) pairs, starting from 0; all moves are valid, and no moves are made after the game is won. A player wins by filling a whole row, column or diagonal with their marks. Print A or B if that player has won, Draw if the board is full with no winner, or Pending if the game is not over yet.

Input

First line: N, the number of moves. Next N lines: row and column of each move.

Output

Print A, B, Draw or Pending.

Constraints

1 <= N <= 9; moves are valid and stop once someone wins

Example input

5
0 0
2 0
1 1
2 1
2 2

Example output

A

Explanation

A plays (0,0), (1,1) and (2,2), filling the main diagonal before B completes any line, so A wins.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Walking Robot Simulation Next: Battleships in a Board