#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

string s,t;
string ans;
ll bef;
bool a[10]={};

void dfs(int index){
  if(index==s.length()){
    ll tmp1=atoll(t.c_str());
    ll tmp2=atoll(ans.c_str());
    ll dif1=min(abs(bef-tmp1),(ll)pow(10,s.length())-abs(bef-tmp1)); 
    ll dif2=min(abs(bef-tmp2),(ll)pow(10,s.length())-abs(bef-tmp2));
    if(dif2!=dif1 ? dif2<dif1 : tmp1<tmp2)ans=t;
  }
  else {
    FOR(i,0,10){
      if(!a[i]){
        a[i]=true;
        t[index]=i+'0';
        dfs(index+1);
        a[i]=false;
      }
    }
  }
}

int main()
{
  cin>>s;

  t=s;
  bef=atoll(s.c_str());
  if(t[0]<'5')t[0]+=5;
  else t[0]-=5;
  a[t[0]-'0']=true;

  dfs(1);

  cout<<ans<<endl;

  return 0;
}
### Prompt

Generate a Cpp solution to the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

string s,t;
string ans;
ll bef;
bool a[10]={};

void dfs(int index){
  if(index==s.length()){
    ll tmp1=atoll(t.c_str());
    ll tmp2=atoll(ans.c_str());
    ll dif1=min(abs(bef-tmp1),(ll)pow(10,s.length())-abs(bef-tmp1)); 
    ll dif2=min(abs(bef-tmp2),(ll)pow(10,s.length())-abs(bef-tmp2));
    if(dif2!=dif1 ? dif2<dif1 : tmp1<tmp2)ans=t;
  }
  else {
    FOR(i,0,10){
      if(!a[i]){
        a[i]=true;
        t[index]=i+'0';
        dfs(index+1);
        a[i]=false;
      }
    }
  }
}

int main()
{
  cin>>s;

  t=s;
  bef=atoll(s.c_str());
  if(t[0]<'5')t[0]+=5;
  else t[0]-=5;
  a[t[0]-'0']=true;

  dfs(1);

  cout<<ans<<endl;

  return 0;
}
```