Under construction

Still being built. Things may change

K-Sort

Time limit1.5sMemory limit1024 MB

Summary
Given a permutation and K, decide whether swapping elements K positions apart (cyclically) can sort it into ascending order.
Level

Medium4 of 10

Topics
Number theory, Array
Solved
No attempts yet

Problem

You are given a permutation A=[A0,A1,…,AN−1]A=[A_0, A_1, \dots, A_{N-1}] of length NN. A permutation of length NN is a sequence in which every integer from 00 to N−1N-1 appears exactly once.

A positive integer KK is also given. You may perform the following operation as many times as you like.

  • For any ii (0≤i<N0 \leq i < N), swap the values of AiA_i and A(i+K) mod NA_{(i+K) \bmod N}.

Determine whether AA can be sorted into ascending order using this operation. See the hint for the definition of  mod \bmod.

Input

The first line contains the length NN and the positive integer KK, separated by a space. (1≤K≤N≤1061 \leq K \leq N \leq 10^{6})

The second line contains the elements A0,A1,…,AN−1A_0, A_1, \dots, A_{N-1}, separated by spaces. Each integer from 00 to N−1N-1 appears exactly once.

Output

Print YES if AA can be sorted into ascending order by repeating the operation, otherwise print NO.

Hint

 mod \bmod is the remainder operation. a mod ba \bmod b is the remainder when aa is divided by bb. For example, 5 mod 3=25 \bmod 3 = 2.

Examples2

  1. Example 1

    Input
    6 2
    2 3 4 1 0 5
    
    Expected output
    YES
    
  2. Example 2

    Input
    4 2
    0 1 3 2
    
    Expected output
    NO