#include <bits/stdc++.h>   using namespace std;   long long a[27];   bool h[27];   bool valid[1005][1005];   long long dp[1005];   int main() {     for (int i = 0; i < 1005; i++) {       for (int j = 0; j < 1005; j++) valid[i][j] = false;     }     for (int i = 0; i < 26; i++) h[i] = false;     int n, lsub = 1;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < 26; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int f = 0;       for (int j = i; j < n; j++) {         h[s[j] -  a ] = true;         for (int k = 0; k < 26; k++)           if (h[k] && a[k] < j - i + 1) {             f = 1;             break;           }         if (f == 1) break;         valid[i][j] = true;         lsub = max(lsub, j - i + 1);       }       for (int k = 0; k < 26; k++) h[k] = false;     }     dp[0] = 1;     dp[-1] = 1;     for (int i = 1; i < n; i++) {       dp[i] = dp[i - 1];       for (int j = 0; j < i; j++) {         if (valid[j][i]) dp[i] = (dp[i] + dp[j - 1]) % 1000000007;       }     }     int i = 0, j = 0, k = 0;     while (i < n) {       if (!valid[j][i]) {         j = i;         k++;       }       i++;     }     cout << dp[n - 1] <<   n ;     cout << lsub <<   n ;     cout << k + 1 <<   n ;   }   