#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(1e5) + 2;
const int mod = (int)(1e9) + 7;
int n, a[1111];
char second[1111];
int t[11111][22], d[1111][1111], distl[1111], distr[1111], usedl[1111],
    usedr[1111];
long long dp[1111];
vector<int> g[maxn];
int first[1111];
int get(int l, int r) {
  int k = first[r - l + 1];
  return min(t[l][k], t[r - (1 << k) + 1][k]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> second[i];
  }
  for (int i = 1; i <= 26; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) t[i][0] = a[second[i] - 'a' + 1];
  for (int i = 2; i <= 1111; i++) first[i] = first[i / 2] + 1;
  for (int j = 1; j <= 10; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      t[i][j] = min(t[i][j - 1], t[i + (1 << (j - 1))][j - 1]);
  }
  for (int len = 1; len <= n; len++) {
    for (int i = 1; i + len - 1 <= n; i++) {
      int j = i + len - 1;
      if (get(i, j) >= len) {
        g[i].push_back(j);
        g[j].push_back(i);
        d[i][j] = 1;
      }
    }
  }
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (d[j][i]) dp[i] = (dp[i] + dp[j - 1]) % mod;
    }
  }
  queue<int> q;
  q.push(1);
  usedl[1] = 1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i] + 1;
      if (!usedl[to]) {
        usedl[to] = 1;
        distl[to] = distl[v] + 1;
        q.push(to);
      }
    }
  }
  q.push(n);
  usedr[n] = 1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i] - 1;
      if (!usedr[to]) {
        usedr[to] = 1;
        distr[to] = distr[v] + 1;
        q.push(to);
      }
    }
  }
  int mxlen = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if (d[i][j] && usedr[j] && usedl[i]) mxlen = max(mxlen, j - i + 1);
    }
  cout << dp[n] << endl << mxlen << endl << distl[n + 1];
  return 0;
}
