#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string S;
    cin>>S;
    int N = S.size();
    int64_t a=0;
    for(int i=0;i<N;i++){
        a*=10; a+=S[i]-'0';
    }
    //n!?????????
    vector<int> V;
    for(int i=0;i<10;i++) V.push_back(i);
    int64_t ans=a, diff=0;
    int64_t pN=1; for(int i=0;i<N;i++) pN*=10;
    do{
        int64_t b=0;
        for(int i=0;i<N;i++){
            b*=10; b+=V[i];
        }
        int64_t ndiff = min(abs(a-b),pN-abs(a-b));
        if(ndiff>diff||(ndiff==diff&&b<ans)){
            ans=b; diff=ndiff;
        }
    }while(next_permutation(V.begin(),V.end()));
    if(ans<pN/10) cout<<'0';
    cout<<ans<<endl;
}
### Prompt

Construct a cpp code solution to the problem outlined:

Example

Input

201


Output

701

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string S;
    cin>>S;
    int N = S.size();
    int64_t a=0;
    for(int i=0;i<N;i++){
        a*=10; a+=S[i]-'0';
    }
    //n!?????????
    vector<int> V;
    for(int i=0;i<10;i++) V.push_back(i);
    int64_t ans=a, diff=0;
    int64_t pN=1; for(int i=0;i<N;i++) pN*=10;
    do{
        int64_t b=0;
        for(int i=0;i<N;i++){
            b*=10; b+=V[i];
        }
        int64_t ndiff = min(abs(a-b),pN-abs(a-b));
        if(ndiff>diff||(ndiff==diff&&b<ans)){
            ans=b; diff=ndiff;
        }
    }while(next_permutation(V.begin(),V.end()));
    if(ans<pN/10) cout<<'0';
    cout<<ans<<endl;
}
```