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

int n; ll po=1;

ll diff(const string &s,const string &t){
    ll ns=stoll(s),nt=stoll(t);
    return min(abs(ns-nt),po-abs(ns-nt));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    n=S.size();
    for (int i=0;i<n;++i) po*=10;
    vector<int> perm(10);
    iota(perm.begin(),perm.end(),0);
    string ans; ll Max=0;
    do {
        string cnt="";
        for (int i=0;i<n;++i) cnt+='0'+perm[i];
        if (Max<diff(cnt,S)){
            Max=diff(cnt,S);
            ans=cnt;
        } else if (diff(cnt,S)==Max){
            if (stoll(cnt)<stoll(ans)) ans=cnt;
        }
    } while(next_permutation(perm.begin(),perm.end()));
    cout << ans << '\n';
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

Example

Input

201


Output

701

### Response

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

int n; ll po=1;

ll diff(const string &s,const string &t){
    ll ns=stoll(s),nt=stoll(t);
    return min(abs(ns-nt),po-abs(ns-nt));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    n=S.size();
    for (int i=0;i<n;++i) po*=10;
    vector<int> perm(10);
    iota(perm.begin(),perm.end(),0);
    string ans; ll Max=0;
    do {
        string cnt="";
        for (int i=0;i<n;++i) cnt+='0'+perm[i];
        if (Max<diff(cnt,S)){
            Max=diff(cnt,S);
            ans=cnt;
        } else if (diff(cnt,S)==Max){
            if (stoll(cnt)<stoll(ans)) ans=cnt;
        }
    } while(next_permutation(perm.begin(),perm.end()));
    cout << ans << '\n';
}

```