#K72812. Unique Maximum Matrix

    ID: 33837 Type: Default 1000ms 256MiB

Unique Maximum Matrix

Unique Maximum Matrix

You are given a matrix \(A\) with \(N\) rows and \(M\) columns. Your task is to determine whether the matrix is a special matrix. A matrix is considered special if it satisfies all of the following conditions:

  • The matrix does not contain any 0 entries.
  • Every row has a unique maximum element. In other words, if \(max(A_{i,*})\) is the maximum value in row \(i\), it must occur exactly once in that row.
  • Every column has a unique maximum element. That is, if \(max(A_{*,j})\) is the maximum value in column \(j\), it must appear exactly once in that column.

If all conditions are met, print YES; otherwise, print NO.

inputFormat

The first line of input contains two integers \(N\) and \(M\) (the number of rows and columns respectively). This is followed by \(N\) lines, each containing \(M\) space-separated integers representing the matrix \(A\).

outputFormat

Output a single line containing YES if the matrix is special, or NO otherwise.

## sample
3 3
10 5 3
1 20 4
2 8 30
YES