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

using ll = long long;
constexpr ll LLINF = (1ll<<60);

string S;
string ans;
ll ansd = LLINF;
int N;
string pat = "0123456789";
int ipat[256];

ll p10[15];

char addr(char c, int val) {
        return (pat[(ipat[c]+val+10)%10]);
}

void solve(int u, string T, int bit, int flag) {
        //cout << u << " " << T << " " << bit << " " << flag << endl;
        if (u == N) {
                //cout << S << " " << T << endl;
                ll val1 = stol(S);
                ll val2 = stol(T);
                ll diff = min({abs(p10[N]+val1-val2), abs(val1-val2), abs(val1-val2-p10[N])});
                if (ansd > diff || (ansd == diff && ans > T)) {
                        ansd = diff; ans = T;
                }
                return;
        }
        int target;
        if (flag == 1) target = -1;
        else if (flag == -1) target = 10;
        else target = S[u] - '0';
        
        if (!flag && (!((bit>>target)&1))) {
                solve(u+1, T + (char)(target+'0'), bit | (1<<target), 0);
        }
        
        for (int i = target+1; i < 10; i++) {
                if (!((bit>>i)&1)) {
                        int nf = flag;
                        if (flag == 0) nf = 1;
                        solve(u+1, T + (char)(i+'0'), bit | (1<<i), nf);
                        break;
                }
        }

        for (int i = target-1; i >= 0; i--) {
                if (!((bit>>i)&1)) {
                        int nf = flag;
                        if (flag == 0) nf = -1;
                        solve(u+1, T + (char)(i+'0'), bit | (1<<i), nf);
                        break;
                }
        }
}

int main() {
        cin >> S;
        N = S.size();
        for (int i = '0'; i <= '9'; i++) {
                ipat[i] = i-'0';
        }


        p10[0] = 1;
        for (int i = 1; i < 15; i++) {
                p10[i] = p10[i-1] * 10;
        }

        S[0] = addr(S[0], 5);

        string c1; c1 += (addr(S[0], -1));
        string c2; c2 += (S[0]);
        string c3; c3 += (addr(S[0], 1));
        //cout << c1 << " " << c2 << " " << c3 << endl;

        solve(1, c1, 1<<(c1[0]-'0'), -1);
        solve(1, c2, 1<<(c2[0]-'0'), 0);
        solve(1, c3, 1<<(c3[0]-'0'), 1);

        cout << ans << endl;
}


### Prompt

Construct a Cpp code solution to the problem outlined:

Example

Input

201


Output

701

### Response

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

using ll = long long;
constexpr ll LLINF = (1ll<<60);

string S;
string ans;
ll ansd = LLINF;
int N;
string pat = "0123456789";
int ipat[256];

ll p10[15];

char addr(char c, int val) {
        return (pat[(ipat[c]+val+10)%10]);
}

void solve(int u, string T, int bit, int flag) {
        //cout << u << " " << T << " " << bit << " " << flag << endl;
        if (u == N) {
                //cout << S << " " << T << endl;
                ll val1 = stol(S);
                ll val2 = stol(T);
                ll diff = min({abs(p10[N]+val1-val2), abs(val1-val2), abs(val1-val2-p10[N])});
                if (ansd > diff || (ansd == diff && ans > T)) {
                        ansd = diff; ans = T;
                }
                return;
        }
        int target;
        if (flag == 1) target = -1;
        else if (flag == -1) target = 10;
        else target = S[u] - '0';
        
        if (!flag && (!((bit>>target)&1))) {
                solve(u+1, T + (char)(target+'0'), bit | (1<<target), 0);
        }
        
        for (int i = target+1; i < 10; i++) {
                if (!((bit>>i)&1)) {
                        int nf = flag;
                        if (flag == 0) nf = 1;
                        solve(u+1, T + (char)(i+'0'), bit | (1<<i), nf);
                        break;
                }
        }

        for (int i = target-1; i >= 0; i--) {
                if (!((bit>>i)&1)) {
                        int nf = flag;
                        if (flag == 0) nf = -1;
                        solve(u+1, T + (char)(i+'0'), bit | (1<<i), nf);
                        break;
                }
        }
}

int main() {
        cin >> S;
        N = S.size();
        for (int i = '0'; i <= '9'; i++) {
                ipat[i] = i-'0';
        }


        p10[0] = 1;
        for (int i = 1; i < 15; i++) {
                p10[i] = p10[i-1] * 10;
        }

        S[0] = addr(S[0], 5);

        string c1; c1 += (addr(S[0], -1));
        string c2; c2 += (S[0]);
        string c3; c3 += (addr(S[0], 1));
        //cout << c1 << " " << c2 << " " << c3 << endl;

        solve(1, c1, 1<<(c1[0]-'0'), -1);
        solve(1, c2, 1<<(c2[0]-'0'), 0);
        solve(1, c3, 1<<(c3[0]-'0'), 1);

        cout << ans << endl;
}


```