#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
int n;
string second;
long long a[26];
long long dp[1001][1001], mn[1001][1001], Min, Mx, cnt;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> second;
  for (int i = 0; i < 26; i++) cin >> a[i];
  for (int i = 1; i < n + 1; i++) {
    Min = MOD;
    for (int j = i; j < n + 1; j++) {
      Min = min(Min, a[(int)(second[j - 1] - 'a')]);
      mn[i][j] = Min;
    }
  }
  Mx = 1;
  dp[1][0] = 1, dp[1][1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 1;
         j < min((long long)i + 1, a[(int)(second[i - 1] - 'a')] + 1); j++) {
      if (mn[i - j + 1][i] < j) break;
      dp[i][j] = dp[i - 1][j - 1], dp[i][0] = (dp[i][0] + dp[i][j]) % MOD;
      if (dp[i][j]) Mx = max(Mx, (long long)(j));
    }
  }
  int i = n;
  while (i > 0) {
    for (int j = 1001 - 1; j >= 1; j--) {
      if (dp[i][j]) {
        cnt++;
        i = i - j;
        break;
      }
    }
  }
  cout << dp[n][0] << "\n" << Mx << "\n" << cnt;
  return 0;
}
