You are given a natural number and a permutation of the numbers . Since is a permutation, it has length and each number from to appears exactly once. You are allowed to swap two elements if their positions are exactly apart. In other words, you may swap and only if . Determine if can be sorted from least to greatest.
Constraints
Subtask 1 [40%]
Subtask 2 [60%]
Input Specification
The first line will contain two space-separated integers, and .
The next line will contain space-separated integers, .
Output Specification
Output YES
if it may be sorted and NO
otherwise.
Sample Input 1
5 1
1 4 3 2 5
Sample Output 1
YES
Explanation for Sample 1
Swap and . The sequence is now 1 4 2 3 5
.
Swap and . The sequence is now 1 2 4 3 5
.
Swap and . The sequence is now 1 2 3 4 5
, which is sorted.
Sample Input 2
5 2
5 4 3 2 1
Sample Output 2
YES
Explanation for Sample 2
Swap and . The sequence is now 5 2 3 4 1
.
Swap and . The sequence is now 3 2 5 4 1
.
Swap and . The sequence is now 3 2 1 4 5
.
Swap and . The sequence is now 1 2 3 4 5
, which is sorted.
Sample Input 3
5 3
5 4 3 2 1
Sample Output 3
NO
Comments