#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector p(10); iota(p.begin(), p.end(), 0); do { if (n == 1) { // 0:シ, 1:イ, 2:タ, 3:ケ, 4:ヤ, 5:マ, 6:キ int shiita = p[0] * 100 + p[1] * 10 + p[2]; int keyama = p[3] * 100 + p[4] * 10 + p[5]; int ikitai = p[1] * 1000 + p[6] * 100 + p[2] * 10 + p[1]; if (shiita + keyama == ikitai && p[1] != 0) { cout << ikitai << endl; return 0; } } else if (n == 2) { // 0:オ, 1:ツ, 2:カ, 3:コ, 4:ク, 5:サ, 6:イ, 7:ビ, 8:ジ, 9:ン int ootsuka = p[0] * 1000 + p[0] * 100 + p[1] * 10 + p[2]; int kokusai = p[3] * 1000 + p[4] * 100 + p[5] * 10 + p[6]; int bijitsukan = p[7] * 10000 + p[8] * 1000 + p[1] * 100 + p[2] * 10 + p[9]; if (ootsuka + kokusai == bijitsukan && p[7] != 0) { cout << bijitsukan << endl; return 0; } } else { // 0:s, 1:p, 2:r, 3:i, 4:n, 5:g, 6:e, 7:h, 8:t, 9:c int spring = p[0] * 100000 + p[1] * 10000 + p[2] * 1000 + p[3] * 100 + p[4] * 10 + p[5]; int eight = p[6] * 10000 + p[3] * 1000 + p[5] * 100 + p[7] * 10 + p[8]; int picnic = p[1] * 100000 + p[3] * 10000 + p[9] * 1000 + p[4] * 100 + p[3] * 10 + p[9]; if (spring + eight == picnic && p[1] != 0) { cout << picnic << endl; return 0; } } } while (next_permutation(p.begin(), p.end())); return 0; }