#include using namespace std; const long long MOD = 1000000007; vector z_algorithm(vector> S){ int N = S.size(); vector ans(N); for (int i = 1, j = 0; i < N; i++){ if (i + ans[i - j] < j + ans[j]){ ans[i] = ans[i - j]; } else { int k = max(0, j + ans[j] - i); while (i + k < N && S[k] == S[i + k]){ k++; } ans[i] = k; j = i; } } ans[0] = N; return ans; } long long tri(long long n){ return n * (n + 1) / 2 % MOD; } int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } string S; cin >> S; if (N == 1){ cout << tri(A[0]) << endl; } else { vector sum(N + 1); sum[0] = 0; for (int i = 0; i < N; i++){ sum[i + 1] = sum[i] + A[i]; } vector> T(N - 1); for (int i = 0; i < N - 1; i++){ T[i] = make_pair(A[i + 1], S[i + 1]); } vector Z = z_algorithm(T); long long ans = sum[N] + tri(A[0] - 1); for (int i = 1; i < N; i++){ if (S[i] == S[0]){ if (A[i] < A[0]){ ans += tri(A[i]); } else { ans += tri(A[0] - 1); ans += (long long) A[0] * (A[i] - A[0]) % MOD; ans += sum[Z[i] + 1]; int x = Z[i] + 1; int y = Z[i] + i + 1; if (y < N){ if (S[x] == S[y]){ ans += min(A[x], A[y]); } } } } ans %= MOD; } ans %= MOD; cout << ans << endl; } }