#C5213. Monotonic Partitioning

    ID: 48838 Type: Default 1000ms 256MiB

Monotonic Partitioning

Monotonic Partitioning

You are given an array of integers \(A = [a_1, a_2, \ldots, a_n]\). Your task is to determine whether the array can be partitioned into one or more contiguous segments such that each segment is strictly increasing or strictly decreasing.

A segment \(A[l..r]\) is strictly increasing if \(a_l < a_{l+1} < \cdots < a_r\) and strictly decreasing if \(a_l > a_{l+1} > \cdots > a_r\). Note that no two adjacent elements in any segment can be equal. The entire array must follow this pattern with at most one switch from increasing to decreasing. If an array does not satisfy these conditions, output NO; otherwise, output YES.

Note: An empty array or an array with a single element is considered valid.

inputFormat

The input is given via standard input. The first line contains an integer \(n\), denoting the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

Output a single line containing either YES if it is possible to partition the array as described, or NO otherwise.

## sample
0
YES