#C4984. Toeplitz Matrix
Toeplitz Matrix
Toeplitz Matrix
We define a Toeplitz matrix as a matrix in which every diagonal from top-left to bottom-right is constant. In other words, for a matrix (A) of size (M \times N), it must hold that (A[i][j] = A[i-1][j-1]) for all (1 \leq i < M) and (1 \leq j < N).
For example, consider the matrix below:
1 2 3 4 5 1 2 3 6 5 1 2
Since every diagonal contains the same value, the answer should be YES
.
In contrast, the following matrix is not Toeplitz:
1 2 3 4 5 1 9 3 6 5 1 2
because the diagonal starting from the second element in the second row has differing elements. Thus, the answer in that case is NO
.
inputFormat
The input is given via STDIN. The first line contains two integers (M) and (N), representing the number of rows and columns of the matrix respectively. The following (M) lines each contain (N) integers separated by spaces, representing the elements of the matrix.
outputFormat
Output a single line to STDOUT: YES
if the given matrix is a Toeplitz matrix, and NO
otherwise.## sample
3 4
1 2 3 4
5 1 2 3
6 5 1 2
YES