Under construction

Still being built. Things may change

Simple Problem

Time limit1sMemory limit1024 MB

Summary
Given p and a sequence b, decide whether some permutation of 1 to N makes the maximum residue-class count over each prefix equal b_i.
Level

Medium6 of 10

Topics
Greedy, Math, Implementation
Solved
No attempts yet

Problem

After leaving PULSE and entering graduate school, Sanjini is fishing at Taejongdae on a holiday, hoping to catch a big one. Hours pass with no bite. Sleepy from holding the rod for so long, Sanjini starts thinking about a simple sequence.

For a permutation aa of length NN, define SS and a sequence bb as follows.

  • Si,jS_{i,j} (1≤i≤N1 \leq i \leq N) is the number of elements among a1,a2,…,aia_1, a_2, \ldots, a_i whose remainder modulo pp is jj (0≤j<p0 \leq j < p).
  • bib_i (1≤i≤N1 \leq i \leq N) is the maximum of Si,0,Si,1,…,Si,p−1S_{i,0}, S_{i,1}, \ldots, S_{i,p-1}.

Sanjini thinks a little longer and wonders whether a permutation aa exists for a given pp and sequence bb. Determine whether a permutation aa that satisfies the conditions exists.

Input

The first line contains the length NN of sequence bb and the integer pp, separated by a space. (1≤N,p≤5×105)(1 \leq N, p \leq 5 \times 10^5)

The second line contains the elements b1,b2,…,bNb_1, b_2, \ldots, b_N of sequence bb in order, separated by spaces. (1≤bi≤N)(1 \leq b_i \leq N)

Output

If a permutation aa that satisfies the conditions exists, print YES. Otherwise, print NO.

Hint

A permutation of length NN is a finite sequence in which each integer from 1 to NN is used exactly once. For example, {1,2,4,3}\{1, 2, 4, 3\} is a permutation, but {1,4,2}\{1, 4, 2\} and {1,3,3,2}\{1, 3, 3, 2\} are not.

Examples4

  1. Example 1

    Input
    3 1
    1 2 3
    
    Expected output
    YES
    
  2. Example 2

    Input
    5 2
    1 2 2 2 2
    
    Expected output
    NO
    
  3. Example 3

    Input
    3 6
    1 1 1
    
    Expected output
    YES
    
  4. Example 4

    Input
    7 2
    1 2 3 2 3 3 4
    
    Expected output
    NO