#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

ll tonum(string s){
	ll res=0;
	for(char c:s){
		res*=10;
		res+=c-'0';
	}
	return res;
}

ll make(int n,vector<int> v){
	ll res=0;
	for(int i=0;i<n;i++){
		res*=10;
		res+=v[i];
	}
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n=s.size();
	ll num=tonum(s);
	ll ten=1;
	for(int i=0;i<n;i++){
		ten*=10;
	}
	vector<int> v(10);
	ll ma=0;
	ll ans=ten;
	for(int i=0;i<10;i++){
		v[i]=i;
	}
	do{
		ll t=make(n,v);
		if(ma<min(abs(num-t),ten-abs(num-t))){
			ans=t;
		}
		else if(ma==min(abs(num-t),ten-abs(num-t))){
			ans=min(ans,t);
		}
		ma=max({ma,min(abs(num-t),ten-abs(num-t))});
	}while(next_permutation(v.begin(),v.end()));
	if(ans<ten/10)cout << 0;
	cout << ans << endl;
}

### Prompt

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

Example

Input

201


Output

701

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

ll tonum(string s){
	ll res=0;
	for(char c:s){
		res*=10;
		res+=c-'0';
	}
	return res;
}

ll make(int n,vector<int> v){
	ll res=0;
	for(int i=0;i<n;i++){
		res*=10;
		res+=v[i];
	}
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n=s.size();
	ll num=tonum(s);
	ll ten=1;
	for(int i=0;i<n;i++){
		ten*=10;
	}
	vector<int> v(10);
	ll ma=0;
	ll ans=ten;
	for(int i=0;i<10;i++){
		v[i]=i;
	}
	do{
		ll t=make(n,v);
		if(ma<min(abs(num-t),ten-abs(num-t))){
			ans=t;
		}
		else if(ma==min(abs(num-t),ten-abs(num-t))){
			ans=min(ans,t);
		}
		ma=max({ma,min(abs(num-t),ten-abs(num-t))});
	}while(next_permutation(v.begin(),v.end()));
	if(ans<ten/10)cout << 0;
	cout << ans << endl;
}

```