#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int M = 1e9 + 7;
int n;
string s;
int a[N];
long long dp[N] = {0};
int dp2[N] = {0};
bool can(int len) {
  for (int i = 0; i < len; ++i) {
    if (a[s[i] - 'a'] < len) {
      return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> s;
  for (int i = 0; i < 26; ++i) {
    cin >> a[i];
  }
  int mx = 1;
  dp[0] = 1;
  dp2[0] = 1;
  for (int i = 1; i < n; ++i) {
    if (can(i + 1)) {
      dp[i]++;
      dp2[i] = 1;
      mx = i + 1;
    } else
      dp2[i] = 1e5;
    int mn = a[s[i] - 'a'];
    for (int j = i - 1; j >= 0; --j) {
      if (mn < i - j) break;
      dp2[i] = min(dp2[i], 1 + dp2[j]);
      dp[i] = (dp[i] + dp[j]) % M;
      mx = max(mx, i - j);
      mn = min(mn, a[s[j] - 'a']);
    }
    dp[i] %= M;
  }
  cout << dp[n - 1] << endl;
  cout << mx << endl;
  cout << dp2[n - 1] << endl;
  return 0;
}
