#include using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; ll mod=1e9+7; #define rep(i,a) for (ll i=0;i>N; vector A(N); string S; rep(i,N) cin>>A[i]; cin>>S; vector dp(N),prefix_sum(N+1); prefix_sum[0]=1; ll ans=0; vector before_ind(26,-1); rep(i,N){ int ch_num=(S[i]-'a'); dp[i]=prefix_sum[i]; if(before_ind[ch_num]!=-1){ dp[i]-=prefix_sum[before_ind[ch_num]+1]; dp[i]+=dp[before_ind[ch_num]]; dp[i]%=mod; } before_ind[ch_num]=i; prefix_sum[i+1]=(prefix_sum[i]+(dp[i]*A[i])%mod)%mod; } cout<<(mod-1+prefix_sum[N])%mod<<"\n"; }