#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<n)return 0; if(k==n || k==0)return 1; ll ret = 1; REP(i,k)ret=ret*(n-i)%MOD; FOR(i,1,k+1)ret=ret*mita[i]%MOD; return ret; } /* sum_i floor(((t[i]-1)*x+t[i]) / x)+1 <= s floor(y) >= y-1 {sum_i ((t[i]-1)*x+t[i]) / x} <= s sum_i (t[i]-1)*x + t[i] <= s * x ((sum_i t[i])-n)*x + (sum_i t[i]) <= s * x (sum_i t[i])*(1+x) <= (s+n) * x sum_i t[i] <= (s + n - sum_i t[i]) * x x >= (sum_i t[i]) / (s + n - sum_i t[i]) sum_i floor(((t[i]-1)*x+t[i]) / x)+1 <= s sum_i floor(((t[i]-1)*x+t[i]) / x) <= s-n sum_i floor(((t[i]-1)*x+t[i]) / x) + n >= s-n floor(y) <= y+1 sum_i ((t[i]-1)*x+t[i]) / x + 2n >= s-n sum_i (1+x)*t[i] - nx >= (s-3n)*x sum_i t[i] >= (s - 2n - sum_i t[i]) * x x <= (sum_i t[i]) / (s - 2n - sum_i t[i]) */ ll solve(ll n, ll s, vl t){ if(n==0)return 1ll; ll tsum = accumulate(ALL(t),0ll); if(tsum > s)return 0ll; if(tsum == s)return 1ll; // binary search Real low = tsum / ((Real)s + (Real)n - tsum); Real high = tsum / ((Real)s - (Real)(n*2) - tsum); // Real low = 0.0, high = 1048575.0; REP(_,40){ Real th = (low+high)/2.0; ll xsum = 0; bool over = false; REP(i,n){ // Real ri = (1.0 - th + t[i]*th) / (th-1.0); Real ri = ((t[i]-1.0)*th+t[i]) / th; if(ri + xsum >= (Real)s){ over = true; break; } ll x = (ll)floorl(ri)+1ll; CHMAX(x, t[i]); xsum += x; } if(!over && xsum <= s){ high = th; }else{ low = th; } } Real th = high; // rest ll xsum = 0; priority_queue> Q; vl xs(n); REP(i,n){ // Real ri = (1.0 - th + t[i]*th) / (th-1.0); Real ri = ((t[i]-1.0)*th+t[i]) / th; ll x = (ll)floorl(ri)+1ll; CHMAX(x, t[i]); xsum += x; xs[i] = x; Q.push(make_pair((Real)(x+1)/(x+1-t[i]),i)); } while(xsum < s){ auto P = Q.top(); Q.pop(); int id = P.second; xs[id]++; ll x = xs[id]; Q.push(make_pair((Real)(x+1)/(x+1-t[id]),id)); xsum++; } // calc ans ll ans = 1ll; REP(i,n){ ans = ans * comb(xs[i], t[i]) % MOD; } return ans; } int main(){ // mod inverse table mita[0] = 0; mita[1] = 1; FOR(i,2,MOD+1){ mita[i] = MOD - (ll)(MOD/i) * mita[MOD%i] % MOD; } // input vl s(26,0); REP(i,26)cin>>s[i]; string t; cin>>t; t = "$" + t + "$"; // calc ll ans = 1ll; REP(i,26){ char c = 'a'+i; vl ts; int cnt = 0; REP(j,t.size()){ if(t[j]!=c){ if(cnt > 0){ ts.push_back(cnt); } cnt = 0; }else{ cnt++; } } ll x = solve(ts.size(), s[i], ts); ans = ans * x % MOD; } cout<