#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) { a = max(a, b); } template void chmin(T& a, const T& b) { a = min(a, b); } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using mint = modint1000000007; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI a(n); rep(i, n) cin >> a[i]; string s; cin >> s; int last_pos[26]; rep(i, 26) last_pos[i] = -1; fenwick_tree ft(n + 1); ft.add(0, 1); rep(i, n) { int x = s[i] - 'a'; int c = a[i]; mint v = ft.sum(last_pos[x] + 1, n + 1); ft.add(i, (c - 1) * v); ft.add(i + 1, v); last_pos[x] = i; } mint ans = ft.sum(0, n + 1) - 1; cout << ans.val() << '\n'; }