#include <bits/stdc++.h>
using namespace std;
int a[27];
int64_t dp[1005], mi[1005], ma[1005];
int temp[1005][30];
int64_t mod = 1000000007;
bool isValid(int x, int y, int len) {
  for (int i = 0; i < 26; i++) {
    int cnt = temp[y][i] - temp[x - 1][i];
    if (cnt > 0) {
      if (a[i] < len) {
        return false;
      }
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < 1005; i++) {
    mi[i] = 99999;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      temp[i][j] = temp[i - 1][j];
    }
    temp[i][s[i - 1] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    cin >> a[i];
  }
  dp[0] = 1;
  mi[0] = 0;
  ma[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i - 1] == 0) continue;
    for (int j = i; j <= n; j++) {
      if (isValid(i, j, j - i + 1)) {
        ma[j] = max(ma[j], ma[i - 1]);
        mi[j] = min(mi[j], mi[i - 1] + 1);
        ma[j] = max(ma[j], (int64_t)j - i + 1);
        dp[j] = (dp[j] % mod + dp[i - 1] % mod) % mod;
      }
    }
  }
  cout << dp[n] << "\n" << ma[n] << "\n" << mi[n];
  return 0;
}
