#include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

struct UnionFind{
    vector<ll> parent;
    UnionFind(ll sz){
        parent.resize(sz);
        reset();
    }

    void reset(){
        FOR(i, 0, parent.size()){
            parent[i] = i;
        }
    }

    void unite(ll a, ll b){
        if(a>b){
            swap(a, b);
        }
        // cout << "unite " << a << " " << b << endl;
        ll rootA = findRoot(a);
        ll rootB = findRoot(b);
        if(rootA>rootB){
            swap(rootA, rootB);
        }
        if(rootA==rootB){
            return;
        }else{
            // 小さい方を親にする
            parent[rootB] = rootA;
        }
    }

    ll findRoot(ll a){
        if(parent[a]==a){
            return a;
        }else{
            return parent[a] = findRoot(parent[a]);
        }
    }

    map<ll, vector<ll> > getGroups(){
        map<ll, vector<ll> > G;
        FOR(i, 0, parent.size()){
            ll r = findRoot(i);
            G[r].push_back(i);
        }
        return G;
    }

    bool is_same_group(ll a, ll b){
        ll rootA = findRoot(a);
        ll rootB = findRoot(b);
        if(rootA==rootB){
            return true;
        }else{
            return false;
        }
    }
};

const ll MAX_V = 300010;
bool dp[MAX_V];

// ant book p64
// a : value
// m : count
// K : target number
bool can_make(vector<ll>& a, vector<ll>& m, ll K){
    FOR(i, 0, MAX_V){
        dp[i] = -1;
    }    
    ll N = a.size();
    FOR(i, 0, N){
        FOR(j, 0, K+1){
            if(dp[j]>=0){
                dp[j]=m[i];
            }else if(j<a[i] || dp[j-a[i]]<=0){
                dp[j] = -1;
            }else{
                dp[j]=dp[j-a[i]] - 1;
            }
        }
    }
    if(dp[K]>=0){ 
        return true;
    }else{
        return false;
    }
}

bool can_make_naive(vector<ll>& a, vector<ll>& m, ll K){
    vector<ll> V;
    FOR(i, 0, a.size()){
        FOR(j, 0, m[i]){
            V.push_back(a[i]);
        }
    }
    ll N = V.size();

    // p("V");
    // vprint(V);

    FOR(i, 0, 1<<N){
        ll sum = 0;
        FOR(j, 0, N){
            if(i>>j&1){
                sum += V[j];
            }
        }
        if(sum==K) return true;
    }
    return false;
}

bool can_make_bitset_ver(vector<ll>& a, vector<ll>& m, ll K){
    vector<ll> V;
    FOR(i, 0, a.size()){
        FOR(j, 0, m[i]){
            V.push_back(a[i]);
        }
    }
    ll N = V.size();
    bitset<150001> dp;
    dp[0] = 1;
    for(int a : V) dp |= (dp << a);
    if(dp[K]){
        return true;
    }else{
        return false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N, R;
    cin >> N >> R;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
        A[i]--;
    }

    auto uf = UnionFind(N);

    FOR(i, 0, N){
        uf.unite(i, A[i]);
    }

    auto group_mp = uf.getGroups();
    map<ll, ll> mp;
    for(auto pa : group_mp){
        ll sz = pa.second.size();
        mp[sz]++;
    }
    
    vector<ll> V; // value
    vector<ll> C; // count
    for(auto pa : mp){
        ll v = pa.first;
        ll c = pa.second;
        V.push_back(v);
        C.push_back(c);
    }
    // vprint(V);
    // vprint(C);

    // if(can_make_naive(V, C, R)){
    if(can_make_bitset_ver(V, C, min(N-R, R))){
    // if(can_make(V, C, R)){
        p_yes();
    }else{
        p_no();
    }

    return 0;
}

### 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;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

struct UnionFind{
    vector<ll> parent;
    UnionFind(ll sz){
        parent.resize(sz);
        reset();
    }

    void reset(){
        FOR(i, 0, parent.size()){
            parent[i] = i;
        }
    }

    void unite(ll a, ll b){
        if(a>b){
            swap(a, b);
        }
        // cout << "unite " << a << " " << b << endl;
        ll rootA = findRoot(a);
        ll rootB = findRoot(b);
        if(rootA>rootB){
            swap(rootA, rootB);
        }
        if(rootA==rootB){
            return;
        }else{
            // 小さい方を親にする
            parent[rootB] = rootA;
        }
    }

    ll findRoot(ll a){
        if(parent[a]==a){
            return a;
        }else{
            return parent[a] = findRoot(parent[a]);
        }
    }

    map<ll, vector<ll> > getGroups(){
        map<ll, vector<ll> > G;
        FOR(i, 0, parent.size()){
            ll r = findRoot(i);
            G[r].push_back(i);
        }
        return G;
    }

    bool is_same_group(ll a, ll b){
        ll rootA = findRoot(a);
        ll rootB = findRoot(b);
        if(rootA==rootB){
            return true;
        }else{
            return false;
        }
    }
};

const ll MAX_V = 300010;
bool dp[MAX_V];

// ant book p64
// a : value
// m : count
// K : target number
bool can_make(vector<ll>& a, vector<ll>& m, ll K){
    FOR(i, 0, MAX_V){
        dp[i] = -1;
    }    
    ll N = a.size();
    FOR(i, 0, N){
        FOR(j, 0, K+1){
            if(dp[j]>=0){
                dp[j]=m[i];
            }else if(j<a[i] || dp[j-a[i]]<=0){
                dp[j] = -1;
            }else{
                dp[j]=dp[j-a[i]] - 1;
            }
        }
    }
    if(dp[K]>=0){ 
        return true;
    }else{
        return false;
    }
}

bool can_make_naive(vector<ll>& a, vector<ll>& m, ll K){
    vector<ll> V;
    FOR(i, 0, a.size()){
        FOR(j, 0, m[i]){
            V.push_back(a[i]);
        }
    }
    ll N = V.size();

    // p("V");
    // vprint(V);

    FOR(i, 0, 1<<N){
        ll sum = 0;
        FOR(j, 0, N){
            if(i>>j&1){
                sum += V[j];
            }
        }
        if(sum==K) return true;
    }
    return false;
}

bool can_make_bitset_ver(vector<ll>& a, vector<ll>& m, ll K){
    vector<ll> V;
    FOR(i, 0, a.size()){
        FOR(j, 0, m[i]){
            V.push_back(a[i]);
        }
    }
    ll N = V.size();
    bitset<150001> dp;
    dp[0] = 1;
    for(int a : V) dp |= (dp << a);
    if(dp[K]){
        return true;
    }else{
        return false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N, R;
    cin >> N >> R;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
        A[i]--;
    }

    auto uf = UnionFind(N);

    FOR(i, 0, N){
        uf.unite(i, A[i]);
    }

    auto group_mp = uf.getGroups();
    map<ll, ll> mp;
    for(auto pa : group_mp){
        ll sz = pa.second.size();
        mp[sz]++;
    }
    
    vector<ll> V; // value
    vector<ll> C; // count
    for(auto pa : mp){
        ll v = pa.first;
        ll c = pa.second;
        V.push_back(v);
        C.push_back(c);
    }
    // vprint(V);
    // vprint(C);

    // if(can_make_naive(V, C, R)){
    if(can_make_bitset_ver(V, C, min(N-R, R))){
    // if(can_make(V, C, R)){
        p_yes();
    }else{
        p_no();
    }

    return 0;
}

```