#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <bitset>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};
const int MAX_N = 150020;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, R;
    cin >> N >> R;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }
    union_find uf(N);
    rep(i, N) uf.unite(A[i], A[A[i]]);
    vector<int> used(N, 0);
    vector<int> B;
    rep(i, N) {
        int root = uf.root(i);
        if (used[root]) {
            continue;
        }
        used[root] = true;
        B.pb(uf.count(root));
    }
    bitset<MAX_N> C(1);
    rep(i, B.size()){
        C |= (C << B[i]);
    }
    
    if(C.test(min(R, N - R)) == 1) {
        output("Yes");
    }
    else {
        output("No");
    }
    
    
    
    
    return 0;
}


### Prompt

Please provide a Cpp coded solution to the problem described below:

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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <bitset>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};
const int MAX_N = 150020;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, R;
    cin >> N >> R;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }
    union_find uf(N);
    rep(i, N) uf.unite(A[i], A[A[i]]);
    vector<int> used(N, 0);
    vector<int> B;
    rep(i, N) {
        int root = uf.root(i);
        if (used[root]) {
            continue;
        }
        used[root] = true;
        B.pb(uf.count(root));
    }
    bitset<MAX_N> C(1);
    rep(i, B.size()){
        C |= (C << B[i]);
    }
    
    if(C.test(min(R, N - R)) == 1) {
        output("Yes");
    }
    else {
        output("No");
    }
    
    
    
    
    return 0;
}


```