#K73572. Find 'CODE' in the Grid

    ID: 34005 Type: Default 1000ms 256MiB

Find 'CODE' in the Grid

Find 'CODE' in the Grid

You are given a two-dimensional grid of characters. Your task is to determine whether the word $CODE$ can be formed by a sequence of adjacent cells. Two cells are considered adjacent if they share a side or a corner (i.e., horizontally, vertically, or diagonally). Each cell may be used at most once in the formation of the word.

Note: All letters in the grid and in the word are case-sensitive, and the word must be formed exactly as CODE (all in uppercase).

Example: Consider the grid below:

C A T
B O D
R E E

One possible way to form CODE is by following the path: (0,0) -> (1,1) -> (1,2) -> (2,2). In this case, the answer is True.

inputFormat

The first line contains two integers n and m separated by a space, representing the number of rows and columns of the grid respectively. The next n lines each contain m characters (each separated by a space) representing the grid.

For example:

3 3
C A T
B O D
R E E

outputFormat

Output a single line: True if the word CODE can be formed in the grid following the rules; otherwise, output False.

## sample
3 3
C A T
B O D
R E E
True