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.