COCI '06 Contest 6 #3 Maraton

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 3 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 Specification

The first line of input contains the integer N\ (1 \le N \le 30), 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 Specification

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

Sample Input 1


Sample Output 1


Sample Input 2


Sample Output 2


Sample Input 3


Sample Output 3



There are no comments at the moment.