#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

ll po(ll a, ll b) {
  ll res = 1;
  for(int i=0;i<b;++i) {
    res *= a;
  }
  return res;
}

int digit(ll n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  ll dig = (int)(s.size());
  ll n = stoll(s);
  vector<ll> a = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

  ll sz = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1;

  ll ma = 0;
  ll ans = 0;
  for(int i=0;i<sz;++i) {
    ll now = 0;
    for(int j=0;j<dig;++j) {
      now += a[j] * po(10, dig-j-1);
    }
    // cout << now << endl;
    
    ll diff = min(abs(n - now), po(10, dig) - abs(n - now));
    // printv(a);
    if(diff > ma) {
      ma = diff;
      ans = now;
    }
    next_permutation(a.begin(), a.end());
  }
  if(dig != digit(ans)) {
    cout << 0;
  }
  cout << ans << endl;
}


### Prompt

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

Example

Input

201


Output

701

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

ll po(ll a, ll b) {
  ll res = 1;
  for(int i=0;i<b;++i) {
    res *= a;
  }
  return res;
}

int digit(ll n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  ll dig = (int)(s.size());
  ll n = stoll(s);
  vector<ll> a = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

  ll sz = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1;

  ll ma = 0;
  ll ans = 0;
  for(int i=0;i<sz;++i) {
    ll now = 0;
    for(int j=0;j<dig;++j) {
      now += a[j] * po(10, dig-j-1);
    }
    // cout << now << endl;
    
    ll diff = min(abs(n - now), po(10, dig) - abs(n - now));
    // printv(a);
    if(diff > ma) {
      ma = diff;
      ans = now;
    }
    next_permutation(a.begin(), a.end());
  }
  if(dig != digit(ans)) {
    cout << 0;
  }
  cout << ans << endl;
}


```