#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

vector<string> v;
long long diff = 0;
long long k = 1;
string ans;

//?????????????????°???????????????
long long toNum(string str){
    long long num = 0;
    rep(i,str.size()){
        num *= 10;
        num += str[i] - '0';
    }
    return num;
}

void solve(string s, string t, int use){
    if(s.size() == t.size()){
        long long S = toNum(s);
        long long T = toNum(t);
        if(diff < min(abs(S - T), k - abs(S - T))){
            diff = min(abs(S - T), k - abs(S - T));
            ans = t;
        }
        return;
    }

    rep(i,10){
        if((use >> i & 1) == 0){
            string temp = t;
            temp += '0' + i;
            solve(s, temp, use | (1 << i));
        }
    }
}

int main(){
    string s;
    cin >> s;
    rep(i,s.size()) k *= 10;
    solve(s, "", 0);

    cout << ans << endl;
}
### Prompt

Create a solution in Cpp for the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

vector<string> v;
long long diff = 0;
long long k = 1;
string ans;

//?????????????????°???????????????
long long toNum(string str){
    long long num = 0;
    rep(i,str.size()){
        num *= 10;
        num += str[i] - '0';
    }
    return num;
}

void solve(string s, string t, int use){
    if(s.size() == t.size()){
        long long S = toNum(s);
        long long T = toNum(t);
        if(diff < min(abs(S - T), k - abs(S - T))){
            diff = min(abs(S - T), k - abs(S - T));
            ans = t;
        }
        return;
    }

    rep(i,10){
        if((use >> i & 1) == 0){
            string temp = t;
            temp += '0' + i;
            solve(s, temp, use | (1 << i));
        }
    }
}

int main(){
    string s;
    cin >> s;
    rep(i,s.size()) k *= 10;
    solve(s, "", 0);

    cout << ans << endl;
}
```