#C3428. Taco Lexicographical Grid Sorting

    ID: 46854 Type: Default 1000ms 256MiB

Taco Lexicographical Grid Sorting

Taco Lexicographical Grid Sorting

You are given a grid with n rows and m columns. Each row of the grid is represented as a string. Your task is to determine whether the grid is already sorted in lexicographical order by rows. In other words, by considering each row as an element, check if the grid is sorted in non-decreasing order.

Formally, given an array of strings \(grid = [s_1, s_2, \ldots, s_n]\), the grid is considered lexicographically sorted if:

\(s_1 \leq s_2 \leq \cdots \leq s_n\)

Output "YES" if the grid is sorted; otherwise, output "NO".

inputFormat

The input is read from standard input (stdin) in the following format:

  • The first line contains two integers n and m separated by a space, representing the number of rows and the number of columns respectively.
  • The next n lines each contain a string of length m, representing the rows of the grid.

outputFormat

Output a single line to standard output (stdout) containing either "YES" if the grid is already sorted lexicographically or "NO" if it is not.

## sample
3 3
011
101
110
YES