#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

string s;
int sz;
ll old, d = 0, ans;

void dfs(int rem, int mask, ll p) {
  if (rem == 0) {
    ll nd = min(abs(p - old), (ll)pow(10, sz) - abs(p - old));
    if (nd < d) return;
    if (nd == d) ans = min(ans, p);
    else ans = p;
    d = nd;
    return;
  }
  for (int i = 0; i < 10; i++) {
    if ((mask >> i & 1) == 0) {
      dfs(rem - 1, mask | (1 << i), p * 10 + i);
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin >> s;
  sz = s.size();
  old = atoll(s.c_str());
  dfs(sz, 0, 0);
  cout << setfill('0') << right << setw(sz) << ans << endl;

  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

Example

Input

201


Output

701

### Response

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

using namespace std;
typedef long long ll;

string s;
int sz;
ll old, d = 0, ans;

void dfs(int rem, int mask, ll p) {
  if (rem == 0) {
    ll nd = min(abs(p - old), (ll)pow(10, sz) - abs(p - old));
    if (nd < d) return;
    if (nd == d) ans = min(ans, p);
    else ans = p;
    d = nd;
    return;
  }
  for (int i = 0; i < 10; i++) {
    if ((mask >> i & 1) == 0) {
      dfs(rem - 1, mask | (1 << i), p * 10 + i);
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin >> s;
  sz = s.size();
  old = atoll(s.c_str());
  dfs(sz, 0, 0);
  cout << setfill('0') << right << setw(sz) << ans << endl;

  return 0;
}

```