#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int n;
char s[1005];
int mLen[26];
long long tot[1005][1005];
int maxLen;
int minCnt[1005][1005];
int main() {
  cin >> n >> s;
  for (int i = 0; i < 26; i++) cin >> mLen[i];
  maxLen = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) minCnt[i][j] = 1005;
  memset(tot, 0, sizeof(tot));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i; j <= n - 1; j++) {
      if (i < j) {
        tot[i][j] = tot[i][j - 1];
        int k = j - 1, tmp_max_len = mLen[s[j] - 'a'];
        while (j - k + 1 <= tmp_max_len && j - k + 1 <= mLen[s[k] - 'a'] &&
               i <= k - 1) {
          tot[i][j] = (tot[i][j] + tot[i][k - 1]) % 1000000007;
          tmp_max_len = min(tmp_max_len, mLen[s[k] - 'a']);
          maxLen = max(maxLen, j - k + 1);
          minCnt[i][j] = min(minCnt[i][j], minCnt[i][k - 1] + 1);
          k--;
        }
        if (i > k - 1 && j - k + 1 <= tmp_max_len &&
            j - k + 1 <= mLen[s[k] - 'a']) {
          tot[i][j] = (tot[i][j] + 1) % 1000000007;
          maxLen = max(maxLen, j - k + 1);
          minCnt[i][j] = 1;
        }
        if (minCnt[i][j] == 1005) minCnt[i][j] = minCnt[i][j - 1] + 1;
      } else
        tot[i][j] = minCnt[i][j] = 1;
    }
  }
  cout << tot[0][n - 1] << endl << maxLen << endl << minCnt[0][n - 1] << endl;
  return 0;
}
