#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
 
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
#include <functional>
#include <cassert>
 
typedef long long ll;
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << endl;
 
#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000
 
bool used[10];
 
int t;
ll p;
ll n;
ll max_d = 0;
ll ans = -1;
 
void dfs(int h=0,ll sum=0){
 
  if(h==t){
    if(max_d < min(abs(sum-n),p-abs(sum-n)) ){
      max_d = min(abs(sum-n),p-abs(sum-n));
      ans = sum;
    }
    return;
  }
  
  for(int i=0;i<10;i++){
    if(used[i]) continue;
 
    used[i] = true;
    
    dfs(h+1,sum*10+i);
 
    used[i] = false;
  }
 
}
  
 
int main(){
  string s;
 
  cin >> s;
 
  t = s.size();
  n = stoll(s);
 
  p = 1;
  
  for(int i=0;i<t;i++){
    p *= 10;
  }
  
  dfs();
 
  string ans_s = to_string(ans);
 
  while((int)ans_s.size() < t){
    ans_s = "0" + ans_s;
  }
   
  cout << ans_s << endl;
  
  return 0;
}


### Prompt

Your challenge is to write a Cpp solution to the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
 
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
#include <functional>
#include <cassert>
 
typedef long long ll;
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << endl;
 
#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000
 
bool used[10];
 
int t;
ll p;
ll n;
ll max_d = 0;
ll ans = -1;
 
void dfs(int h=0,ll sum=0){
 
  if(h==t){
    if(max_d < min(abs(sum-n),p-abs(sum-n)) ){
      max_d = min(abs(sum-n),p-abs(sum-n));
      ans = sum;
    }
    return;
  }
  
  for(int i=0;i<10;i++){
    if(used[i]) continue;
 
    used[i] = true;
    
    dfs(h+1,sum*10+i);
 
    used[i] = false;
  }
 
}
  
 
int main(){
  string s;
 
  cin >> s;
 
  t = s.size();
  n = stoll(s);
 
  p = 1;
  
  for(int i=0;i<t;i++){
    p *= 10;
  }
  
  dfs();
 
  string ans_s = to_string(ans);
 
  while((int)ans_s.size() < t){
    ans_s = "0" + ans_s;
  }
   
  cout << ans_s << endl;
  
  return 0;
}


```