#include <bits/stdc++.h>
using namespace std;
int n, dp[1003], dpw[1003], occ[26];
string s;
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < 26; i++) cin >> occ[i];
  dp[0] = 1;
  int mx = 1;
  for (int i = 1; i < n; i++) {
    int ml = occ[(int)(s[i] - 'a')];
    for (int j = i; j >= 0; j--) {
      ml = min(ml, occ[(int)(s[j] - 'a')]);
      if (i - j + 1 > ml)
        break;
      else {
        mx = max(mx, i - j + 1);
        if (j == 0)
          dp[i] = (((dp[i]) % (1000 * 1000 * 1000 + 7)) +
                   ((1) % (1000 * 1000 * 1000 + 7))) %
                  (1000 * 1000 * 1000 + 7);
        else {
          dp[i] = (((dp[i]) % (1000 * 1000 * 1000 + 7)) +
                   ((dp[j - 1]) % (1000 * 1000 * 1000 + 7))) %
                  (1000 * 1000 * 1000 + 7);
        }
      }
    }
  }
  cout << dp[n - 1] << '\n';
  cout << mx << '\n';
  dpw[0] = 1;
  for (int i = 1; i < n; i++) {
    dpw[i] = INT_MAX;
    int ml = occ[(int)(s[i] - 'a')];
    for (int j = i; j >= 0; j--) {
      ml = min(occ[(int)(s[j] - 'a')], ml);
      if (i - j + 1 > ml)
        break;
      else {
        if (j == 0)
          dpw[i] = 1;
        else
          dpw[i] = min(dpw[j - 1] + 1, dpw[i]);
      }
    }
  }
  cout << dpw[n - 1] << '\n';
}
