#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  long long N = S.size();
  long long A = stoll(S);
  long long ans = -1;
  long long diff = 0;
  vector<int> p(10);
  for (int i = 0; i < 10; i++){
    p[i] = i;
  }
  long long MAX = 1;
  for (int i = 0; i < N; i++){
    MAX *= 10;
  }
  while (1){
    long long B = 0;
    for (int i = 0; i < N; i++){
      B = B * 10 + p[i];
    }
    long long d = min(abs(A - B), MAX - abs(A - B));
    if (d > diff || d == diff && ans > B){
      diff = d;
      ans = B;
    }
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  string T = to_string(ans);
  while (T.size() < N){
    T = '0' + T;
  }
  cout << T << endl;
}

### Prompt

Your task is to create a cpp solution to the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  long long N = S.size();
  long long A = stoll(S);
  long long ans = -1;
  long long diff = 0;
  vector<int> p(10);
  for (int i = 0; i < 10; i++){
    p[i] = i;
  }
  long long MAX = 1;
  for (int i = 0; i < N; i++){
    MAX *= 10;
  }
  while (1){
    long long B = 0;
    for (int i = 0; i < N; i++){
      B = B * 10 + p[i];
    }
    long long d = min(abs(A - B), MAX - abs(A - B));
    if (d > diff || d == diff && ans > B){
      diff = d;
      ans = B;
    }
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  string T = to_string(ans);
  while (T.size() < N){
    T = '0' + T;
  }
  cout << T << endl;
}

```