#include <bits/stdc++.h>
using namespace std;
template <class T>
class RMQ {
 public:
  T *a;
  int t;
  T **mn;
  T maxn;
  int *log2;
  void SetMaxn(T *maxn) { this->maxn = *maxn; }
  void SetMaxn(T maxn) { this->maxn = maxn; }
  void Creat(T a[], int maxn) {
    int k = 1, p = 0;
    log2 = new int[maxn + 1];
    for (int i = 0; i <= maxn; i++) log2[i] = (i == 0 ? -1 : log2[i >> 1] + 1);
    while (k < maxn) {
      k *= 2;
      p += 1;
    }
    t = p;
    mn = new T *[maxn + 1];
    for (int i = 0; i < maxn; i++) {
      mn[i] = new T[t + 1];
      mn[i][0] = a[i];
      for (int j = 1; j <= t; j++) mn[i][j] = maxn;
    }
    for (int j = 1; j <= t; j++)
      for (int i = 0; i + (1 << j) <= maxn; i++) {
        T sa = mn[i][j - 1];
        T sb = mn[i + (1 << (j - 1))][j - 1];
        if (sa < sb)
          mn[i][j] = sa;
        else
          mn[i][j] = sb;
      }
  }
  T Getx(int ql, int qr) {
    int k = log2[qr - ql + 1];
    return min(mn[ql][k], mn[qr - (1 << k) + 1][k]);
  }
  T Getw(int ql, int qr) {
    --ql, --qr;
    int k = log2[qr - ql + 1];
    return min(mn[ql][k], mn[qr - (1 << k) + 1][k]);
  }
};
RMQ<int> rr;
char s[1010];
int a[28];
int cc[1010];
int dp[1010], f[1010];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  s[0] = 0;
  for (int i = 0; i < 26; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) s[i] -= 'a';
  for (int i = 1; i <= n; i++) cc[i] = a[s[i]];
  rr.Creat(cc + 1, n);
  int maxl = 0;
  dp[0] = 1;
  for (int i = 0; i <= n; i++) f[i] = 0x7fffffff;
  f[0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      int l = i - j;
      int d = rr.Getw(l + 1, i);
      if (j <= d) {
        if (maxl < j) maxl = j;
        dp[i] = (dp[i] + dp[l]) % 1000000007;
        f[i] = min(f[i], f[l] + 1);
      }
    }
  }
  printf("%d\n%d\n%d", dp[n], maxl, f[n]);
  return 0;
}
