#C8361. Bookshelf Sorting

    ID: 52335 Type: Default 1000ms 256MiB

Bookshelf Sorting

Bookshelf Sorting

Given a list of book titles, determine whether the books on the shelf are sorted in alphabetical order. The ordering is based on the standard lexicographical order, i.e. using the natural string comparison.

If the list is sorted, print YES; otherwise, print NO. An empty list or a list with a single title is considered sorted.

For example, in the list:

  • A Brief History of Time
  • Cosmos
  • The Elegant Universe

the answer is YES because:

\(\text{A Brief History of Time} \leq \text{Cosmos} \leq \text{The Elegant Universe}\)

where the comparison is done lexicographically.

inputFormat

The input is given via standard input in the following format:

 n
 title_1
 title_2
 ...
 title_n

Here, n is a non-negative integer representing the number of books on the shelf, and the following n lines each contain a book title.

outputFormat

Output a single line to standard output containing YES if the books are sorted alphabetically and NO otherwise.

## sample
3
A Brief History of Time
Cosmos
The Elegant Universe
YES