#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int MOD = 1e9 + 7;
long long dp[N];
int len_dp[N];
char str[N];
int cnt[30];
struct RMQ {
  int d[N][15];
  void init(int n) {
    int siz = n;
    for (int i = 0; i < siz; i++) d[i][0] = cnt[str[i] - 'a'];
    for (int j = 1; (1 << j) <= siz; j++) {
      for (int i = 0; i + (1 << j) - 1 < siz; i++) {
        d[i][j] = min(d[i][j - 1], d[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  int query(int l, int r) {
    int k = 0, lim = r - l + 1;
    while ((1 << (k + 1)) <= lim) k++;
    return min(d[l][k], d[r - (1 << k) + 1][k]);
  }
};
RMQ rmq;
int main() {
  int n;
  scanf("%d%s", &n, str);
  for (int i = 0; i < 26; i++) {
    scanf("%d", &cnt[i]);
  }
  rmq.init(n);
  dp[0] = 1;
  len_dp[0] = 1;
  int _max = 1;
  for (int i = 1; i < n; i++) {
    int l = max(0, i - cnt[str[i] - 'a'] + 1);
    dp[i] = dp[i - 1];
    len_dp[i] = len_dp[i - 1] + 1;
    for (int j = l; j < i; j++) {
      if (rmq.query(j, i) >= (i - j + 1)) {
        _max = max(_max, i - j + 1);
        dp[i] += j - 1 >= 0 ? dp[j - 1] : 1;
        len_dp[i] = min(len_dp[i], (j - 1 >= 0 ? len_dp[j - 1] : 0) + 1);
      }
    }
    if (dp[i] >= MOD) dp[i] %= MOD;
  }
  printf("%lld\n", dp[n - 1]);
  printf("%d\n", _max);
  printf("%d\n", len_dp[n - 1]);
}
