#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef vectorVI; typedef vectorVVI; typedef vectorVS; typedef pairPII; typedef long long LL; typedef pairPLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PB push_back #define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define F first #define S second bool comp(const string &s,const string &t){ if(s.length()!=t.length())return s.length()>n; while(n--){ string str; cin>>str; while(str[0]=='0'&&str.length()>1){ str=str.substr(1,str.length()-1); } V.PB(str); } sort(V.begin(),V.end(),comp); string str=V[0]; LL d=0; LL ma=0; REP(i,str.length()){ LL v=(isdigit(str[i])?str[i]-'0':str[i]-'A'+10); ma=max(ma,v); } ma++; REP(i,str.length()){ d*=ma; d+=(isdigit(str[i])?str[i]-'0':str[i]-'A'+10); } cout<