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

int main()
{
	string S, res;
	cin >> S;
	ll n = S.size(), md = -1, MAX = 1, s = stoll(S);
	vector<int> digit = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	for (int i = 0; i < n; i++) {
		MAX *= 10;
	}
	do {
		ll val = 0;
		string v;
		for (int i = 0; i < n; i++) {
			val = val * 10 + digit[i];
			v.push_back('0' + digit[i]);
		}
		ll d = min(MAX - abs(s - val), abs(s - val));
		if (d > md) {
			md = d;
			res = v;
		}
	} while (next_permutation(digit.begin(), digit.end()));
	cout << res << endl;
	return 0;
}
### 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;
using ll = long long;

int main()
{
	string S, res;
	cin >> S;
	ll n = S.size(), md = -1, MAX = 1, s = stoll(S);
	vector<int> digit = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	for (int i = 0; i < n; i++) {
		MAX *= 10;
	}
	do {
		ll val = 0;
		string v;
		for (int i = 0; i < n; i++) {
			val = val * 10 + digit[i];
			v.push_back('0' + digit[i]);
		}
		ll d = min(MAX - abs(s - val), abs(s - val));
		if (d > md) {
			md = d;
			res = v;
		}
	} while (next_permutation(digit.begin(), digit.end()));
	cout << res << endl;
	return 0;
}
```