#include #include #include using namespace std; const int mod = 1e9 + 7; int main() { int n; scanf("%d", &n); vector a(n + 1); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); vector sum(n + 1, 0); vector f(n + 1, 0); vector lst(n + 1); string s; cin >> s; vector pos(26, -1); for (int i = 1; i <= n; i++) { int u = s[i - 1] - 'a'; lst[i] = pos[u]; pos[u] = i; } auto seg = [&](int l, int r) { if (l > r) return 0; int res = sum[r]; if (l - 1 >= 0) res -= sum[l - 1]; if (res < 0) res += mod; return res; }; int ans = 0; f[0] = 1; sum[0] = 1; vector single(n + 1); for (int i = 1; i <= n; i++) { int cur = 0; if (lst[i] == -1) cur = seg(0, i - 1); else { cur = seg(lst[i] + 1, i - 1); cur = (cur + single[lst[i]]) % mod; } single[i] = cur; cur = cur * 1ll * a[i] % mod; // printf("i = %d, cur = %d\n", i, cur); sum[i] = (sum[i - 1] + cur) % mod; ans = (ans + cur) % mod; } printf("%d\n", ans); return 0; }