#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template void reader(T *x, S *y){reader(x);reader(y);} template void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template void writerLn(T x){writer(x,'\n');} template void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} template T GCD(T a,T b){T r; while(a){r=b; b=a; a=r%a;} return b;} void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){ ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q; r0=x; r1=y; a0=1; a1=0; b0=0; b1=1; while(r1>0){ q=r0/r1; r2=r0%r1; a2=a0-q*a1; b2=b0-q*b1; r0=r1; r1=r2; a0=a1; a1=a2; b0=b1; b1=b2; } *c=r0; *a=a0; *b=b0; } ll get_inv(ll n, ll p){ ll a,b,c; extended_euclid(n,p,&c,&a,&b); if(a s; string str, tmp, mn; rep(i,K) rep(j,C[i]) str += (char)('A'+i); do{ tmp = mn = str; rep(i,tmp.size()){ tmp = tmp.substr(1) + tmp[0]; mn = min(mn, tmp); } if(s.count(mn)==0) res++, s.insert(mn); }while(next_permutation(str.begin(), str.end())); return res; } int main(){ int i, j, k; int res, res1; fact[0] = 1; REP(i,1,1000100) fact[i] = fact[i-1] * i % MD; fact_inv[1000050] = get_inv(fact[1000050], MD); for(i=1000050-1;i>=0;i--) fact_inv[i] = fact_inv[i+1] * (i+1) % MD; reader(&K); rep(i,K) reader(C+i); res = solve(); writerLn(res); // res1 = solve_brute(); // writerLn(res,res1); // assert(res==res1); return 0; }