#C4863. Taco Sequence Sorting

    ID: 48448 Type: Default 1000ms 256MiB

Taco Sequence Sorting

Taco Sequence Sorting

You are given a sequence of n cards, each with a unique integer from 1 to n. Kevin can perform any number of operations where he reverses any subsequence (not necessarily contiguous) of the sequence. Prove that using these operations, it is always possible to sort the sequence in non-decreasing order. In other words, regardless of the initial arrangement, you must print YES if the sequence can be sorted and NO otherwise.

Mathematically, for any permutation ( \pi ) of ( {1, 2, \dots, n} ), reversing appropriate subsequences can transform ( \pi ) into the sorted sequence ( (1, 2, \dots, n) ).

inputFormat

The input is read from standard input. The first line contains an integer ( n ) representing the number of cards. The second line contains ( n ) space-separated integers describing the current sequence.

outputFormat

Output a single line to standard output. Print YES if the sequence can be sorted using an arbitrary number of reversal operations. Otherwise, print NO.## sample

5
3 1 2 4 5
YES