Problem7982--ABC254 —— C - K Swap

7982: ABC254 —— C - K Swap

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

We have a sequence of length $N:\ A=(a_1,…,a_N)$. Additionally, you are given an integer K.
You can perform the following operation zero or more times.
  • Choose an integer i such that 1≤i≤N−K, then swap the values of $a_i$ and $a_{i+K}$.
Determine whether it is possible to sort A in ascending order.

Input

Input is given from Standard Input in the following format:
$N\ K$
$a_1\ …\ a_N$

Output

If it is possible to sort A in ascending order, print Yes; otherwise, print No.

Constraints

$2≤N≤2×10^5$
$1≤K≤N−1$
$1≤a_i≤10^9$
All values in input are integers.

Sample 1 Input

5 2
3 4 1 3 4

Sample 1 Output

Yes

The following sequence of operations sorts A in ascending order.

  • Choose i=1 to swap the values of $a_1$ and $a_3$. A is now (1,4,3,3,4).
  • Choose i=2 to swap the values of $a_2$ and $a_4$. A is now (1,3,3,4,4).

Sample 2 Input

5 3
3 4 1 3 4

Sample 2 Output

No

Sample 3 Input

7 5
1 2 3 4 5 5 10

Sample 3 Output

Yes

Source/Category