#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string X;
	cin >> X;
	ll N = 0;
	for(int i = 0; i < X.size(); i++){
		N = N * 10 + X[i] - '0';
	}
	int L = X.size();

	ll t = 1;
	for(int i = 0; i < L; i++){
		t *= 10;
	}

	vector<int> n;
	for(int i = 0; i < 10; i++){
		n.push_back(i);
	}

	ll maxd = -1;
	string ans;
	do{
		ll k = 0;
		for(int i = 0; i < L; i++){
			k = k * 10 + n[i];
		}
		ll d = min(abs(k - N), t - abs(k - N));
		string s = "";
		for(int i = 0; i < L; i++){
			s += '0' + n[i];
		}
		if(maxd < d || maxd == d && ans > s){
			maxd = d;
			ans = s;
		}
	} while(next_permutation(n.begin(), n.end()));

	cout << ans << endl;
}
### Prompt

Develop a solution in cpp to the problem described below:

Example

Input

201


Output

701

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string X;
	cin >> X;
	ll N = 0;
	for(int i = 0; i < X.size(); i++){
		N = N * 10 + X[i] - '0';
	}
	int L = X.size();

	ll t = 1;
	for(int i = 0; i < L; i++){
		t *= 10;
	}

	vector<int> n;
	for(int i = 0; i < 10; i++){
		n.push_back(i);
	}

	ll maxd = -1;
	string ans;
	do{
		ll k = 0;
		for(int i = 0; i < L; i++){
			k = k * 10 + n[i];
		}
		ll d = min(abs(k - N), t - abs(k - N));
		string s = "";
		for(int i = 0; i < L; i++){
			s += '0' + n[i];
		}
		if(maxd < d || maxd == d && ans > s){
			maxd = d;
			ans = s;
		}
	} while(next_permutation(n.begin(), n.end()));

	cout << ans << endl;
}
```