#include <bits/stdc++.h>
using namespace std;
long long n, m, t, ans, x, y, c, d, a[26], res[1005], dp[1005], mod = 1e9 + 7;
bool f;
string s;
long long solve(long long p) {
  c = 1;
  d = 2;
  while (p > 0) {
    if (p & 1) c = (c * d) % mod;
    d = (d * d) % mod;
    p >>= 1;
  }
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  for (long long i = 0; i < 26; ++i) cin >> a[i];
  fill(res + 1, res + n + 1, 1e18 + 1);
  res[0] = 0;
  dp[0] = dp[1] = res[1] = ans = 1;
  for (long long i = 2, j; i <= n; ++i) {
    x = s[i - 1] - 'a';
    t = a[x];
    j = i;
    for (; i - j < a[x] && j > 0; --j) {
      y = s[j - 1] - 'a';
      t = min(t, a[y]);
      if (t <= i - j) break;
      res[i] = min(res[i], 1 + res[j - 1]);
      dp[i] = (dp[i] + dp[j - 1]) % mod;
      ans = max(ans, i - j + 1);
    }
  }
  cout << dp[n] << endl << ans << endl << res[n] << endl;
  return 0;
}
