#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
int a[30];
char s[3500];
int dp[3500];
int min_num[3500];
bool check(int c, int b) {
  for (int i = c - b + 1; i <= c; i++) {
    int tmp = (int)(s[i] - 'a');
    if (a[tmp] < b) return false;
  }
  return true;
}
int main() {
  int n;
  while (cin >> n) {
    scanf("%s", s + 1);
    for (int i = 0; i < 26; i++) cin >> a[i];
    memset(dp, 0, sizeof(dp));
    min_num[0] = 0;
    dp[0] = 1;
    int max_num = 0;
    for (int i = 1; i <= n; i++) {
      min_num[i] = INF;
      for (int j = 1; j <= i; j++) {
        if (check(i, j)) {
          max_num = max(max_num, j);
          min_num[i] = min(min_num[i], min_num[i - j] + 1);
          dp[i] = (dp[i] + dp[i - j]) % mod;
        }
      }
    }
    cout << dp[n] << endl;
    cout << max_num << endl;
    cout << min_num[n] << endl;
  }
  return 0;
}
