#K92342. Uniform Boundary Subgrid

    ID: 38176 Type: Default 1000ms 256MiB

Uniform Boundary Subgrid

Uniform Boundary Subgrid

In this problem, you are given an n (\times) m grid composed of lowercase characters. Your task is to determine whether there exists a rectangular subgrid (with at least 2 rows and 2 columns) such that all of its boundary cells have the same character. In other words, for some indices (x_1, y_1, x_2, y_2) with (0 \le x_1 < x_2 < n) and (0 \le y_1 < y_2 < m), check if every cell on the boundary of the rectangle defined by the top-left corner ((x_1, y_1)) and bottom-right corner ((x_2, y_2)) contains an identical character.

Note: A subgrid must have at least 2 rows and 2 columns. If no such subgrid exists, print NO.

inputFormat

The first line contains two integers (n) and (m) denoting the number of rows and columns, respectively. Each of the following (n) lines contains a string of length (m) representing a row of the grid.

outputFormat

Output a single line containing YES if a rectangular subgrid exists that satisfies the condition, or NO otherwise.## sample

4 5
aaaaa
abbba
abbba
aaaaa
YES