#K61167. Almost Sorted Sequence

    ID: 31250 Type: Default 1000ms 256MiB

Almost Sorted Sequence

Almost Sorted Sequence

You are given a sequence of n integers: \(a_1, a_2, \ldots, a_n\). The sequence is considered almost sorted if either it is already sorted in non-decreasing order or it can be made sorted by removing exactly one element.

Formally, a sequence is almost sorted if either:

  • \(a_1 \le a_2 \le \cdots \le a_n\), or
  • There exists an index \(i\) (\(1 \le i \le n\)) such that if you remove \(a_i\), the remaining sequence is sorted in non-decreasing order.

Your task is to determine if a given sequence is almost sorted according to the above definition. Output Yes if it is, otherwise output No.

inputFormat

The input is read from standard input and consists of two lines:

  1. The first line contains an integer \(n\) (the number of elements in the sequence).
  2. The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\).

outputFormat

Output a single line to standard output with Yes if the sequence is almost sorted, or No otherwise.

## sample
6
1 2 7 4 5 6
Yes

</p>