//https://ncode.syosetu.com/n4830bu/295/ #include using namespace std; using ll = long long; int main() { vector S(26); string T; for (auto&& s : S) { cin >> s; } cin >> T; vector> cnt(26); char c = '-'; int len = 0; for (int i = 0; i < T.size(); i++) { char& t = T[i]; if (t != c) { if (c != '_') { cnt[c - 'a'].emplace_back(len); } c = t; len = 0; } len++; } if (len) cnt[c - 'a'].emplace_back(len); ll ans = 1; for (int i = 0; i < 26; i++) { priority_queue, vector>, function& x, const pair& y)>> que([](const pair& x, const pair& y) { return __int128(x.first + 1) * (y.first - y.second + 1) < __int128(y.first + 1) * (x.first - x.second + 1); }); for (auto&& x : cnt[i]) { S[i] -= x; que.push({x, x}); } if (S[i] < 0) { cout << 0 << endl; return 0; } if (cnt[i].size() == 0) continue; while (S[i]--) { auto [maine, book] = que.top(); que.pop(); ans /= (maine - book + 1); if (__int128(ans) * (maine + 1) < (1ll << 62)) ans *= (maine + 1); else { cout << "hel" << endl; return 0; } que.push({maine + 1, book}); } } cout << ans << endl; }