#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}


struct UnionFind{
int uf[100010];
int rank1[100010];

//n要素で初期化
void init(int n){
  for(int i=0;i<n;i++){
    uf[i]=i;
    rank1[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(uf[x]==x){
    return x;
  } else {
    return uf[x]=find(uf[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(rank1[x]<rank1[y]){
    uf[x]=y;
  }else{
    uf[y]=x;
    if(rank1[x]==rank1[y])rank1[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
return find(x)==find(y);
}
};
//arc-d65 連結　latteさん
//UF uf;
//uf.init(n)をわすれない
struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
	int N,R;
	cin>>N>>R;
	vector<int>p(N);
	UF uf;
	uf.init(N);
	REP(i,N){
		cin>>p[i];
		p[i]--;
		if(p[i]!=i)uf.unite(i,p[i]);
	}
	vector<int>cnt(300030,0);
	vector<int>used(300030,0);
	REP(i,N){
		if(used[uf.find(i)])continue;
		cnt[uf.size(i)]++;
		used[uf.find(i)] = true;
	}
	vector<pair<int,int>>v;
	REP(i,300030){
		if(cnt[i])v.push_back({i,cnt[i]});
	}
	vector<int>dp(300030,-1);
	dp[0] = 1;
	REP(i,v.size()){
		REP(j,R+1){
			if(dp[j] >= 0){
				dp[j] = v[i].second;
			}else if(j < v[i].first || dp[j - v[i].first] <= 0){
				dp[j] = -1;
			}else {
				dp[j] = dp[j - v[i].first] - 1;
			}
		}
	}
	if(dp[R] >= 0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

### Prompt

Generate a cpp solution to the following problem:

D: Two Colors Sort

problem

During the walk, umg found a sequence of length N, P_1, P_2, ..., P_N, which can be made by rearranging 1,2, ..., N.

umg can use mysterious powers to exchange places by choosing two different numbers painted in the same color.

umg wanted to be able to sort the sequence in ascending order by painting R of the numbers in the sequence in red and the remaining N-R in blue.

umg Determine if you can reach your goal.

However, the numbers are so heavy that they cannot be moved without mysterious force. Also, since umg is a genius, you can use mysterious powers any number of times.

Input format


N R
P_1 P_2 ... P_N


Constraint

* 1 \ leq N \ leq 3 \ times 10 ^ 5
* 1 \ leq R \ leq N
* 1 \ leq P_i \ leq N
* P_i \ neq P_j (1 \ leq i <j \ leq N)
* All inputs are integers.



Output format

umg Print `Yes` if you can achieve your goal, otherwise` No` on one line.

Input example 1


3 2
1 3 2


Output example 1


Yes

* You can achieve your goal by painting 1 in blue and 2 and 3 in red.



Input example 2


5 2
1 2 3 4 5


Output example 2


Yes

* They are arranged in ascending order from the beginning.



Input example 3


10 7
3 4 8 5 7 6 2 10 1 9


Output example 3


No





Example

Input

3 2
1 3 2


Output

Yes

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}


struct UnionFind{
int uf[100010];
int rank1[100010];

//n要素で初期化
void init(int n){
  for(int i=0;i<n;i++){
    uf[i]=i;
    rank1[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(uf[x]==x){
    return x;
  } else {
    return uf[x]=find(uf[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(rank1[x]<rank1[y]){
    uf[x]=y;
  }else{
    uf[y]=x;
    if(rank1[x]==rank1[y])rank1[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
return find(x)==find(y);
}
};
//arc-d65 連結　latteさん
//UF uf;
//uf.init(n)をわすれない
struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
	int N,R;
	cin>>N>>R;
	vector<int>p(N);
	UF uf;
	uf.init(N);
	REP(i,N){
		cin>>p[i];
		p[i]--;
		if(p[i]!=i)uf.unite(i,p[i]);
	}
	vector<int>cnt(300030,0);
	vector<int>used(300030,0);
	REP(i,N){
		if(used[uf.find(i)])continue;
		cnt[uf.size(i)]++;
		used[uf.find(i)] = true;
	}
	vector<pair<int,int>>v;
	REP(i,300030){
		if(cnt[i])v.push_back({i,cnt[i]});
	}
	vector<int>dp(300030,-1);
	dp[0] = 1;
	REP(i,v.size()){
		REP(j,R+1){
			if(dp[j] >= 0){
				dp[j] = v[i].second;
			}else if(j < v[i].first || dp[j - v[i].first] <= 0){
				dp[j] = -1;
			}else {
				dp[j] = dp[j - v[i].first] - 1;
			}
		}
	}
	if(dp[R] >= 0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

```