#K61162. Almost Sorted Sequence

    ID: 31249 Type: Default 1000ms 256MiB

Almost Sorted Sequence

Almost Sorted Sequence

Given an array of integers, determine whether it is possible to remove at most one element such that the remaining sequence is non-decreasing. In other words, check if there exists a way to remove one element (or none) so that the resulting sequence satisfies

A1A2An1,A_1 \le A_2 \le \cdots \le A_{n-1},

where \(A\) is the sequence after removal. If such a removal is possible, output YES; otherwise, output NO.

Note: A sequence with a single element or a sequence that is already non-decreasing is considered valid.

inputFormat

The first line contains an integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output a single line containing YES if the array can be converted into a non-decreasing sequence by removing at most one element, otherwise output NO.

## sample
5
10 5 7 10 12
YES

</p>