#include <bits/stdc++.h>
using namespace std;
int n, mod = 1e9 + 7, arr[28], dp[1005], mx;
string s;
int solve(int i) {
  if (dp[i] != -1) return dp[i];
  if (i == n) return 1;
  int mn = arr[s[i] - 'a'], ans = 0;
  for (int j = i; j < n && j - i + 1 <= mn; j++) {
    mn = min(mn, arr[s[j] - 'a']);
    if (j - i + 1 > mn) break;
    if (solve(j + 1)) {
      mx = max(mx, j - i + 1);
      ans += solve(j + 1);
      ans %= mod;
    }
  }
  return dp[i] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> s;
  for (int i = 0; i < 26; i++) cin >> arr[i];
  int i = 0, j = 0, mn = arr[s[0] - 'a'], sub = 0;
  while (i < n) {
    while (j < n && j - i + 1 <= mn) {
      mn = min(mn, arr[s[j] - 'a']);
      if (j - i + 1 > mn) break;
      j++;
    }
    sub++, mn = arr[s[j] - 'a'];
    i = j;
  }
  int ans = solve(0);
  cout << ans << "\n" << mx << "\n" << sub << "\n";
  return 0;
}
