Problem list
Log in
#coci00033 · COCI 2006/2007 Contest 6

Maraton

Silver III 1.0 s 32 MB

Albert, Barbara, Casper, Dinko, Eustahije are starting a marathon game of tic-tac-toe, played on an $N \times N$ board.

Initially, all squares on the board are empty and players take turns writing the first letter of their name into any of the empty squares (because the players are elite, no two players have the same first letter). The game ends when some player places $N$ of his or her letters consecutively in a row, column or diagonally. That player is declared the winner.

Write a program that, given the state of the board, determines if the game is over and who won if it is.

Input

The first line of input contains the integer $N$ ($1 \le N \le 100$), the size of the board.

The following $N$ lines contain $N$ characters each. The characters will be uppercase letters of the English alphabet or . (if the square is empty).

The input data will be such that there is at most one winner.

Output

If the game is over, output the first letter of the winner's name. If not, output ongoing (even if the board is full).

Example 1

Input
3
XOC
XOC
X..
Output
X

Example 2

Input
4
....
..A.
AAB.
.B.B
Output
ongoing

Example 3

Input
3
ABB
AAA
BBA
Output
A
Source
COCI 2006/2007 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code