All problems

Problem 490

Toeplitz Matrix

Easy · 10 pts · Matrix

Problem

A matrix is Toeplitz if every diagonal running from top-left to bottom-right contains a single repeated value. Equivalently, every element equals the element diagonally above and to the left of it (whenever that element exists). Decide whether the given matrix is Toeplitz.

Input

First line: R and C. Next R lines: C integers each.

Output

Print YES if the matrix is Toeplitz, otherwise NO.

Constraints

1 <= R, C <= 100; 0 <= value <= 99

Example input

3 4
1 2 3 4
5 1 2 3
9 5 1 2

Example output

YES

Explanation

In 1 2 3 4 / 5 1 2 3 / 9 5 1 2, every top-left to bottom-right diagonal holds one value (for example 1 1 1 and 2 2 2), so the answer is YES.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Matrix Diagonal Sum Next: Search a Row-Column Sorted Matrix