/* -*- coding: utf-8 -*- * * 1156.cc: No.1156 Nada Picnic 2 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const char ss[3][3][16] = { { "012", "345", "1621" }, { "0012", "3456", "78129" }, { "012345", "63578", "139439" } }; /* typedef */ /* global variables */ int ps[10]; /* subroutines */ inline int s2i(const char s[], int ps[]) { int sum = 0; for (int i = 0; s[i]; i++) sum = sum * 10 + ps[s[i] - '0']; return sum; } int fukumen(const char s0[], const char s1[], const char s2[]) { for (int i = 0; i < 10; i++) ps[i] = i; do { if (ps[s0[0] - '0'] != 0 && ps[s1[0] - '0'] != 0 && ps[s2[0] - '0'] != 0) { int a0 = s2i(s0, ps), a1 = s2i(s1, ps), a2 = s2i(s2, ps); if (a0 + a1 == a2) return a2; } } while (next_permutation(ps, ps + 10)); return 0; } /* main */ int main() { int n; scanf("%d", &n); n--; int a = fukumen(ss[n][0], ss[n][1], ss[n][2]); printf("%d\n", a); return 0; }