#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long DL = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  vector<int> alph(26);
  for (int i = 0; i < 26; ++i) {
    cin >> alph[i];
  }
  vector<long long> dp(n + 1);
  vector<long long> minLen(n + 1, INF);
  dp[0] = 1;
  minLen[0] = 0;
  int ansMaxLen = 0;
  for (int i = 1; i <= n; ++i) {
    int maxLen = alph[s[i - 1] - 'a'];
    for (int j = 1; j <= maxLen; ++j) {
      if (i >= j && alph[s[i - j] - 'a'] >= j) {
        dp[i] += dp[i - j];
        dp[i] %= DL;
        maxLen = min(maxLen, alph[s[i - j] - 'a']);
        ansMaxLen = max(ansMaxLen, j);
        minLen[i] = min(minLen[i], minLen[i - j] + 1);
      } else
        break;
    }
  }
  cout << dp[n] << endl;
  cout << ansMaxLen << endl;
  cout << minLen[n] << endl;
  return 0;
}
