#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define each(i,c) for(auto i=(c).begin();i!=(c).end();++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizoef(a)) #define sz(s) (int)((s).size()) #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define pb push_back #define MP(x,y) make_pair((x),(y)) using namespace std; typedef long long ll; typedef pair P; #define DIGIT 8 // 区切る数字の桁数 class MDC{ public: vector s2i (string s ); string ladd (vector, vector ); string lsub (vector, vector ); string lmul (vector, ll ); string ldiv (vector, ll ); private: string vi2s(vector ); }; ll s2ll (string s ){ stringstream ss (s ); ll res; ss >> res; return res; } string lltos (int n, int flag ){ stringstream ss; ss << n; string res; ss >> res; if (flag ){ while (res.length() != DIGIT ){ res = '0' + res; } // end while } // end if return res; } // 文字列の数字を DIGIT で区切った数字群に変換 vector MDC::s2i (string s ){ vector res; res.clear(); while (s.length() % DIGIT != 0 ){ s = '0' + s; } // end while for (int i = 0; i < s.length(); i += DIGIT ){ string t = s.substr (i, DIGIT ); res.push_back (s2ll(t ) ); } // end for return res; } // 数字群を文字列に変換 string MDC::vi2s (vector v ){ int n = v.size(); string res = ""; rep (i, n ) res += lltos(v[i], i ); return res; } // 足し算 string MDC::ladd (vector a, vector b ){ reverse (ALL (a ) ); reverse (ALL (b ) ); while (a.size() != b.size() ){ if (a.size() < b.size() ) a.push_back (0LL ); else b.push_back (0LL ); } // end while int n = a.size(); ll carry = 0LL; vector res; res.clear(); rep (i, n ){ ll c = (a[i] + b[i] ) + carry; if (c >= (ll)pow(10, DIGIT ) ){ c -= (ll)pow(10, DIGIT ); carry = 1LL; }else{ carry = 0LL; } // end if res.push_back (c ); } // end if if (carry ){ res.push_back (carry ); } // end if reverse(ALL (res ) ); return vi2s(res ); } // 掛け算 string MDC::lmul (vector a, ll b ){ reverse (ALL (a ) ); int n = a.size(); ll carry = 0LL; vector res; res.clear(); rep (i, n ){ ll d = a[i]*b + carry; ll c = d % ((ll)pow(10, DIGIT ) ); carry = (d - c ) / ((ll)pow(10, DIGIT ) ); res.push_back (c ); } // end if if (carry ) res.push_back (carry ); reverse (ALL (res ) ); return vi2s(res ); } map digits; string ladds (string s, string t ){ MDC MDC; vector a = MDC.s2i (s ); vector b = MDC.s2i (t ); string res = MDC.ladd (a, b ); return res; } string lmuls (ll s, ll b ){ MDC MDC; vector a; a.push_back (s ); string res = MDC.lmul (a, b ); return res; } // bit進数から10進数に変換する string todigit (string s, int bit ){ int n = s.length(); reverse (ALL (s ) ); ll d = 1LL; string res = ""; res += '0'; rep (i, n ){ string add = lmuls ((ll)digits[s[i]], d ); res = ladds (res, add ); d *= (ll)bit; } // end rep return res; } bool max_bool (string s, string t ){ if (s.length() != t.length() ){ if (s.length() > t.length() ) return true; else return false; } // end if rep (i, s.length() ){ if (s[i] == t[i] ) continue; return s[i] >= t[i]; } // end rep return true; } string max_s (string s, string t ){ return (max_bool(s, t ) ? s : t ); } bool min_bool (string s, string t ){ if (s.length() != t.length() ) return (s.length() < t.length() ); rep (i, s.length() ){ if (s[i] == t[i] ) continue; return s[i] <= t[i]; } // end rep return true; } string min_s (string s, string t ){ return (min_bool(s, t ) ? s : t ); } const char order[36] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; int main() { digits.clear(); rep (i, sizeof(order)/sizeof(order[0] ) ) digits[order[i]] = i; ios_base::sync_with_stdio(0); int N; cin >> N; string res = ""; rep (i, N ){ string s; cin >> s; int max_digits = 0; rep (j, s.length() ){ max_digits = max (max_digits, digits[s[j]]+1 ); } // end rep string curr = todigit (s, max_digits ); res = (i == 0 ? curr : min_s (res, curr ) ); // cerr << s <<'(' << max_digits << ')' << ' ' << curr << endl; } // end rep cout << res << endl; return 0; }