Tic-Tac-Toe

Time limit1sMemory limit128 MB

Problem

The game of Tic-Tac-Toe is played on an $n \times n$ grid (where $n$ is usually but not necessarily three). Two players alternate placing symbols on squares of the grid. One player places Xs and the other places Os, and the player placing Xs always goes first. When the grid contains a vertical, horizontal, or diagonal sequence of at least $m$ consecutive squares that all contain the same symbol, the game ends and the winner is the player who placed the last symbol. When every square of the grid is filled and neither player has won, the game ends in a draw.

Your task is to analyze the state of a Tic-Tac-Toe board and determine whether the game is still in progress, or if it has finished — who won, or whether it ended in a draw. You must also detect erroneous board states that could never occur during an actual game.

Input

The first line contains two integers $n$ and $m$, separated by a space, with $1 \le m \le n \le 2000$. Each of the following $n$ lines contains one row of the board. Each such line contains exactly $n$ characters, and each character is either an X, an O, or a period (.) denoting an empty square.

Output

Output a single line: X WINS, O WINS, or DRAW if the game is over; IN PROGRESS if the game has not yet finished; or ERROR if the state of the board could never occur during a game.