#include using namespace std; const int M = 1000003; const long long LINF = (long long)3e18; using frac = pair; long long fact[1000003], inv[1000003]; long long powmod(long long a, long long b) { if (b == 0) return 1LL; return (b & 1) ? a * powmod(a, b - 1) % M : powmod(a * a % M, b / 2); } long long comb(long long n, int k) { int a = (int)(n % M); int b = (int)((n - k) % M); if (a <= b) return 0; return fact[a] * inv[k] % M * inv[b] % M; } // a < b : -1, a == b : 0, a > b : 1 int compare(frac a, frac b) { long long da = a.first / a.second; long long db = b.first / b.second; if (da < db) return -1; if (da > db) return 1; a.first -= da * a.second; b.first -= db * b.second; if (a.first == 0 && b.first == 0) return 0; if (a.first == 0) return -1; if (b.first == 0) return 1; if (a.second < M && b.second < M) { long long ma = a.first * b.second; long long mb = b.first * a.second; return ma < mb ? -1 : ma == mb ? 0 : -1; } return compare(frac(b.second, b.first), frac(a.second, a.first)); } frac getmin(frac& a, frac& b) { return compare(a, b) < 0 ? a : b; } int main() { fact[0] = 1; for (int i = 1; i < M; ++i) { fact[i] = fact[i - 1] * i % M; } inv[M - 1] = powmod(fact[M - 1], M - 2); for (int i = M - 1; i > 0; --i) { inv[i - 1] = inv[i] * i % M; } long long s[26]; for (int i = 0; i < 26; ++i) cin >> s[i]; string t; cin >> t; vector lis[26]; int sz[26] = {}; for (int i = 0; i < (int)t.size(); ++i) { if (i > 0 && t[i] == t[i - 1]) ++lis[t[i] - 'a'][sz[t[i] - 'a'] - 1]; else { lis[t[i] - 'a'].push_back(1); ++sz[t[i] - 'a']; } --s[t[i] - 'a']; } long long ans = 1; for (int i = 0; i < 26; ++i) { if (s[i] < 0) { cout << "0\n"; return 0; } if (s[i] == 0 || sz[i] == 0) continue; long double l = 1, r = 1e7; vector cnt(sz[i]); while (1) { long double m = (l + r) / 2; long long sum = 0; vector minid; frac minf = frac(M * 9, 1); for (int j = 0; j < sz[i]; ++j) { if (sum + lis[i][j] / (m - 1) - 1 > LINF) { sum = LINF; break; } cnt[j] = (long long)(lis[i][j] / (m - 1) + 1e-9); if (cnt[j] == 0) continue; frac f = frac(lis[i][j] + cnt[j], cnt[j]); int c = compare(minf, f); if (c == 0) minid.push_back(j); else if (c > 0) { minf = f; minid.clear(); minid.push_back(j); } sum += cnt[j]; } if (sum >= s[i] && sum - (int)minid.size() <= s[i]) { int d = sum - s[i]; for (int j = 0; j < d; ++j) --cnt[minid[j]]; break; } if (sum < s[i]) r = m; else l = m; } for (int j = 0; j < sz[i]; ++j) ans = ans * comb(lis[i][j] + cnt[j], lis[i][j]) % M; } cout << ans << "\n"; return 0; }