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

using ll = long long int;

bool used[10];
string s, ans;
ll maxi, diff = 0;

void rec(int n, string t){
    // cout << n << " " << t << endl;
    if(n == 0){
        ll d = abs(stol(s)-stol(t));
        if(min(d, maxi-d) > diff){
            ans = t;
            diff = min(d, maxi-d);
        }else if(min(d, maxi-d) == diff && stol(ans)>stol(t)){
            ans = t;
        }
        return;
    }
    for(int i=0;i<10;i++){
        if(!used[i]){
            t.push_back('0'+i);
            used[i] = true;
            rec(n-1,t);
            t.pop_back();
            used[i] = false;
        }
    }
}

int solve(){
    cin >> s;
    maxi = ll(pow(10,s.size()));
    rec(s.size(), "");
    cout << ans << endl;
    return 0;
}

int main(){
    solve();
    return 0;
}


### Prompt

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

Example

Input

201


Output

701

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

bool used[10];
string s, ans;
ll maxi, diff = 0;

void rec(int n, string t){
    // cout << n << " " << t << endl;
    if(n == 0){
        ll d = abs(stol(s)-stol(t));
        if(min(d, maxi-d) > diff){
            ans = t;
            diff = min(d, maxi-d);
        }else if(min(d, maxi-d) == diff && stol(ans)>stol(t)){
            ans = t;
        }
        return;
    }
    for(int i=0;i<10;i++){
        if(!used[i]){
            t.push_back('0'+i);
            used[i] = true;
            rec(n-1,t);
            t.pop_back();
            used[i] = false;
        }
    }
}

int solve(){
    cin >> s;
    maxi = ll(pow(10,s.size()));
    rec(s.size(), "");
    cout << ans << endl;
    return 0;
}

int main(){
    solve();
    return 0;
}


```