#K69262. Longest Consistent Letter Sequence

    ID: 33048 Type: Default 1000ms 256MiB

Longest Consistent Letter Sequence

Longest Consistent Letter Sequence

You are given an $N \times N$ grid consisting of lowercase letters. Your task is to find the length of the longest contiguous sequence of identical letters in the grid. The sequence can extend in any of the following four directions:

  • Horizontally (left to right)
  • Vertically (top to bottom)
  • Diagonally from top-left to bottom-right
  • Diagonally from top-right to bottom-left

For example, in the grid below:

abcd
eeee
fghi
jklm

the longest contiguous sequence is 'e' repeated 4 times (vertically) so the answer is 4. Your solution should read from standard input and write the answer to standard output.

inputFormat

The first line contains an integer $N$ representing the size of the grid. The following $N$ lines each contain a string of length $N$ consisting of lowercase letters, representing the grid.

Input is given via standard input (stdin).

outputFormat

Output a single integer — the length of the longest contiguous sequence of identical letters found in the grid. Output should be written to standard output (stdout).

## sample
4
abcd
eeee
fghi
jklm
4