cho.sh
NotesCho Mini
Loading...

Omok

Time limit

1s

Memory limit

128 MB

Problem

Omok is played on a board with 19 horizontal lines and 19 vertical lines using black stones (1) and white stones (2). The horizontal lines are numbered 1 through 19 from top to bottom, and the vertical lines are numbered 1 through 19 from left to right.

A color wins when exactly five stones of that color are consecutive horizontally, vertically, or diagonally. A line of six or more consecutive stones is not a win.

Given the current board, determine whether black has won, white has won, or the game has not been decided yet. The input will not contain a position where both colors win at the same time or where one color wins in more than one place at the same time.

Input

The input consists of 19 lines. Each line contains 19 integers separated by spaces. A 1 means a black stone, a 2 means a white stone, and a 0 means an empty point.

Output

On the first line, print 1 if black wins, 2 if white wins, and 0 if the game has not been decided yet.

If black or white wins, print on the second line the row number and column number of the leftmost stone among the five consecutive stones, in that order. If the five stones are vertical, print the coordinate of the topmost stone among them.