Tic-tac-toe
Tic-tac-toe on an infinite board is a game played by two players on an endless grid. Players alternate turns, and during each turn, a player places their symbol in any unoccupied cell on the board. The first player uses the symbol 'X' (cross), while the second player uses 'O' (nought).
The game is won by the player who first aligns five of their symbols consecutively in a row, column, or diagonal. Once this condition is met, the game concludes with that player as the winner.
One day, a bright student named Anton discovered a drawing of crosses and noughts in his notebook. He is unsure whether it represents the state of a game he played with his friend Alexey or is merely a random doodle.
Your task is to write a program that determines if the depicted position could have resulted from a legitimate game of tic-tac-toe on an infinite board, whether the game is finished or still in progress. Assume that the players always adhere to the rules.
Input
The input file contains the illustration from Anton's notebook. Empty cells are represented by the symbol '.' (dot). The symbols for the players are represented by 'X' and 'O' (uppercase Latin letters 'X' and 'O').
The input file will have no more than 100 lines, and each line will contain no more than 100 characters. There are no blank lines in the file. It is guaranteed that at least one 'X' or 'O' will be present in the input file.
Output
Print the word CORRECT if the position shown could have resulted from a valid tic-tac-toe game on an infinite board (either at the end or during the game). Otherwise, print the word INCORRECT.