#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <iomanip>
using namespace std;

vector<bool> used(10, false);
long long int diff = 0;
long long int ans = 0;
long long int pot;
void search(long long int n, int l, long long int num){
    if(l==0){
        long long int d = min(llabs(n-num), pot-llabs(n-num));
        if(d > diff){
            diff = d;
            ans = num;
        }
        return;
    }
    for(int i=0; i<=9; i++){
        if(!used[i]){
            used[i] = true;
            search(n, l-1, num*10+i);
            used[i] = false;
        }
    }
}

int main(){
    string str;
    cin >> str;

    int l = str.length();
    long long int n = stoll(str);
    pot = 1;
    for(int i=0; i<l; i++) pot*=10;
    search(n,l,0);

    cout << setfill('0') << setw(l) << right <<  ans << endl;
    return 0;
}
### Prompt

In Cpp, your task is to solve the following problem:

Example

Input

201


Output

701

### Response

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

vector<bool> used(10, false);
long long int diff = 0;
long long int ans = 0;
long long int pot;
void search(long long int n, int l, long long int num){
    if(l==0){
        long long int d = min(llabs(n-num), pot-llabs(n-num));
        if(d > diff){
            diff = d;
            ans = num;
        }
        return;
    }
    for(int i=0; i<=9; i++){
        if(!used[i]){
            used[i] = true;
            search(n, l-1, num*10+i);
            used[i] = false;
        }
    }
}

int main(){
    string str;
    cin >> str;

    int l = str.length();
    long long int n = stoll(str);
    pot = 1;
    for(int i=0; i<l; i++) pot*=10;
    search(n,l,0);

    cout << setfill('0') << setw(l) << right <<  ans << endl;
    return 0;
}
```