#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; ll UNKO = 1LL<<62; double EPS = 1e-10; ll gcd(ll a, ll b) { if (b == 0) return abs(a); else return gcd(b, a % b); } ll mul(ll x, ll y) { double xy = (double)x * y; if (xy > UNKO * 1.9) return 0; return x * y; } ll c(ll n, ll k, vector >& C) { if (n < 5000) return C[n][k]; if (k > n - k) k = n - k; if (k > 10) return 0; vector bunshi(k), bunbo(k); for (int i = 0; i < k; i++) { bunshi[i] = k - i; bunbo[i] = i + 1; } for (int i = 0; i < k; i++) for (int j = 0; j < k; j++) { ll d = gcd(bunshi[i], bunbo[j]); bunshi[i] /= d; bunbo[j] /= d; } ll ans = 1; for (int i = 0; i < k; i++) ans = mul(ans, bunshi[i]); return ans; } int main() { vector > C(5000, vector(5000)); for (int i = 0; i < 5000; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) { if (!C[i - 1][j - 1] || (j <= i - 1 && !C[i - 1][j])) continue; C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; if (C[i][j] >= UNKO) C[i][j] = 0; } } vector a(26); for (int k = 0; k < 26; k++) cin >> a[k]; vector sum(26); vector > b(26, vector(1000001)); string s; cin >> s; s.push_back(' '); char prev = 0; int x = 0; for (int i = 0; i < s.length(); i++) { char c = s[i]; if (c == prev) x++; else { if (prev) { sum[prev - 'a'] += x; b[prev - 'a'][x]++; } prev = c; x = 1; } } for (int k = 0; k < 26; k++) if (a[k] < sum[k]) { cout << 0 << endl; return 0; } ll ans = 1; for (int k = 0; k < 26; k++) { int ma = 0; for (int x = 1; x <= 1000000; x++) if (b[k][x]) ma = x; if (ma == 0) continue; // cout << (char)('a' + k) << ' ' << ma << endl; a[k] -= sum[k]; int num = b[k][ma]; for (int t = 0; t < a[k] % num; t++) ans = mul(ans, c(ma + a[k] / num + 1, ma, C)); for (int t = 0; t < num - a[k] % num; t++) ans = mul(ans, c(ma + a[k] / num, ma, C)); } if (ans == 0 || ans >= UNKO) cout << "hel" << endl; else cout << ans << endl; }