#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

ll table_5[120][5],index_10,leftTable[120],rightTable[120],m_data[10] = {0,1,2,3,4,5,6,7,8,9};
ll* table_10;

void calc10(){

	int select_num = 5,num,loc_left[5],loc_right[5],left_index,right_index,index,calc[5],value;

	index_10 = 0;

	for(int i = 0; i < 1024;i++){
		num = 0;
		for(int k = 0; k < 10; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		//??°???????????????????????????
		for(int k = 0; k < 10; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		calc[0] = m_data[loc_left[0]],calc[1] = m_data[loc_left[1]],calc[2] = m_data[loc_left[2]],calc[3] = m_data[loc_left[3]],calc[4] = m_data[loc_left[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			leftTable[left_index++] = value;
		}

		calc[0] = m_data[loc_right[0]],calc[1] = m_data[loc_right[1]],calc[2] = m_data[loc_right[2]],calc[3] = m_data[loc_right[3]],calc[4] = m_data[loc_right[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			rightTable[right_index++] = value;
		}

		for(int k = 0; k < 120; k++){
			for(int p = 0; p < 120; p++){
				table_10[index_10++] = 100000*leftTable[k] + rightTable[p];
				//printf("%lld\n",table_10[index_10-1]);
			}
		}
	}
}


int main(){

	table_10 = new ll[3628800];

	int index_5 = 0;

	for(int a = 0; a < 5; a++){
		for(int b = 0; b < 5; b++){
			for(int c = 0; c < 5; c++){
				for(int d = 0; d < 5; d++){
					for(int e = 0; e < 5; e++){
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e){
							table_5[index_5][0] = a,table_5[index_5][1] = b,table_5[index_5][2] = c,table_5[index_5][3] = d,table_5[index_5][4] = e;
							index_5++;
						}
					}
				}
			}
		}
	}

	calc10();

	ll tmp,base_num = 0,length,maximum = -1,ans;

	char buf[11];

	scanf("%s",buf);

	for(length = 0;buf[length] != '\0';length++);

	for(int i = 0; i < length; i++){
		base_num = 10*base_num + buf[i] - '0';
	}

	ll S = pow(10,length),S2 = pow(10,length-1);

	for(int i = 0; i < 3628800; i++){
		tmp = min(abs(table_10[i]%S-base_num),S-abs(table_10[i]%S-base_num));
		if(tmp > maximum){
			maximum = tmp;
			ans = table_10[i]%S;
		}else if(tmp == maximum){
			if(ans > table_10[i]%S){
				ans = table_10[i]%S;
			}
		}
	}

	if(ans/S2 == 0)printf("0");
	printf("%lld\n",ans);

	return 0;
}
### Prompt

Construct a cpp code solution to the problem outlined:

Example

Input

201


Output

701

### Response

```cpp
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

ll table_5[120][5],index_10,leftTable[120],rightTable[120],m_data[10] = {0,1,2,3,4,5,6,7,8,9};
ll* table_10;

void calc10(){

	int select_num = 5,num,loc_left[5],loc_right[5],left_index,right_index,index,calc[5],value;

	index_10 = 0;

	for(int i = 0; i < 1024;i++){
		num = 0;
		for(int k = 0; k < 10; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		//??°???????????????????????????
		for(int k = 0; k < 10; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		calc[0] = m_data[loc_left[0]],calc[1] = m_data[loc_left[1]],calc[2] = m_data[loc_left[2]],calc[3] = m_data[loc_left[3]],calc[4] = m_data[loc_left[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			leftTable[left_index++] = value;
		}

		calc[0] = m_data[loc_right[0]],calc[1] = m_data[loc_right[1]],calc[2] = m_data[loc_right[2]],calc[3] = m_data[loc_right[3]],calc[4] = m_data[loc_right[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			rightTable[right_index++] = value;
		}

		for(int k = 0; k < 120; k++){
			for(int p = 0; p < 120; p++){
				table_10[index_10++] = 100000*leftTable[k] + rightTable[p];
				//printf("%lld\n",table_10[index_10-1]);
			}
		}
	}
}


int main(){

	table_10 = new ll[3628800];

	int index_5 = 0;

	for(int a = 0; a < 5; a++){
		for(int b = 0; b < 5; b++){
			for(int c = 0; c < 5; c++){
				for(int d = 0; d < 5; d++){
					for(int e = 0; e < 5; e++){
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e){
							table_5[index_5][0] = a,table_5[index_5][1] = b,table_5[index_5][2] = c,table_5[index_5][3] = d,table_5[index_5][4] = e;
							index_5++;
						}
					}
				}
			}
		}
	}

	calc10();

	ll tmp,base_num = 0,length,maximum = -1,ans;

	char buf[11];

	scanf("%s",buf);

	for(length = 0;buf[length] != '\0';length++);

	for(int i = 0; i < length; i++){
		base_num = 10*base_num + buf[i] - '0';
	}

	ll S = pow(10,length),S2 = pow(10,length-1);

	for(int i = 0; i < 3628800; i++){
		tmp = min(abs(table_10[i]%S-base_num),S-abs(table_10[i]%S-base_num));
		if(tmp > maximum){
			maximum = tmp;
			ans = table_10[i]%S;
		}else if(tmp == maximum){
			if(ans > table_10[i]%S){
				ans = table_10[i]%S;
			}
		}
	}

	if(ans/S2 == 0)printf("0");
	printf("%lld\n",ans);

	return 0;
}
```