P6369 [COCI 2006/2007 #6] MARATON

Description

Given an $n \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 $3$ 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 $n$. The next $n$ lines each contain $n$ 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.

Explanation/Hint

#### Constraints For $100\%$ of the testdata, $1 \le n \le 30$. #### Notes **This problem is translated from [COCI2006-2007](https://hsin.hr/coci/archive/2006_2007/) [CONTEST #6](https://hsin.hr/coci/archive/2006_2007/contest6_tasks.pdf) *T3 MARATON***。 Translated by ChatGPT 5