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

#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool u[10];
ll sll, p10;
ll cv = 0, bv = 0, bdiff = 0;

void dfs(ll left) {
	//cout << left << " " << cv << endl;

	if (left == 0) {
		ll diff = min(abs(cv - sll), p10 - abs(cv - sll));
		if (diff > bdiff || diff == bdiff && cv < bv) {
			bv = cv;
			bdiff = diff;
		}
		return;
	}

	rep(i, 0, 10) if (!u[i]) {
		u[i] = 1;
		cv = (cv * 10) + i;
		dfs(left - 1);
		cv /= 10;
		u[i] = 0;
	}
}

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	string s; cin >> s;
	sll = stoll(s);
	p10 = 1;
	rep(i, 0, s.length()) p10 *= 10;
	dfs(s.length());
	string ans = to_string(bv);
	if (ans.length() < s.length())
		ans = "0" + ans;
	cout << ans << endl;
}


### Prompt

Please provide a Cpp coded solution to the problem described below:

Example

Input

201


Output

701

### Response

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

#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool u[10];
ll sll, p10;
ll cv = 0, bv = 0, bdiff = 0;

void dfs(ll left) {
	//cout << left << " " << cv << endl;

	if (left == 0) {
		ll diff = min(abs(cv - sll), p10 - abs(cv - sll));
		if (diff > bdiff || diff == bdiff && cv < bv) {
			bv = cv;
			bdiff = diff;
		}
		return;
	}

	rep(i, 0, 10) if (!u[i]) {
		u[i] = 1;
		cv = (cv * 10) + i;
		dfs(left - 1);
		cv /= 10;
		u[i] = 0;
	}
}

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	string s; cin >> s;
	sll = stoll(s);
	p10 = 1;
	rep(i, 0, s.length()) p10 *= 10;
	dfs(s.length());
	string ans = to_string(bv);
	if (ans.length() < s.length())
		ans = "0" + ans;
	cout << ans << endl;
}


```