problems / 250

Suki's Striped Blanket

easy matrix arrays strings 1000 ms · 256 MB

Suki's Striped Blanket

Suki, a black curly-coated dog with a grey beard and white paws, has a favourite nap blanket. It is woven as a grid of R rows and C columns of coloured squares, and it is supposed to have diagonal stripes: every square should have the same colour as the square diagonally up and to its left. Before she settles down for her afternoon nap, Suki wants to check the pattern.

Rows are numbered 1 to R from top to bottom and columns 1 to C from left to right. A square (r, c) with r ≥ 2 and c ≥ 2 is wrong if its colour differs from the colour of square (r − 1, c − 1). Squares in the first row or the first column have no up-left neighbour and are never wrong.

If no square is wrong, the blanket is perfect. Otherwise, report the first wrong square in reading order: the one with the smallest row, and among those, the smallest column.

Input

The first line contains two integers R and C (1 ≤ R, C ≤ 1000).

Each of the next R lines contains a string of exactly C lowercase English letters: the colours of one row of the blanket, from left to right.

Output

If the blanket is perfect, print YES.

Otherwise, print NO on the first line and, on the second line, two integers r and c: the row and column of the first wrong square in reading order.

Notes

In the first example every top-left to bottom-right diagonal has a single colour, so the blanket is perfect.

In the second example, squares (2, 4), (3, 2) and (3, 4) are wrong. Square (2, 4) comes first in reading order because it is in an earlier row, even though (3, 2) is further left.

Example 1

Input

3 4
abcd
eabc
feab

Output

YES

Example 2

Input

3 4
abcd
eabx
fzax

Output

NO
2 4

Hints · reveal one at a time if you're stuck

Hint 1

You never need to look at a whole stripe at once. Which single other square decides whether square (r, c) is wrong?

Hint 2

Checking each square only against its up-left neighbour is enough. What matters is the order you check them in: the second example shows that the leftmost wrong square is not always the one to report.

report an issue Prefer your own editor? sooks prep 250 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.