#include <bits/stdc++.h>
using namespace std;
const int ALPHABET = 26;
int mx_length[ALPHABET];
string message;
bool isvalid(int i, int j) {
  int word_len = j - i + 1;
  for (int k = i; k <= j; ++k)
    if (mx_length[message[k] - 'a'] < word_len) return false;
  return true;
}
int mx_substr_length = 0;
int mn_no_substr = 1 << 28;
const int MOD = int(1e9 + 7);
const int MAX = 1009;
int dp[MAX];
int calc_ways(int idx) {
  if (idx >= (int)message.size()) {
    return 1;
  }
  if (dp[idx] != -1) return dp[idx];
  int ans = 0;
  for (int i = idx; i < (int)message.size(); ++i) {
    if (isvalid(idx, i)) ans = (ans % MOD + calc_ways(i + 1) % MOD) % MOD;
  }
  return dp[idx] = ans;
}
int calc_substr(int idx) {
  if (idx >= (int)message.size()) {
    return 0;
  }
  if (dp[idx] != -1) return dp[idx];
  int ans = 1 << 28;
  for (int i = idx; i < (int)message.size(); ++i) {
    if (isvalid(idx, i)) ans = min(ans, calc_substr(i + 1) + 1);
  }
  return dp[idx] = ans;
}
int calc_mx_substr(int idx) {
  if (idx >= (int)message.size()) {
    return 0;
  }
  if (dp[idx] != -1) return dp[idx];
  int ans = -1 << 28;
  for (int i = idx; i < (int)message.size(); ++i) {
    if (isvalid(idx, i))
      ans = max(ans, max((i - idx) + 1, calc_mx_substr(i + 1)));
  }
  return dp[idx] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  int n;
  cin >> n >> message;
  for (int i = 0; i < ALPHABET; ++i) cin >> mx_length[i];
  int no_ways = calc_ways(0);
  memset(dp, -1, sizeof dp);
  mx_substr_length = calc_mx_substr(0);
  memset(dp, -1, sizeof dp);
  mn_no_substr = calc_substr(0);
  cout << no_ways << endl << mx_substr_length << endl << mn_no_substr << endl;
}
