#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<string,string> pss;
vector<pss> vpss;
bool used;
string s;
ll maxdif=-1000;
string ans="0";
vector<string> cands;
void getnum(string makenum,int count,int last)
{
  if(count==0)
    {
      cands.push_back(makenum);
    }
  else
    {
      for(int i=last+1;i<10;i++)
	{
	  string newnum=makenum+to_string(i);
	  getnum(newnum,count-1,i);
	}
    }
}


int main(void)
{
  cin >> s;
  int ssize=int(s.size());
  string tmp="";
  ll n10=10;
  for(int i=0;i<ssize-1;i++)
    {
      n10*=10;
    }
  getnum(tmp,ssize,-1);
  for(int i=0;i<cands.size();i++)
    {
      //cout << cands[i] << endl;
      //cout << endl;
      do{
	string tmp=cands[i];
	//cout << tmp << endl;
	ll newpass=stoll(cands[i]);
	ll dif=min(abs(stoll(s)-newpass),n10-abs(stoll(s)-newpass));
	if(dif==maxdif)
	  {
	    maxdif=dif;
	    if(ans=="0")
	      {
		ans=cands[i];
	      }
	    if(stoll(cands[i])<stoll(ans))
	      {
		ans=cands[i];
	      }
	  }
	if(dif>maxdif)
	  {
	    maxdif=dif;
	    ans=cands[i];	
	  }
	
      }while(next_permutation(cands[i].begin(),cands[i].end()));
    }
  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>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<string,string> pss;
vector<pss> vpss;
bool used;
string s;
ll maxdif=-1000;
string ans="0";
vector<string> cands;
void getnum(string makenum,int count,int last)
{
  if(count==0)
    {
      cands.push_back(makenum);
    }
  else
    {
      for(int i=last+1;i<10;i++)
	{
	  string newnum=makenum+to_string(i);
	  getnum(newnum,count-1,i);
	}
    }
}


int main(void)
{
  cin >> s;
  int ssize=int(s.size());
  string tmp="";
  ll n10=10;
  for(int i=0;i<ssize-1;i++)
    {
      n10*=10;
    }
  getnum(tmp,ssize,-1);
  for(int i=0;i<cands.size();i++)
    {
      //cout << cands[i] << endl;
      //cout << endl;
      do{
	string tmp=cands[i];
	//cout << tmp << endl;
	ll newpass=stoll(cands[i]);
	ll dif=min(abs(stoll(s)-newpass),n10-abs(stoll(s)-newpass));
	if(dif==maxdif)
	  {
	    maxdif=dif;
	    if(ans=="0")
	      {
		ans=cands[i];
	      }
	    if(stoll(cands[i])<stoll(ans))
	      {
		ans=cands[i];
	      }
	  }
	if(dif>maxdif)
	  {
	    maxdif=dif;
	    ans=cands[i];	
	  }
	
      }while(next_permutation(cands[i].begin(),cands[i].end()));
    }
  cout << ans << endl;
  return 0;
}


```