#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
 
using ll=long long;
 
 
ll cmp(ll ten,string s,string t){
	ll a=0LL,b=0LL;
	for(auto &i:s) a=10LL*a+i-'0';
	for(auto &i:t) b=10LL*b+i-'0';
	return min(abs(a-b),ten-abs(a-b));
}
 
int main(void){
	string s,t;
	cin >> s;
	int n=s.size();
	ll ten=1LL;
	rep(i,n) ten*=10LL;
 
	rep(i,10) t+=(i+'0');
	ll cmax=0;
	string ans="";
	do{
		string ct=t.substr(0,n);
		ll cur=cmp(ten,s,ct);
		if(cur>cmax||(cur==cmax&&ct<ans)) cmax=cur,ans=ct;
	}while(next_permutation(t.begin(),t.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>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
 
using ll=long long;
 
 
ll cmp(ll ten,string s,string t){
	ll a=0LL,b=0LL;
	for(auto &i:s) a=10LL*a+i-'0';
	for(auto &i:t) b=10LL*b+i-'0';
	return min(abs(a-b),ten-abs(a-b));
}
 
int main(void){
	string s,t;
	cin >> s;
	int n=s.size();
	ll ten=1LL;
	rep(i,n) ten*=10LL;
 
	rep(i,10) t+=(i+'0');
	ll cmax=0;
	string ans="";
	do{
		string ct=t.substr(0,n);
		ll cur=cmp(ten,s,ct);
		if(cur>cmax||(cur==cmax&&ct<ans)) cmax=cur,ans=ct;
	}while(next_permutation(t.begin(),t.end()));
 
	cout << ans << endl;
	return 0;
}	
```