#K80417. Monotonic Array Check

    ID: 35526 Type: Default 1000ms 256MiB

Monotonic Array Check

Monotonic Array Check

Given an array of integers, determine whether the array is monotonic. An array is considered monotonic if it is either entirely non-decreasing or entirely non-increasing.

In mathematical notation, a sequence \(a_1, a_2, \ldots, a_n\) is monotonic if either \(a_1 \le a_2 \le \cdots \le a_n\) or \(a_1 \ge a_2 \ge \cdots \ge a_n\).

inputFormat

The input is read from standard input (stdin). The first line contains an integer \(n\), which is the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output to standard output (stdout) a single line containing "YES" if the array is monotonic, and "NO" otherwise.

## sample
5
1 2 2 3 4
YES