#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

ll x, n, Dif, Ans, xx, N;
bool vis[50];
char ch[50];

inline ll Min(ll a, ll b) {
	return a < b ? a : b;
}
inline ll Abs(ll a) {
	return a < 0 ? -a : a;
}

void dfs(ll u, ll Ad, ll l) {
	if (l > n) {
		ll dif = Min(N - Abs(u - x), Abs(u - x));
		if (dif >= Dif) {
			if (Dif < dif || Ans > u) Ans = u;
			Dif = dif;
		}
		return;
	}
 	for (ll i = 0; i <= 9; i++)
		if (!vis[i]){
			vis[i] = 1;
			dfs(u + Ad * i, Ad * 10ll, l + 1);
			vis[i] = 0;
		}
}

int main(void) {
//	freopen("1.in", "r", stdin);
//	gets(ch);
	scanf("%s", ch);
	n = strlen(ch);
	for (int i = 0; i < n; i++)
		x = x * 10ll + ch[i] - '0';
	N = 1;
	for (ll i = 0; i < n; i++) N *= 10;
	dfs(0, 1, 1);
	if (Ans * 10ll < N) putchar('0');
//	printf("%lld\n", Ans);
	cout << Ans << endl;
	return 0;
}
### Prompt

Create a solution in Cpp for the following problem:

Example

Input

201


Output

701

### Response

```cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

ll x, n, Dif, Ans, xx, N;
bool vis[50];
char ch[50];

inline ll Min(ll a, ll b) {
	return a < b ? a : b;
}
inline ll Abs(ll a) {
	return a < 0 ? -a : a;
}

void dfs(ll u, ll Ad, ll l) {
	if (l > n) {
		ll dif = Min(N - Abs(u - x), Abs(u - x));
		if (dif >= Dif) {
			if (Dif < dif || Ans > u) Ans = u;
			Dif = dif;
		}
		return;
	}
 	for (ll i = 0; i <= 9; i++)
		if (!vis[i]){
			vis[i] = 1;
			dfs(u + Ad * i, Ad * 10ll, l + 1);
			vis[i] = 0;
		}
}

int main(void) {
//	freopen("1.in", "r", stdin);
//	gets(ch);
	scanf("%s", ch);
	n = strlen(ch);
	for (int i = 0; i < n; i++)
		x = x * 10ll + ch[i] - '0';
	N = 1;
	for (ll i = 0; i < n; i++) N *= 10;
	dfs(0, 1, 1);
	if (Ans * 10ll < N) putchar('0');
//	printf("%lld\n", Ans);
	cout << Ans << endl;
	return 0;
}
```