#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool used[10];
string S;
int N, M, len, ma, ans;

void solve(int p, int num) {
    if(p == len) {
        int v = min(abs(N - num), M - abs(N - num));
        if(ma <= v) {
            if(ma < v) ans = num;
            else chmin(ans, num);
            ma = v;
        }
    }
    else {
        rep(i,0,10) {
            if(used[i]) continue;
            used[i] = true;
            solve(p+1, num*10 + i);
            used[i] = false;
        }
    }
}

signed main() {
    cin >> S;
    len = S.length();
    N = atoll(S.c_str());
    M = 1; ans = INF;
    rep(i,0,len) M *= 10;
    solve(0, 0);
    string res = to_string(ans);
    int rest = len - res.length();
    rep(i,0,rest) res = '0' + res;
    cout << res << endl;
    return 0;
}
### Prompt

Create a solution in Cpp for the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool used[10];
string S;
int N, M, len, ma, ans;

void solve(int p, int num) {
    if(p == len) {
        int v = min(abs(N - num), M - abs(N - num));
        if(ma <= v) {
            if(ma < v) ans = num;
            else chmin(ans, num);
            ma = v;
        }
    }
    else {
        rep(i,0,10) {
            if(used[i]) continue;
            used[i] = true;
            solve(p+1, num*10 + i);
            used[i] = false;
        }
    }
}

signed main() {
    cin >> S;
    len = S.length();
    N = atoll(S.c_str());
    M = 1; ans = INF;
    rep(i,0,len) M *= 10;
    solve(0, 0);
    string res = to_string(ans);
    int rest = len - res.length();
    rep(i,0,rest) res = '0' + res;
    cout << res << endl;
    return 0;
}
```