#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

string s;
ll a, c, ret, ans;
void dfs(string t, int d) {
	//cout << t << " " << d << endl;
	if(t.size() == s.size()) {
		VI v;
		REP(i, t.size()) v.PB(t[i]-'0');
		do {
			ll b = 0;
			REP(i, t.size()) b *= 10, b += v[i];
			//cout << b << " " << abs(a-b) << " " << c-abs(a-b) << endl;
			if((ans < min(abs(a-b), c-abs(a-b))) || (ans == min(abs(a-b), c-abs(a-b)) && b < ret)) {
				ans = min(abs(a-b), c-abs(a-b));
				ret = b;
			}
		} while(next_permutation(ALL(v)));
		return;
	}
	FOR(i, d+1, 10) {
		char c = '0' + i;
		dfs(t + c, i);
	}
}

signed main(void)
{
	cin >> s;
	const int n = s.size();
	a = stol(s);
	c = 1, ans = -LLINF;
	REP(i, n) c *= 10;

	dfs("", -1);
	cout << setfill('0') << setw(n) << ret << endl;

	return 0;
}
### Prompt

Develop a solution in cpp to the problem described below:

Example

Input

201


Output

701

### Response

```cpp
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

string s;
ll a, c, ret, ans;
void dfs(string t, int d) {
	//cout << t << " " << d << endl;
	if(t.size() == s.size()) {
		VI v;
		REP(i, t.size()) v.PB(t[i]-'0');
		do {
			ll b = 0;
			REP(i, t.size()) b *= 10, b += v[i];
			//cout << b << " " << abs(a-b) << " " << c-abs(a-b) << endl;
			if((ans < min(abs(a-b), c-abs(a-b))) || (ans == min(abs(a-b), c-abs(a-b)) && b < ret)) {
				ans = min(abs(a-b), c-abs(a-b));
				ret = b;
			}
		} while(next_permutation(ALL(v)));
		return;
	}
	FOR(i, d+1, 10) {
		char c = '0' + i;
		dfs(t + c, i);
	}
}

signed main(void)
{
	cin >> s;
	const int n = s.size();
	a = stol(s);
	c = 1, ans = -LLINF;
	REP(i, n) c *= 10;

	dfs("", -1);
	cout << setfill('0') << setw(n) << ret << endl;

	return 0;
}
```