#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

lli stoll(string &s) {
    lli res = 0LL;
    REP (i, 0, s.size()) {
        res = res * 10 + s[i] - '0';
    }
    return res;
}

string lltos(lli n, int d) {
    string res = "";
    lli bs = 1;
    REP (i, 1, d) bs *= 10;
    REP (i, 0, d) {
        res += (n / bs) + '0';
        n %= bs;
        bs /= 10;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    int N = s.size();
    lli num = stoll(s);
    vector<bool> used(10, false);
    lli ans = 1LL << 60;
    lli dis = -1;
    lli bs = 1;
    REP (i, 0, N) bs *= 10;
    function<void(int, lli)> rec = [&](int idx, lli n) {
        if (idx == N) {
            lli d = min(abs(n - num), bs - abs(n - num));
            if (d > dis || (d == dis && n < ans)) {
                dis = d;
                ans = n;
            }
        } else {
            REP (i, 0, 10) {
                if (used[i]) continue;
                used[i] = true;
                rec(idx + 1, n * 10 + i);
                used[i] = false;
            }
        }
    };
    rec(0, 0LL);
    cout << lltos(ans, N) << endl;
    return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

Example

Input

201


Output

701

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

lli stoll(string &s) {
    lli res = 0LL;
    REP (i, 0, s.size()) {
        res = res * 10 + s[i] - '0';
    }
    return res;
}

string lltos(lli n, int d) {
    string res = "";
    lli bs = 1;
    REP (i, 1, d) bs *= 10;
    REP (i, 0, d) {
        res += (n / bs) + '0';
        n %= bs;
        bs /= 10;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    int N = s.size();
    lli num = stoll(s);
    vector<bool> used(10, false);
    lli ans = 1LL << 60;
    lli dis = -1;
    lli bs = 1;
    REP (i, 0, N) bs *= 10;
    function<void(int, lli)> rec = [&](int idx, lli n) {
        if (idx == N) {
            lli d = min(abs(n - num), bs - abs(n - num));
            if (d > dis || (d == dis && n < ans)) {
                dis = d;
                ans = n;
            }
        } else {
            REP (i, 0, 10) {
                if (used[i]) continue;
                used[i] = true;
                rec(idx + 1, n * 10 + i);
                used[i] = false;
            }
        }
    };
    rec(0, 0LL);
    cout << lltos(ans, N) << endl;
    return 0;
}

```