#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

string s, t, ans;
bool used[10];
ll Max = 0, ten = 1, a;
void dfs() {
	if (s.size() == t.size()) {
		ll b = stoll(t);
		ll k = min(abs(a - b), ten - abs(a - b));
		if (Max < k) {
			Max = k; ans = t;
		}
		else if (Max == k) {
			ll c = stoll(ans);
			if (b < c)ans = t;
		}
		return;
	}
	rep(i, 10) {
		if (!used[i]) {
			used[i] = true; t += char(i + '0');
			dfs();
			used[i] = false; t.pop_back();
		}
	}
}
int main() {
	cin >> s; a = stoll(s);
	rep(i, s.size())ten *= 10; dfs();
	cout << ans << endl;
}
### Prompt

Your task is to create 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;
typedef long long ll;

string s, t, ans;
bool used[10];
ll Max = 0, ten = 1, a;
void dfs() {
	if (s.size() == t.size()) {
		ll b = stoll(t);
		ll k = min(abs(a - b), ten - abs(a - b));
		if (Max < k) {
			Max = k; ans = t;
		}
		else if (Max == k) {
			ll c = stoll(ans);
			if (b < c)ans = t;
		}
		return;
	}
	rep(i, 10) {
		if (!used[i]) {
			used[i] = true; t += char(i + '0');
			dfs();
			used[i] = false; t.pop_back();
		}
	}
}
int main() {
	cin >> s; a = stoll(s);
	rep(i, s.size())ten *= 10; dfs();
	cout << ans << endl;
}
```