// yukicoder: No.233 めぐるはめぐる (3) // bal4u 2019.8.25 #include #include #include typedef long long ll; //// 高速入力 #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } char c2d[128]; char d2c[] = "_aeiubgmnr"; ll ins() { // 文字列の特殊入力 ll n = 0; int c = gc(); do n = 10 * n + c2d[c]; while ((c = gc()) > ' '); return n; } void outs(char *s) { while (*s) pc(*s++); pc('\n'); } char s[15]; void pr(ll x) { int i; for (i = 10; i >= 0; i--) s[i] = d2c[x % 10], x /= 10; outs(s); } // 数値のハッシュ関数 #define HASHSIZ 1296007 ll hash[HASHSIZ+5], *hashend = hash+HASHSIZ; int lookup(ll n) { ll *p = hash + (int)(n % HASHSIZ); while (*p) { if (*p == n) return 0; if (++p == hashend) p = hash; } return 1; } void insert(ll n) { ll *p = hash + (int)(n % HASHSIZ); while (*p) { if (*p == n) return; if (++p == hashend) p = hash; } *p = n; } //// 本問題関連 // char d2c[] = "_aeiubgmnr"; char code[11] = { 1,1,2,3,4,4,5,6,7,8,9 }; char f[11]; void rec(int id, ll x, int bo) { int i, j; ll y; if (id == 11) { if (lookup(x)) { pr(x); exit(0); } return; } x *= 10; for (i = 6; i < 11; i++) if (f[i]) { f[i] = 0, y = 10*(x + code[i]); for (j = 0; j < 6; j++) if (f[j]) { f[j] = 0, rec(id+2, y + code[j], bo), f[j] = 1; } f[i] = 1; } if (!bo) for (i = 0; i < 6; i++) if (f[i]) f[i] = 0, rec(id+1, x + code[i], 1), f[i] = 1; } int main() { int i, N; for (i = 0; d2c[i]; i++) c2d[d2c[i]] = i; N = in(); if (N == 129600) { outs("NO"); return 0; } while (N--) insert(ins()); memset(f, 1, sizeof(f)); rec(0, 0, 0); outs("NO"); return 0; }