#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); auto e1 = [&](vector d) { int L = d[0] * 100 + d[1] * 10 + d[2]; int R = d[3] * 100 + d[4] * 10 + d[5]; int A = d[1] * 1000 + d[6] * 100 + d[2] * 10 + d[1]; bool f = d[0] != 0 && d[3] != 0 && d[1] != 0; return pair{f && (L + R == A), A}; }; auto e2 = [&](vector d) { int L = d[0] * 1000 + d[0] * 100 + d[1] * 10 + d[2]; int R = d[3] * 1000 + d[4] * 100 + d[5] * 10 + d[6]; int A = d[7] * 10000 + d[8] * 1000 + d[1] * 100 + d[2] * 10 + d[9]; bool f = d[0] != 0 && d[3] != 0 && d[7] != 0; return pair{f && (L + R == A), A}; }; auto e3 = [&](vector d) { int L = d[0] * 100000 + d[1] * 10000 + d[2] * 1000 + d[3] * 100 + d[4] * 10 + d[5]; int R = d[6] * 10000 + d[3] * 1000 + d[5] * 100 + d[7] * 10 + d[8]; int A = d[1] * 100000 + d[3] * 10000 + d[9] * 1000 + d[4] * 100 + d[3] * 10 + d[9]; bool f = d[0] != 0 && d[6] != 0 && d[1] != 0; return pair{f && (L + R == A), A}; }; int N; cin >> N; vector d(10); iota(d.begin(), d.end(), 0); do { bool b; int ans; if(N == 1) tie(b, ans) = e1(d); if(N == 2) tie(b, ans) = e2(d); if(N == 3) tie(b, ans) = e3(d); if(b) { cout << ans << endl; return 0; } } while(next_permutation(d.begin(), d.end())); }