Under construction

Still being built. Things may change

Sudoku

Time limit1sMemory limit1024 MB

Summary
Given a partially filled 9x9 sudoku grid, decide whether any row, column, or 3x3 subgrid repeats a digit.
Level

Easy2 of 10

Topics
Implementation, Matrix
Solved
No attempts yet

Problem

Sudoku is a logic-based combinatorial number-placement puzzle. The goal is to fill a 9×99 \times 9 grid with the digits 1 to 9 so that the following hold:

  • Each row contains each digit from 1 to 9 exactly once.
  • Each column contains each digit from 1 to 9 exactly once.
  • Each of the nine 3×33 \times 3 subgrids contains each digit from 1 to 9 exactly once.

Given a sudoku grid that is not yet finished, determine whether it contains a mistake. You do not need to check whether the grid is solvable.

Input

The input describes the sudoku grid. The characters |, -, and + frame the 3×33 \times 3 subgrids. The character . represents an empty cell. All other characters are digits from 1 to 9.

Output

Print GRESKA if the board contains a mistake. Otherwise, print OK.

Hint

In the first example there is no mistake, so the output is OK. In the second example, the digit 5 appears twice in the ninth column, and the digit 5 also appears twice in the lower right 3×33 \times 3 subgrid. In the third example, the digit 2 appears twice in the second column and the digit 6 appears twice in the seventh column, so there are two mistakes.

Examples3

  1. Example 1

    Input
    +---+---+---+
    |52.|...|.81|
    |.39|58.|...|
    |.8.|.9.|...|
    +---+---+---+
    |24.|...|1.3|
    |1..|43.|86.|
    |.63|..7|.24|
    +---+---+---+
    |...|1.9|35.|
    |..8|.74|6..|
    |31.|86.|7.9|
    +---+---+---+
    
    Expected output
    OK
    
  2. Example 2

    Input
    +---+---+---+
    |3..|6..|..4|
    |4.9|8.1|..7|
    |..7|.49|6..|
    +---+---+---+
    |946|157|8.2|
    |.2.|3..|745|
    |.7.|28.|...|
    +---+---+---+
    |...|4..|..5|
    |8.5|.6.|.2.|
    |734|..8|5..|
    +---+---+---+
    
    Expected output
    GRESKA
    
  3. Example 3

    Input
    +---+---+---+
    |5..|98.|67.|
    |6..|...|.31|
    |.2.|613|.4.|
    +---+---+---+
    |.96|8.2|1.7|
    |.28|..5|.9.|
    |7.3|19.|6..|
    +---+---+---+
    |962|.7.|.1.|
    |1.5|...|76.|
    |.7.|5..|9..|
    +---+---+---+
    
    Expected output
    GRESKA