// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx2,tune=native") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BIT(i,j) (((i)>>(j))&1LL) #define MASK(i) (1LL<<(i)) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define fi first #define se second #define ull ungsigned long long #define ll long long #define ld long double #define vi vector #define vvi vector #define vvvi vector #define pii pair #define vpii vector #define vvpii vector #define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j) #define REPD(i,be,en) for(int i = (be); i>=(en); i--) #define REP(i,be,en) for(int i = (be); i<=(en); i++) #define endl "\n" #define MP make_pair #define int ll //-----------------------------------------------------------------------------------------------// inline void scan(){} template inline void scan(F &f,R&... r){cin>>f;scan(r...);} inline void print(){} template inline void print(F f,R... r){cout< void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif //------------------------------------------------------------------------------------------------// const ll LINF = 1e18; const int INF = 1e9; const int LOG = 20; const int MAXN = 5e5+7; const int N = 1e2+3; const int MOD = 1e9+7; const int BASE = 1e5; const ld EPS = 1e-9; const ld PI = acos(-1); const int OFFSET = 1e3; //------------------------------------------------------------------------------------------------// template bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;} template bool maxi(T1 &a, T2 b){if(a T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; } template T lcm(T a, T b) { return a/gcd(a,b)*b; } //------------------------------------------------------------------------------------------------// /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- */ void add(int &a, int b){ a += b; if(a>=MOD) a -= MOD; } int dp[MAXN][27],a[MAXN],s[MAXN]; void solve(){ int n; cin >> n; for(int i = 1; i<=n; i++) cin >> a[i]; for(int i = 1; i<=n; i++){ char c; cin >> c; s[i] = c-'a'; } dp[0][26] = 1; for(int i = 1; i<=n; i++){ int now = s[i]; for(int j = 0; j<=26; j++){ add(dp[i][j],dp[i-1][j]); if(j!=now){ add(dp[i][now],1LL*dp[i-1][j]*a[i]%MOD); } } } int res = 0; for(int i = 0; i<=25; i++){ add(res,dp[n][i]); } cout << res << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } #define task1 "nothing" if(fopen(task1".inp","r")){ freopen(task1".inp","r",stdin); freopen(task1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/