#include #include #pragma GCC target ("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace atcoder; using ll=long long; #define endl "\n" #define rep(i,a,b) for(it i=(it)(a);i<=(it)b;i++) #define nrep(i,a,b) for(it i=(it)(a);i>=(it)b;i--) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define moda 998244353LL #define modb 1000000007LL #define dai 2500000000000000000LL #define tyu 2500000000 #define giri 1000000000 #define en 3.14159265358979 #define sho -dai #define eps 1e-14 #define yn(x) cout<<(x ? "Yes\n":"No\n"); #define YN(x) cout<<(x ? "YES\n":"NO\n"); using it=long long; using un=unsigned long long; using db=long double; using st=string; using ch=char; using bo=bool; using P=pair; using ip=pair; using mint=modint; using mints=modint998244353; using vi=vector; using ivi=vector; using vd=vector; using vs=vector; using vc=vector; using vb=vector; using vp=vector

; using ivp=vector; using vm=vector; using sp=set

; using isp=set; using ss=set; using sc=set; using si=set; using isi=set; using svi=set; using vvi=vector; using ivvi=vector; using vvd=vector; using vvs=vector; using vvb=vector; using vvc=vector; using vvp=vector; using ivvp=vector; using vvm=vector; using vsi=vector; using ivsi=vector; using vsp=vector; using ivsp=vector; using vvsi=vector; using ivvsi=vector; using vvsp=vector; using ivvsp=vector; using vvvi=vector; using ivvvi=vector; using vvvd=vector; using vvvm=vector; using vvvvi=vector; using ivvvvi=vector; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; map kazu; rep(i,0,9)kazu[(ch)(i+'0')]=i; rep(i,0,25)kazu[(ch)(i+'A')]=i+10; it ans=dai*2; rep(i,1,n){ st v;cin>>v; int ma=0; for(ch c:v)ma=max(ma,kazu[c]); it ima=0; for(ch c:v){ ima*=ma+1; ima+=kazu[c]; } ans=min(ans,ima); } cout<