#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
const int MOD = 1e9 + 7;
int n;
int a[26];
char s[MAX_N];
void solve() {
  vector<int> dp1(n + 1, 0), dp2(n + 1, n);
  dp1[n] = 1;
  dp2[n] = 0;
  int longest = 0;
  for (int i = n - 1; i >= 0; i--) {
    int maxLen = a[s[i] - 'a'];
    for (int j = i; j < n; j++) {
      maxLen = min(maxLen, a[s[j] - 'a']);
      if (j - i + 1 > maxLen) break;
      longest = max(longest, j - i + 1);
      dp1[i] = (dp1[i] + dp1[j + 1]) % MOD;
      dp2[i] = min(dp2[i], 1 + dp2[j + 1]);
    }
  }
  printf("%d\n%d\n%d", dp1[0], longest, dp2[0]);
}
int main() {
  scanf("%d%s", &n, s);
  for (int i = 0; i < 26; i++) {
    scanf("%d", &a[i]);
  }
  solve();
}
