#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll MOD = 1000003; struct R { ll n, k; R () {} R (ll n, ll k) : n(n), k(k) { } bool operator < (const R& o) const { bool r1 = (n + 1) * (o.n + 1 - o.k) == (o.n + 1) * (n + 1 - k); return r1 ? k < o.k : (n + 1) * (o.n + 1 - o.k) < (o.n + 1) * (n + 1 - k); } }; ll modpow(ll a, int b) { if (b == 0) return 1LL; if (b == 1) return a; if (b % 2 == 1) return a * modpow(a, b-1); ll h = modpow(a, b/2); return h * h % MOD; } ll modinv(ll a) { return modpow(a, MOD-2); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll s[26]; string T; for (int j = 0; j < 26; ++j) { cin >> s[j]; } cin >> T; int co[26]; fill(co, co+26, 0); for (const char ch : T) { ++co[ch-'a']; } for (int j = 0; j < 26; ++j) { if (co[j] > s[j]) { cout << 0 << endl; return 0; } } vector cu[26]; char prev = T[0]; int count = 0; for (const char ch : T) { if (prev == ch) { ++count; } else { cu[prev-'a'].push_back(count); count = 1; } prev = ch; } cu[prev-'a'].push_back(count); ll ans = 1LL; for (int j = 0; j < 26; ++j) { priority_queue pq; for (int v : cu[j]) { pq.emplace(v, v); } if (pq.empty()) continue; for (int k = 0; k < s[j] - co[j]; ++k) { R r = pq.top(); pq.pop(); ans = ans * (r.n + 1) % MOD * modinv(r.n + 1 - r.k) % MOD; pq.emplace(r.n+1, r.k); } } cout << ans << endl; return 0; }