#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    ll k = pow(10LL, n);

    vector<int> v(10);
    iota(v.begin(), v.end(), 0);

    string ans;
    ll maxd = -1;
    do
    {
        string t = "";
        for(int i = 0; i < n; i++) t += v[i] + '0';
        ll a = stoll(s), b = stoll(t);
        ll d = min(abs(a - b), k - abs(a - b));
        if(d == maxd and stoll(t) < stoll(ans)) ans = t;
        else if(d > maxd)
        {
            ans = t;
            maxd = d;
        }
    }
    while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;
    return 0;
}



### Prompt

Please formulate a cpp solution to the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    ll k = pow(10LL, n);

    vector<int> v(10);
    iota(v.begin(), v.end(), 0);

    string ans;
    ll maxd = -1;
    do
    {
        string t = "";
        for(int i = 0; i < n; i++) t += v[i] + '0';
        ll a = stoll(s), b = stoll(t);
        ll d = min(abs(a - b), k - abs(a - b));
        if(d == maxd and stoll(t) < stoll(ans)) ans = t;
        else if(d > maxd)
        {
            ans = t;
            maxd = d;
        }
    }
    while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;
    return 0;
}



```