#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long memo[1010][27][1010], n, a[30];
string s;
long long mx = 0;
long long solve(int pos, int ch, long long cnt) {
  mx = max(mx, cnt);
  if (pos == n) return 1;
  if (ch != -1 && memo[pos][ch][cnt] != -1) return memo[pos][ch][cnt];
  long long x = s[pos] - 'a';
  long long ret = solve(pos + 1, x, 1);
  if (ch != -1) {
    long long nxt;
    if (a[x] < a[ch])
      nxt = x;
    else
      nxt = ch;
    if (cnt + 1 <= a[nxt]) ret = (ret + solve(pos + 1, nxt, cnt + 1)) % mod;
  }
  if (ch != -1) memo[pos][ch][cnt] = ret;
  return ret;
}
int main() {
  cin >> n >> s;
  for (int i = 0; i < 26; i++) cin >> a[i];
  memset(memo, -1, sizeof(memo));
  long long x = solve(0, -1, 0);
  long long y = 0, z = 1, mn = 1e9, cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      bool check = true;
      for (int k = i; k <= j; k++) {
        if (a[s[k] - 'a'] < j - i + 1) {
          check = false;
          break;
        }
      }
      if (!check) {
        i = j - 1;
        z++;
        break;
      }
      y = max(y, (long long)j - i + 1);
    }
  }
  cout << x << endl << mx << endl << z << endl;
  return 0;
}
