#P6369. [COCI 2006/2007 #6] MARATON

[COCI 2006/2007 #6] MARATON

Problem Description

Given an n×nn \times n square board, several players are playing tic-tac-toe on it.

The rules of tic-tac-toe are: each player takes turns writing a letter, and all letters written by the same player are identical. If a player forms 33 consecutive copies of their own letter in a row, a column, or a diagonal, then that player wins.

Given the current state of the board, find the winning player.

Input Format

The first line contains an integer nn.

The next nn lines each contain nn characters, which are either uppercase letters or . (meaning no one has played on that cell).

Output Format

Output one uppercase letter on a single line, representing the letter written by the winning player.

If no one has won, output ongoing.

The testdata guarantees that at most one player has won.

3
XOC
XOC
X..
X
4
....
..A.
AAB.
.B.B
ongoing
3
ABB
AAA
BBA
A

Hint

Constraints

For 100%100\% of the testdata, 1n301 \le n \le 30.

Notes

This problem is translated from COCI2006-2007 CONTEST #6 T3 MARATON

Translated by ChatGPT 5