#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
int dp[3000];
char s[3000];
int a[300];
int xin[3000];
bool judge(int i,int j){
	int l=j-i+1;
	for(int k=i;k<=j;k++){
		if(a[s[k]-'a']<l)
		return false;
	}
	return true;
}
int main(){
    int mix=1;
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=0;i<26;i++)
        scanf("%d",&a[i]);
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    xin[0]=0;
    for(int i=1;i<=n;i++){
        xin[i]=inf;
        for(int j=1;j<=i;j++){
            if(judge(i-j+1,i)){
                dp[i]=(dp[i]+dp[i-j])%mod;
                xin[i]=min(xin[i],xin[i-j]+1);
                if(dp[i-j])
                mix=max(mix,j);
            }
        }
    }
    cout<<dp[n]<<endl;
    cout<<mix<<endl;
    cout<<xin[n]<<endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
long long dp[300];
char s[300];
int a[30];
int xin[300];
bool judge(int i,int j){
	int l=j-i+1;
	for(int k=i;k<=j;k++){
		if(a[s[k]-'a']<l)
		return false;
	}
	return true;
}
int main(){
    int n;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    xin[0]=0;
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=0;i<26;i++){
        scanf("%d",&a[i]);
    }
    int mix=1;
    for(int i=1;i<=n;i++){
        xin[i]=inf;
        for(int x=1;x<=i;x++){
            int l=i-x+1;
            if(judge(l,i)){
                dp[i]+=dp[i-x];
                dp[i]%=mod;
                xin[i]=min(xin[i],xin[i-x]+1);
                if(dp[i-x])
                    mix=max(mix,x);
            }
        }
    }
    cout<<dp[n]<<endl;
    printf("%d\n",mix);
    printf("%d\n",xin[n]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
int dp[300];
char s[300];
int a[30];
int xin[300];
bool judge(int i,int j){
	int l=j-i+1;
	for(int k=i;k<=j;k++){
		if(a[s[k]-'a']<l)
		return false;
	}
	return true;
}
int main(){
    int n;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    xin[0]=0;
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=0;i<26;i++){
        scanf("%d",&a[i]);
    }
    int mix=1;
    for(int i=1;i<=n;i++){
        xin[i]=inf;
        for(int x=1;x<=i;x++){
            int l=i-x+1;
            if(judge(l,i)){
                dp[i]+=dp[i-x];
                dp[i]%=mod;
                xin[i]=min(xin[i],xin[i-x]+1);
                if(dp[i-x])
                    mix=max(mix,x);
            }
        }
    }
    printf("%d\n",dp[n]);
    printf("%d\n",mix);
    printf("%d\n",xin[n]);
    return 0;
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[j] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mncnt;
    int mxlen;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < 26; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (i - j + 1 > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            mx = max(mx, i - j + 1);
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = max(i - j + 1, f[j - 1].mxlen);
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[j] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << mx << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mncnt;
    int mxlen;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < 26; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (i - j + 1 > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = max(i - j + 1, f[j - 1].mxlen);
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[j] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < 26; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[j] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < 26; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (i - j + 1 > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = i - j + 1;
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[j] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1010;
const int MO=1000000007;
char s[N];
int a[30],cnt[N][30];
int f[N][N],mlen[N][N];
bool vis[N][N];

bool check(int c1[],int c2[],int len)
{
    for (int i=0;i<26;i++) {
        if (c1[i]-c2[i]>0&&len>a[i]) return false;
    }
    return true;
}

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for (int i=0;i<26;i++) {
        scanf("%d",&a[i]);
    }
    vis[0][0]=true;
    f[0][0]=1;
    for (int i=1;i<=n;i++) {
        memcpy(cnt[i],cnt[i-1],sizeof(cnt[i]));
        cnt[i][s[i]-'a']++;
        for (int j=1;j<=i;j++) {
            for (int k=0;k<i;k++) {
                if (vis[k][j-1]) {
                    if (check(cnt[i],cnt[k],i-k)) {
                        f[i][j]=((ll)f[i][j]+f[k][j-1])%MO;
                        vis[i][j]=true;
                        mlen[i][j]=max(mlen[i][j],i-k);
                    }
                }
            }
        }
    }
    int tot=0,len=0,ans=0;
    for (int i=n,j=1;j<=n;j++) {
        tot=((ll)tot+f[i][j])%MO;
        if (!ans&&vis[i][j]) {
            ans=j;
            len=max(len,mlen[i][j]);
        }
    }
    printf("%d\n%d\n%d\n",tot,len,ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1010;
const int MO=1000000007;
char s[N];
int a[30];
int f[N],mnum[N];

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    for (int i=0;i<26;i++) {
        scanf("%d",&a[i]);
    }
    int mlen=0;
    f[0]=1;mnum[0]=0;
    for (int i=1;i<=n;i++) {
        int r=0;
        mnum[i]=i;
        for (int j=i-1;j>=0;j--) {
            r=max(r,i-a[s[j]-'a']);
            if (r>j) break;
            f[i]=((ll)f[i]+f[j])%MO;
            mnum[i]=min(mnum[i],mnum[j]+1);
            mlen=max(mlen,i-j);
        }
    }
    printf("%d\n%d\n%d\n",f[n],mlen,mnum[n]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1010;
const int MO=1000000007;
char s[N];
int a[30],cnt[N][30];
int f[N][N],mlen[N][N];
bool vis[N][N];

inline bool check(int c1[],int c2[],int len)
{
    for (int i=0;i<26;i++) {
        if (c1[i]-c2[i]>0&&len>a[i]) return false;
    }
    return true;
}

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for (int i=0;i<26;i++) {
        scanf("%d",&a[i]);
    }
    vis[0][0]=true;
    f[0][0]=1;
    for (int i=1;i<=n;i++) {
        memcpy(cnt[i],cnt[i-1],sizeof(cnt[i]));
        cnt[i][s[i]-'a']++;
        for (int k=0;k<i;k++) {
            if (check(cnt[i],cnt[k],i-k)) {
                for (int j=1;j<=i;j++) {
                    if (vis[k][j-1]) {
                        f[i][j]=((ll)f[i][j]+f[k][j-1])%MO;
                        vis[i][j]=true;
                        mlen[i][j]=max(mlen[i][j],mlen[k][j-1]);
                        mlen[i][j]=max(mlen[i][j],i-k);
                    }
                }
            }
        }
    }
    int tot=0,len=0,ans=0;
    for (int i=n,j=1;j<=n;j++) {
        if (vis[i][j]) {
            tot=((ll)tot+f[i][j])%MO;
            len=max(len,mlen[i][j]);
            if (!ans) ans=j;
        }
    }
    printf("%d\n%d\n%d\n",tot,len,ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1010;
const int MO=1000000007;
char s[N];
int a[30],cnt[N][30];
ll f[N][N];
int mlen[N][N];
bool vis[N][N];

bool check(int c1[],int c2[],int len)
{
    for (int i=0;i<26;i++) {
        if (c1[i]-c2[i]>0&&len>a[i]) return false;
    }
    return true;
}

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for (int i=0;i<26;i++) {
        scanf("%d",&a[i]);
    }
    vis[0][0]=true;
    f[0][0]=1;
    for (int i=1;i<=n;i++) {
        memcpy(cnt[i],cnt[i-1],sizeof(cnt[i]));
        cnt[i][s[i]-'a']++;
        for (int k=0;k<i;k++) {
            if (check(cnt[i],cnt[k],i-k)) {
                for (int j=1;j<=i;j++) {
                    if (vis[k][j-1]) {
                        f[i][j]=(f[i][j]+f[k][j-1])%MO;
                        vis[i][j]=true;
                        mlen[i][j]=max(mlen[i][j],i-k);
                    }
                }
            }
        }
    }
    ll tot=0;
    int len=0,ans=0;
    for (int i=n,j=1;j<=n;j++) {
        if (vis[i][j]) {
            tot=(tot+f[i][j])%MO;
            len=max(len,mlen[i][j]);
            if (!ans) ans=j;
        }
    }
    printf("%I64d\n%d\n%d\n",tot,len,ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1010;
const int MO=1000000007;
char s[N];
int a[30],cnt[N][30];
int f[N][N],mlen[N][N];
bool vis[N][N];

bool check(int c1[],int c2[],int len)
{
    for (int i=0;i<26;i++) {
        if (c1[i]-c2[i]>0&&len>a[i]) return false;
    }
    return true;
}

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    for (int i=0;i<26;i++) {
        scanf("%d",&a[i]);
    }
    vis[0][0]=true;
    f[0][0]=1;
    for (int i=1;i<=n;i++) {
        memcpy(cnt[i],cnt[i-1],sizeof(cnt[i]));
        cnt[i][s[i]-'a']++;
        for (int k=0;k<i;k++) {
            if (check(cnt[i],cnt[k],i-k)) {
                for (int j=1;j<=i;j++) {
                    if (vis[k][j-1]) {
                        f[i][j]=((ll)f[i][j]+f[k][j-1])%MO;
                        vis[i][j]=true;
                        mlen[i][j]=max(mlen[i][j],i-k);
                    }
                }
            }
        }
    }
    int tot=0,len=0,ans=0;
    for (int i=n,j=1;j<=n;j++) {
        tot=((ll)tot+f[i][j])%MO;
        if (!ans&&vis[i][j]) {
            ans=j;
            len=max(len,mlen[i][j]);
        }
    }
    printf("%d\n%d\n%d\n",tot,len,ans);
    return 0;
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 1e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            f[i].x += f[j - 1].x;
            f[i].x %= mod;
            f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
            f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 2e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    can[0] = true;
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            if (can[j - 1]) {
                f[i].x += f[j - 1].x;
                f[i].x %= mod;
                f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
                f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
                can[i] = true;
            }
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    if (can[n]) {
        cout << f[n].mncnt << '\n';
    } else {
        cout << 0 << '\n';
    }
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 1e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 0;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            f[i].x += f[j - 1].x;
            f[i].x %= mod;
            f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
            f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    cout << f[n].mncnt << '\n';
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 1e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 1;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) break;
            f[i].x += f[j - 1].x;
            f[i].x %= mod;
            f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
            f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    cout << f[n].mncnt << '\n';
}


#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

const int N = (int)1e3 + 123;
const int MOD = (int)1e9 + 7;

char s[N];
int a[200];

int add(int a, int b) {
    long long res = a + b;
    return (int) (res % MOD);
}

int mul(int a, int b) {
    long long res = a * 1ll * b;
    return (int) (res % MOD);
}

int dp[N];
int ans[N];

bool ok[N][N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    for (int i = 0; i < 26; ++i) {
        scanf("%d", &a[i + 'a']);
    }
    ok[0][0] = true;
    int max_len = 1;
    for (int i = 1; i <= n; ++i) {
        ok[i][i] = true;
        int mn = a[s[i - 1]];
        for (int j = i + 1; j <= n; ++j) {
            if (a[s[j - 1]] < mn) {
                mn = a[s[j - 1]];
            }
            ok[i][j] |= ok[i][j - 1] * (mn >= (j - i + 1));
            if (ok[i][j]) {
                max_len = max(max_len, j - i + 1);
            }
        }
    }
    dp[0] = 1;
    ans[0] = 0;
    for (int i = 1; i <= n; ++i) {
        ans[i] = MOD;
        for (int j = 0; j < i; ++j) {
            if (ok[j + 1][i]) {
                dp[i] = add(dp[i], dp[j]);
                ans[i] = min(ans[i], ans[j] + 1);
            }
        }
    }
    printf("%d\n%d\n%d", dp[n], max_len, ans[n]);
    return 0;
}


#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;
using ld = long double;

using namespace std;

const ll mod = 1e9 + 7;
const ll inf = 1e9;

struct st {
    ll x, mxlen, mncnt;
    st() {
        x = 0;
        mxlen = 1;
        mncnt = inf;
    }
};

const int N = 1234;

bool can[N];
st f[N];
int a[26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    f[0].mncnt = 0;
    f[0].x = 1;
    for (int i = 1; i <= n; ++i) {
        vector<bool> was(26, 0);
        for (int j = i; j > 0; --j) {
            int c = s[j] - 'a';
            int len = i - j + 1;
            was[c] = true;
            bool ok = true;
            for (int w = 0; w < 26; ++w) {
                if (was[w]) {
                    if (len > a[w]) {
                        ok = false;
                    }
                }
            }
            if (!ok) continue;
            f[i].x += f[j - 1].x;
            f[i].x %= mod;
            f[i].mxlen = max((ll)(len), f[j - 1].mxlen);
            f[i].mncnt = min(f[i].mncnt, f[j - 1].mncnt + 1);
        }
    }
    cout << f[n].x << '\n';
    cout << f[n].mxlen << '\n';
    cout << f[n].mncnt << '\n';
}


#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

const int N = (int)1e3 + 123;
const int MOD = (int)1e9 + 7;

char s[N];
int a[200];

int add(int a, int b) {
    long long res = a + b;
    return (int) (res % MOD);
}

int mul(int a, int b) {
    long long res = a * 1ll * b;
    return (int) (res % MOD);
}

int dp[N];
int ans[N];

bool ok[N][N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    for (int i = 0; i < 26; ++i) {
        scanf("%d", &a[i + 'a']);
    }
    ok[0][0] = true;
    int max_len = 0;
    for (int i = 1; i <= n; ++i) {
        ok[i][i] = true;
        int mn = a[s[i - 1]];
        for (int j = i + 1; j <= n; ++j) {
            if (a[s[j - 1]] < mn) {
                mn = a[s[j - 1]];
            }
            ok[i][j] |= ok[i][j - 1] * (mn >= (j - i + 1));
            if (ok[i][j]) {
                max_len = max(max_len, j - i + 1);
            }
        }
    }
    dp[0] = 1;
    ans[0] = 0;
    for (int i = 1; i <= n; ++i) {
        ans[i] = MOD;
        for (int j = 0; j < i; ++j) {
            if (ok[j + 1][i]) {
                dp[i] = add(dp[i], dp[j]);
                ans[i] = min(ans[i], ans[j] + 1);
            }
        }
    }
    printf("%d\n%d\n%d", dp[n], max_len, ans[n]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans=1, an, mn2,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				ans= max(ans, cnt);
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
			mn3= vec[i-1];
		}
//		mn2= vec[i-1];
//		for(int j= i-2 ; j>= 0 ; j--){
//
//		}
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		else
			an= 1;
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=0;
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		else
			an= 0;
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
			mn3= vec[i-1];
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		if(an+1>mn2){
			an= 0;
			mn2= vec[i-1];
		}
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
			mn3= vec[i-1];
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		else{
			an= 1;
			mn2= vec[i-1];
		}
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			ans= max(ans,cnt);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
			mn3= vec[i-1];
		}
	}
	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
			mn3= vec[i-1];
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		else{
			an= 0;
			mn2= vec[i-1];
		}
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN= 1e5+10, MOD= 1e9+7;
ll dp[MAXN];
int n,num[30],ans, an, mn2= MOD,ans2=1, mn3= MOD;
string s;
vector<int>vec;

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	for(int i=0 ; i < 26 ; i++)
		cin>> num[i];
	for(int i=0 ; i < n ; i++)
		vec.push_back(num[s[i]-'a']);

	dp[0]=dp[1]= 1;
	for(int i=2 ; i <= n ; i++){
		dp[i]= dp[i-1];
		int cnt=1,mn= vec[i-1];

		for(int j=i-2 ; j >= 0 ; j--){
			mn=min(mn, vec[j]);
			cnt++;
			if(cnt <= mn&& i-cnt>= 0){
				dp[i]+= dp[i-cnt];
				dp[i]%= MOD;
			}
			else
				break;
		}
		dp[i]%= MOD;
	}
	dp[n]%= MOD;
	int j=0;
	for(int i=1 ; i <= n ; i++){
		j++;
//		cout<< j<<endl;
		mn3= min(mn3, vec[i-1]);
		if(mn3< j){
			ans2++;
			j=1;
		}

		mn2= min(mn2,vec[i-1]);
		if(an+1<= mn2&& an+1> ans){
			ans= an+1;
			an++;
		}
		else
			an= 0;
	}

	cout<< dp[n]<<endl<<ans<<endl<<ans2;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (correct(l, r)) ans++;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return ans % MOD;
}

int main() {
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<int> p(26);
string s;

int MOD = (int)1e9 + 7;

bool correct(int l, int r) {
    string buffer;
    for (int i = l; i <= r; i++) {
        buffer += s[i];
        int len = (int)buffer.size();
        bool good = true;
        for (int j = 0; j < (int)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

int calc(int l, int r) {
    if (l > r) {
        return 0;
    }
    if (l == r) {
        return 1;
    }
    string buffer;
    int ans = 0;
    if (correct(l, r)) ans++;
    for (int i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            ans += calc(i + 1, r);
            ans %= MOD;
        }
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    cin >> s;
    for (int i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<int> z;
    for (int i = 0; i < (int)s.size(); i++) {
        buffer += s[i];
        //cout << buffer << "\n";
        int len = (int)buffer.size();
        bool good = true;
        for (int j = 0; j < (int)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((int)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    int max_len = 0;
    for (int i = 0; i < (int)z.size(); i++) {
        max_len = max(max_len, z[i]);
    }
    cout << max_len << "\n" << (int)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];
int can[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        if (p[s[i] - 'a'] < r - l + 1) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (can[l][r] == -1 ? can[l][r] = correct(l, r) : can[l][r]) {
        ans++;
        max_len = max(max_len, r - l + 1);
    }
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (can[l][i] == -1 ? can[l][i] = correct(l, i) : can[l][i]) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
            can[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (correct(l, r)) ans++;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (correct(l, r)) ans++;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            ans += calc(i + 1, r);
            ans %= MOD;
        }
    }
    return ans % MOD;
}

int main() {
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        //cout << buffer << "\n";
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    long long max_len = 0;
    for (long long i = 0; i < (long long)z.size(); i++) {
        max_len = max(max_len, z[i]);
    }
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];
int can[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        if (p[s[i] - 'a'] < r - l + 1) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        max_len = max(max_len, 1);
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (can[l][r] == -1 ? can[l][r] = correct(l, r) : can[l][r]) {
        ans++;
        max_len = max(max_len, r - l + 1);
    }
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (can[l][i] == -1 ? can[l][i] = correct(l, i) : can[l][i]) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
            can[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (correct(l, r)) {
        ans++;
        max_len = max(max_len, r - l + 1);
    }
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];
int can[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (can[l][r] == -1 ? can[l][r] = correct(l, r) : can[l][r]) {
        ans++;
        max_len = max(max_len, r - l + 1);
    }
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (can[l][i] == -1 ? can[l][i] = correct(l, i) : can[l][i]) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
            can[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (l == r) {
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (correct(l, r)) ans++;
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (correct(l, i)) {
            ans += calc(i + 1, r);
            ans %= MOD;
        }
    }
    return ans % MOD;
}

int main() {
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        //cout << buffer << "\n";
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    long long max_len = 0;
    for (long long i = 0; i < (long long)z.size(); i++) {
        max_len = max(max_len, z[i]);
    }
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int a[1000 + 1][1000 + 1];
int can[1000 + 1][1000 + 1];

vector<long long> p(26);
string s;

long long MOD = (long long)1e9 + 7;
long long max_len = 0;

bool correct(long long l, long long r) {
    string buffer;
    for (long long i = l; i <= r; i++) {
        if (p[s[i] - 'a'] < r - l + 1) {
            return false;
        }
    }
    return true;
}

long long calc(long long l, long long r) {
    if (l > r) {
        return 0;
    }
    if (a[l][r] != -1) {
        return a[l][r];
    }
    if (l == r && p[s[l] - 'a'] > 0) {
        max_len = max(max_len, 1ll);
        return 1;
    }
    string buffer;
    long long ans = 0;
    if (can[l][r] == -1 ? can[l][r] = correct(l, r) : can[l][r]) {
        ans++;
        max_len = max(max_len, r - l + 1);
    }
    for (long long i = l; i <= r; i++) {
        buffer += s[i];
        if (can[l][i] == -1 ? can[l][i] = correct(l, i) : can[l][i]) {
            long long res = calc(i + 1, r);
            if (res != 0) {
                max_len = max(max_len, i - l + 1);
            }
            ans += res;
            ans %= MOD;
        }
    }
    return a[l][r] = (ans % MOD);
}

int main() {
    for (int i = 0; i < 1000 + 1; i++) {
        for (int j = 0; j < 1000 + 1; j++) {
            a[i][j] = -1;
            can[i][j] = -1;
        }
    }
    long long n;
    cin >> n;
    cin >> s;
    for (long long i = 0; i < 26; i++) {
        cin >> p[i];
    }
    string buffer;
    vector<long long> z;
    for (long long i = 0; i < (long long)s.size(); i++) {
        buffer += s[i];
        long long len = (long long)buffer.size();
        bool good = true;
        for (long long j = 0; j < (long long)buffer.size(); j++) {
            if (p[buffer[j] - 'a'] < len) {
                good = false;
            }
        }
        if (!good) {
            z.push_back(len - 1);
            buffer = s[i];
        }
    }
    if (!buffer.empty()) {
        z.push_back((long long)z.size());
    }
    cout << calc(0, n - 1) << "\n";
    cout << max_len << "\n" << (long long)z.size();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
int dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	dp[0] = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] += dp[j-1];
			}

		}
		if(now >= i+1) dp[i]++;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}

	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
long long dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] += dp[j-1];
			}

		}
		now = min(num[st[0]-'a'],now);
		if(now >= i+1) dp[i]++;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}
	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
long long MOD = 1e9+7;
long long dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] = dp[i] + dp[j-1]% MOD;
			}

		}
		now = min(num[st[0]-'a'],now);
		if(now >= i+1) dp[i] =  dp[i] + 1% MOD;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}
	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
long long MOD = 1e9+7;
long long dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] = (dp[i] + dp[j-1])% MOD;
			}
		}
		now = min(num[st[0]-'a'],now);
		if(now >= i+1) dp[i] =  (dp[i] + 1)% MOD;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}
	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
int dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	dp[0] = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] += dp[j-1];
			}

		}
		now = min(num[st[0]],now);
		if(now >= i+1) dp[i]++;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}
	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
char st[N];
int num[30];
int dp[N];
int n;
int main(){
	cin >> n;
	scanf("%s",st);
	for(int i= 1;i <= 26;i ++){
		scanf("%d",&num[i-1]);
	}
	int len = strlen(st);
	dp[0] = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] - 'a'];
		for(int j= i;j > 0;j --){
			now = min(now,num[st[j] - 'a']);
			if(now >= i - j+1){
					dp[i] += dp[j-1];
			}

		}
		now = min(num[st[0]-'a'],now);
		if(now >= i+1) dp[i]++;
		//cout <<i << ' '<< dp[i] << ' ' << now << endl;
	}
	cout << dp[len-1]<<endl;
	int mx = 0;
	for(int i= 0;i < len;i ++){
		int now = num[st[i] -'a'];
		for(int j= i;j < len;j ++){
			now = min(now,num[st[j] - 'a']);
			if(j - i+1 <= now){
				mx = max(mx,j-i+1);
			}
			else break;
		}
	}
	cout << mx << endl;
	mx = 0;
	int idx = 0;
	while(idx < len){
		bool ok = true;
		int now = num[st[idx] - 'a'];
		for(int i = idx;i < len;i ++){
			now = min(now,num[st[i] - 'a']);
			if(now >= i - idx +1){
				continue;
			}
			else {mx ++;idx = i;ok = false;break;}
		}
		if(ok) {mx ++;break;}
	}
	cout << mx << endl;
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 9;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min;

long long dp[1005][1005];

long long solve (int x, int y, int depth) {
	if (x == n) {
		ans_min = min (ans_min, depth);
		return 1;
	}
	if (x > y) return 0;
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x + mn - 1; i >= x; i --) {
		cur += solve (i + 1, y, depth + 1);
		cur %= MOD;
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < 26; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1, 0);
	printf ("%lld\n%d\n%d\n", p, ans_max, ans_min);
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 9;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min, D[1005];

long long dp[1005][1005];

long long solve (int x, int y) {
	if (x == n) {
		D[n] = 0;
		return 1;
	}
	if (x > y) return 0;
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;
	D[x] = n + 2;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x + mn - 1; i >= x; i --) {
		cur += solve (i + 1, y);
		D[x] = min (D[i + 1] + 1, D[x]);
		cur %= MOD;
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < 26; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1);
	printf ("%lld\n%d\n%d\n", p, ans_max, D[0]);
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min, D[1005];

long long dp[1005][1005];

long long solve (int x, int y) {
	if (x == n) {
		D[n] = 0;
		return 1ll;
	}
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;
	D[x] = n + 2;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x; i < x + mn; i ++) {
		cur += solve (i + 1, y);
		cur %= MOD;
	}
	for (int i = x; i <= x + mn; i ++) {
		D[x] = min (D[i] + 1, D[x]);
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < 26; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1);
	if (p == 0ll) {
		printf ("0\n0\n0\n");
	} else printf ("%lld\n%d\n%d\n", p, ans_max, D[0]);
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 9;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min, D[1005];

long long dp[1005][1005];

long long solve (int x, int y) {
	if (x == n) {
		D[n] = 0;
		return 1;
	}
	if (x > y) return 0;
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;
	D[x] = n + 2;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x; i < x + mn; i ++) {
		cur += solve (i + 1, y);
		cur %= MOD;
	}
	for (int i = x; i <= x + mn; i ++) {
		D[x] = min (D[i] + 1, D[x]);
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < 26; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1);
	printf ("%lld\n%d\n%d\n", p, ans_max, D[0]);
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 9;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min;

long long dp[1005][1005];

long long solve (int x, int y, int depth) {
	if (x == n) {
		ans_min = min (ans_min, depth);
		return 1;
	}
	if (x > y) return 0;
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x + mn - 1; i >= x; i --) {
		cur += solve (i + 1, y, depth + 1);
		cur %= MOD;
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < n; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1, 0);
	printf ("%lld\n%d\n%d\n", p, ans_max, ans_min);
	return 0;
}


/* ta yag odo batorshihiin code harj bn */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef long long ll;

const ll MOD = 1e9 + 9;
const ll INFl = 9223372036854775807ll;
const int inf = (1 << 28) - 1;

#define ff first
#define ss second
#define pb push_back
#define _N 300005
#define mk make_pair

ll power(ll x, ll y, ll z) { ll t = 1; while (y > 0) { if (y % 2) { t = (t * x) % z; } x = (x * x) % z; y /= 2; } return t; }

int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

ll sqr (ll x) {
	return x * x;
}

char S[_N];
int n, a[30], ans_max, ans_min, D[1005];

long long dp[1005][1005];

long long solve (int x, int y) {
	if (x == n) {
		D[n] = 0;
		return 1ll;
	}
	if (dp[x][y]) return dp[x][y];
	long long cur = 0ll;
	int mn = y - x + 1;
	D[x] = n + 2;

	for (int i = x; i <= y; i ++) {
		if (a[S[i] - 'a'] >= i - x + 1) {
			if (mn > a[S[i] - 'a']) mn = a[S[i] - 'a'];
		} else mn = i - x;
		if (mn <= i - x + 1) break;
	}
	ans_max = max (ans_max, mn);
	for (int i = x; i < x + mn; i ++) {
		cur += solve (i + 1, y);
		cur %= MOD;
	}
	for (int i = x; i <= x + mn; i ++) {
		D[x] = min (D[i] + 1, D[x]);
	}
	return dp[x][y] = cur;
}

int main () {
	scanf ("%d", &n);
	ans_max = 0; ans_min = n;
	scanf ("%s", S);
	for (int i = 0;i < 26; i++) scanf ("%d", &a[i]);
	long long p = solve (0, n - 1);
	if (p == 0ll) {
		printf ("0\n0\n0\n");
	} else printf ("%lld\n%d\n%d\n", p, ans_max, D[0]);
	return 0;
}


#include <bits/stdc++.h>
#define MAX 1010
using namespace std;

int n;
int x;
int tam, menor, len;
int a[26];
int dp[3][MAX];
string s;

int main(){
	cin>>n;
	cin>>s;

	for(int i=0; i<26; i++)
		cin>>a[i];

	dp[0][n]=1;

	for(int i=n-1; i>=0; i--){
		len=a[s[i]-'a'];
		tam=1;

		for(int j=i+1; j<n; j++){
			if(tam+1 <= min(len, a[s[j]-'a'])){
				len=min(len, a[s[j]-'a']);
				tam++;
			}
			else break;
		}

		dp[0][i]=0;
		for(int j=1; j<=tam; j++)
			dp[0][i]+=dp[0][i+j];

		dp[1][i]=max(dp[1][i+1], tam);
	}

	menor=0;
	for(int i=0; i<n; i++){
		menor++;
		//cout<<i<<" "<<menor<<"\n";
		for(int j=1; j<dp[1][i]; j++) i++;
	}

	cout<<dp[0][0]<<"\n"<<dp[1][0]<<"\n"<<menor<<"\n";
}


#include <bits/stdc++.h>
#define MAX 1010
#define MOD 1000000007
using namespace std;

int n;
int x;
int tam, menor, len, maior=0;
int a[26];
int dp[3][MAX];
string s;

int main(){
	cin>>n;
	cin>>s;

	for(int i=0; i<26; i++)
		cin>>a[i];

	dp[0][n]=1;

	for(int i=n-1; i>=0; i--){
		len=a[s[i]-'a'];
		tam=1;

		for(int j=i+1; j<n; j++){
			if(tam+1 <= min(len, a[s[j]-'a'])){
				len=min(len, a[s[j]-'a']);
				tam++;
			}
			else break;
		}

		dp[0][i]=0;
		for(int j=1; j<=tam; j++)
			dp[0][i]=(dp[0][i]+dp[0][i+j])%MOD;

		dp[1][i]=tam;
		maior=max(tam, maior);
	}

	//for(int i=0; i<n; i++){
	//	cout<<dp[1][i]<<"\n";
	//}

	menor=0;
	for(int i=0; i<n; i++){
		menor++;
		int k=i;
		//cout<<dp[1][i]<<" "<<i<<"\n";
		for(int j=1; j<dp[1][k] && j<n; j++) i++;
		//cout<<k<<"\n";
	}

	cout<<dp[0][0]<<"\n"<<maior<<"\n"<<menor<<"\n";
}


#include <bits/stdc++.h>
#define MAX 1010
using namespace std;

int n;
int x;
int tam, menor, len;
int a[26];
int dp[3][MAX];
string s;

int main(){
	cin>>n;
	cin>>s;

	for(int i=0; i<26; i++)
		cin>>a[i];

	dp[0][n]=1;

	for(int i=n-1; i>=0; i--){
		len=a[s[i]-'a'];
		tam=1;

		for(int j=i+1; j<n; j++){
			if(tam+1 <= min(len, a[s[j]-'a'])){
				len=min(len, a[s[j]-'a']);
				tam++;
			}
			else break;
		}

		dp[0][i]=0;
		for(int j=1; j<=tam; j++)
			dp[0][i]+=dp[0][i+j]%MOD;

		dp[1][i]=max(dp[1][i+1], tam);
	}

	menor=0;
	for(int i=0; i<n; i++){
		menor++;
		//cout<<i<<" "<<menor<<"\n";
		for(int j=1; j<dp[1][i]; j++) i++;
	}

	cout<<dp[0][0]<<"\n"<<dp[1][0]<<"\n"<<menor<<"\n";
}


#include <bits/stdc++.h>
#define MAX 1010
#define MOD 1000000007
using namespace std;

int n;
int x;
int tam, menor, len, maior=0;
int a[26];
int dp[3][MAX];
string s;

int main(){
	cin>>n;
	cin>>s;

	for(int i=0; i<26; i++)
		cin>>a[i];

	dp[0][n]=1;

	for(int i=n-1; i>=0; i--){
		len=a[s[i]-'a'];
		tam=1;

		for(int j=i+1; j<n; j++){
			if(tam+1 <= min(len, a[s[j]-'a'])){
				len=min(len, a[s[j]-'a']);
				tam++;
			}
			else break;
		}

		dp[0][i]=0;
		for(int j=1; j<=tam; j++)
			dp[0][i]=(dp[0][i]+dp[0][i+j])%MOD;

		dp[1][i]=tam;
		maior=max(tam, maior);
	}

	for(int i=0; i<n; i++){
		cout<<dp[1][i]<<"\n";
	}

	menor=0;
	for(int i=0; i<n; i++){
		menor++;
		int k=i;
		//cout<<dp[1][i]<<" "<<i<<"\n";
		for(int j=1; j<dp[1][k] && j<n; j++) i++;
		//cout<<k<<"\n";
	}

	cout<<dp[0][0]<<"\n"<<maior<<"\n"<<menor<<"\n";
}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
};
vector<long long> V;
R M[1005];
long long L=1;

int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    M[V.size()-1].a1=1;
    M[V.size()-1].a2=1;
long long w= V.size();
w-=2;

    for(long long  i=w;i>=0;i--)
    {long long ms=V[i];
for(long long j=0;(j+i)<V.size();j++)
{

ms=min(ms,V[i+j]);
if(ms<(j+1))break;
if((i+j) == V.size()-1){M[i].a2=1;L=max(j+1,L);M[i].a1++;break;}
M[i].a1+=M[i+j+1].a1;M[i].a1=M[i].a1%1000000007;M[i].a2=min(M[i].a2,M[i+j+1].a2+1);L=max(L,j+1);
}
    }
    cout<<(M[0].a1 %1000000007 )<<endl<<L<<endl<<M[0].a2<<endl;
}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
    G(R j){(this->a1)+=(j.a1);(this->a2)=min(j.a2+1,(this->a2));}
};
vector<long long> V;
R M[1005];
long long L=0;

int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    M[V.size()-1].a1=1;
    M[V.size()-1].a2=1;

    for(long long  i=V.size()-2;i>=0;i--)
    {long long ms=V[i];
for(long long j=0;(j+i)<V.size();j++)
{

ms=min(ms,V[i+j]);
if(ms<(j+1))break;
if((i+j) == V.size()-1){M[i].a2=1;L=max(j+1,L);M[i].a1++;break;}
M[i].a1+=M[i+j+1].a1;M[i].a2=min(M[i].a2,M[i+j+1].a2+1);L=max(L,j+1);
}
    }
    cout<<(M[0].a1 % 1000000007)<<endl<<L<<endl<<M[0].a2<<endl;
}


#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
};
vector<long long> V;
R M[1005];
long long L=1;

int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    M[V.size()-1].a1=1;
    M[V.size()-1].a2=1;
long long w= V.size();
w-=2;

    for(long long  i=w;i>=0;i--)
    {long long ms=V[i];
for(long long j=0;(j+i)<V.size();j++)
{

ms=min(ms,V[i+j]);
if(ms<(j+1))break;
if((i+j) == V.size()-1){M[i].a2=1;L=max(j+1,L);M[i].a1++;break;}
M[i].a1+=M[i+j+1].a1;M[i].a1=M[i].a1%1000000007;M[i].a2=min(M[i].a2,M[i+j+1].a2+1);L=max(L,j+1);
}
    }
    cout<<(M[0].a1 %1000000007 )<<endl<<L<<endl<<M[0].a2<<endl;
}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
    G(R j){(this->a1)+=(j.a1);(this->a2)=min(j.a2+1,(this->a2));}
};
vector<long long> V;
R M[1000];
long long L=0;
R key(long long X)
{
if(M[X].a1 != 0) return M[X];
long long  ms=V[X];
for(long long  i=0;(i+X)<(V.size());i++)
{
    ms=min(V[i+X],ms);
    if(ms>=i+1)
    { if(X+i < V.size() - 1){L=max(L,i+1); M[X].G(key(X+i+1));  }
        if(X+i == V.size() - 1) {M[X].a2=1;L=max(L,i+1);M[X].a1+=1;}
    }

}
return M[X];
}
int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    R K = key(0);
    cout<<K.a1<<endl<<L<<endl<<K.a2<<endl;

}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : int a1,a2;
    R(){a1=0;a2=100000000;}
    G(R j){(this->a1)+=(j.a1);(this->a2)=min(j.a2+1,(this->a2));}
};
vector<int> V;
R M[1000];
int L=0;
R key(int X)
{
if(M[X].a1 != 0) return M[X];
int ms=V[X];
for(int i=0;(i+X)<(V.size());i++)
{
    ms=min(V[i+X],ms);
    if(ms>=i+1)
    { if(X+i < V.size() - 1){L=max(L,i+1); M[X].G(key(X+i+1));  }
        if(X+i == V.size() - 1) {M[X].a2=1;L=max(L,i+1);M[X].a1+=1;}
    }

}
return M[X];
}
int main()
{int p;cin>>p;
    string s;cin>>s; int b[26];
    for(int i=0;i<26;i++) cin>>b[i];
    for(int i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    R K = key(0);
    cout<<K.a1<<endl<<L<<endl<<K.a2<<endl;

}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
    G(R j){(this->a1)+=(j.a1);(this->a2)=min(j.a2+1,(this->a2));}
};
vector<long long> V;
R M[1000];
long long L=0;
R key(long long X)
{
if(M[X].a1 != 0) return M[X];
long long  ms=V[X];
for(long long  i=0;(i+X)<(V.size());i++)
{
    ms=min(V[i+X],ms);
    if(ms>=i+1)
    { if(X+i < V.size() - 1){L=max(L,i+1); M[X].G(key(X+i+1));  }
        if(X+i == V.size() - 1) {M[X].a2=1;L=max(L,i+1);M[X].a1+=1;}
    }

}
return M[X];
}
int main()
{int p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    R K = key(0);
    cout<<K.a1<<endl<<L<<endl<<K.a2<<endl;

}


#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
};
vector<long long> V;
R M[1005];
long long L=0;

int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    M[V.size()-1].a1=1;
    M[V.size()-1].a2=1;

    for(long long  i=V.size()-2;i>=0;i--)
    {long long ms=V[i];
for(long long j=0;(j+i)<V.size();j++)
{

ms=min(ms,V[i+j]);
if(ms<(j+1))break;
if((i+j) == V.size()-1){M[i].a2=1;L=max(j+1,L);M[i].a1++;break;}
M[i].a1+=M[i+j+1].a1;M[i].a1=M[i].a1%1000000007;M[i].a2=min(M[i].a2,M[i+j+1].a2+1);L=max(L,j+1);
}
    }
    cout<<(M[0].a1 %1000000007 )<<endl<<L<<endl<<M[0].a2<<endl;
}


#include<iostream>
#include<vector>
using namespace std;
class R
{
    public : long long a1,a2;
    R(){a1=0;a2=100000000;}
    G(R j){(this->a1)+=(j.a1);(this->a2)=min(j.a2+1,(this->a2));}
};
vector<long long> V;
R M[1000];
long long L=0;
R key(long long X)
{
if(M[X].a1 != 0) return M[X];
long long  ms=V[X];
for(long long  i=0;(i+X)<(V.size());i++)
{
    ms=min(V[i+X],ms);
    if(ms>=i+1)
    { if(X+i < V.size() - 1){L=max(L,i+1); M[X].G(key(X+i+1));  }
        if(X+i == V.size() - 1) {M[X].a2=1;L=max(L,i+1);M[X].a1+=1;}
    }

}
return M[X];
}
int main()
{long long p;cin>>p;
    string s;cin>>s; long long  b[26];
    for(long long  i=0;i<26;i++) cin>>b[i];
    for(long long  i=0;i<s.length();i++)V.push_back(b[s[i]-'a']);
    R K = key(0);
    cout<<(K.a1 % 1000000007)<<endl<<L<<endl<<K.a2<<endl;

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define Sz(s) int((s).size())
#define Fill(s,v) memset(s,v,sizeof(s))
#define f(i,n) for (int i=0; i<n; i++)
#define f1(i,n) for (int i=1; i<=n; i++)
#define fI(i,a,b) for (int i=a; i<=b; i++)
int n;
string s;
int val[27];
int mxlen=0,mnp=1e9;
ll mem[1003][1003];

ll cont(int i,int l,int mn){
if(i==n-1){
        return 1;
}

ll &ans=mem[i][l];
if(ans!=-1)return ans;
ans=0;
ans+=cont(i+1,1,val[s[i+1]-'a']);
if(min(mn,val[s[i+1]-'a'])>l)ans+=cont(i+1,l+1,min(mn,val[s[i+1]-'a']));
return ans%(ll)(1e9+7);
}

set<pair<int,int> > st;

int main()
{
  memset(mem,-1,sizeof mem);
cin>>n>>s;
f(i,26)cin>>val[i];

int l=0,mn=1e9,c=0;
for(int i=0; i<n; i++){
    l++; mn=min(mn,val[s[i]-'a']);
    if(l==mn)l=0,mn=1e9,c++;
    else if(l>mn)l=1,mn=val[s[i]-'a'],c++;
}
if(l<=mn && l)c++;

for(int i=0; i<n; i++){

        st.insert({val[s[i]-'a'],i});
  int mnv=st.begin()->F;

    while(mnv<st.size() && st.size()>0){
            int ind=i-st.size()+1;
        st.erase({val[s[ind]-'a'],ind});
    mnv=st.begin()->F;
    }

    mxlen=max(mxlen,(int)st.size());
}

cout<<cont(0,1,val[s[0]-'a'])%(ll)(1e9+7)<<endl;
cout<<mxlen<<endl<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define Sz(s) int((s).size())
#define Fill(s,v) memset(s,v,sizeof(s))
#define f(i,n) for (int i=0; i<n; i++)
#define f1(i,n) for (int i=1; i<=n; i++)
#define fI(i,a,b) for (int i=a; i<=b; i++)
int n;
string s;
int val[27];
int mxlen=0,mnp=1e9;
ll mem[1003][1003];

ll cont(int i,int l,int mn){
    mxlen=max(mxlen,l);
if(i==n-1){
        return 1;
}

ll &ans=mem[i][l];
if(ans!=-1)return ans;
ans=0;
ans+=cont(i+1,1,val[s[i+1]-'a']);
if(min(mn,val[s[i+1]-'a'])>l)ans+=cont(i+1,l+1,min(mn,val[s[i+1]-'a']));
return ans;
}

int main()
{
  memset(mem,-1,sizeof mem);
cin>>n>>s;
f(i,26)cin>>val[i];

int l=0,mn=1e9,c=0;
for(int i=0; i<n; i++){
    l++; mn=min(mn,val[s[i]-'a']);
    if(l==mn)l=0,mn=1e9,c++;
    else if(l>mn)l=1,mn=val[s[i]-'a'],c++;
}
if(l<mn && l)c++;

cout<<cont(0,1,val[s[0]-'a'])<<endl;
cout<<mxlen<<endl<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define Sz(s) int((s).size())
#define Fill(s,v) memset(s,v,sizeof(s))
#define f(i,n) for (int i=0; i<n; i++)
#define f1(i,n) for (int i=1; i<=n; i++)
#define fI(i,a,b) for (int i=a; i<=b; i++)
int n;
string s;
int val[27];
int mxlen=0,mnp=1e9;
ll mem[1003][1003];

ll cont(int i,int l,int mn){
if(i==n-1){
        return 1;
}

ll &ans=mem[i][l];
if(ans!=-1)return ans;
ans=0;
ans+=cont(i+1,1,val[s[i+1]-'a']);
if(min(mn,val[s[i+1]-'a'])>l)ans+=cont(i+1,l+1,min(mn,val[s[i+1]-'a']));
return ans%(ll)(1e9+7);
}

set<pair<int,int> > st;

int main()
{
  memset(mem,-1,sizeof mem);
cin>>n>>s;
f(i,26)cin>>val[i];

int l=0,mn=1e9,c=0;
for(int i=0; i<n; i++){
    l++; mn=min(mn,val[s[i]-'a']);
    if(l==mn)l=0,mn=1e9,c++;
    else if(l>mn)l=1,mn=val[s[i]-'a'],c++;
}
if(l<mn && l)c++;

for(int i=0; i<n; i++){

        st.insert({val[s[i]-'a'],i});
  int mnv=st.begin()->F;

    while(mnv<st.size() && st.size()>0){
            int ind=i-st.size()+1;
        st.erase({val[s[ind]-'a'],ind});
    mnv=st.begin()->F;
    }

    mxlen=max(mxlen,(int)st.size());
}

cout<<cont(0,1,val[s[0]-'a'])%(ll)(1e9+7)<<endl;
cout<<mxlen<<endl<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define Sz(s) int((s).size())
#define Fill(s,v) memset(s,v,sizeof(s))
#define f(i,n) for (int i=0; i<n; i++)
#define f1(i,n) for (int i=1; i<=n; i++)
#define fI(i,a,b) for (int i=a; i<=b; i++)
int n;
string s;
int val[27];
int mxlen=0,mnp=1e9;
ll mem[1003][1003];

ll cont(int i,int l,int mn){
    mxlen=max(mxlen,l);
if(i==n-1){
        return 1;
}

ll &ans=mem[i][l];
if(ans!=-1)return ans;
ans=0;
ans+=cont(i+1,1,val[s[i+1]-'a']);
if(min(mn,val[s[i+1]-'a'])>l)ans+=cont(i+1,l+1,min(mn,val[s[i+1]-'a']));
return ans;
}

int main()
{
  memset(mem,-1,sizeof mem);
cin>>n>>s;
f(i,26)cin>>val[i];

int l=0,mn=1e9,c=1;
for(int i=0; i<n; i++){
    l++; mn=min(mn,val[s[i]-'a']);
    if(l==mn)l=0,mn=1e9,c++;
    else if(l>mn)l=1,mn=val[s[i]-'a'],c++;
}

cout<<cont(0,1,val[s[0]-'a'])<<endl;
cout<<mxlen<<endl<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define Sz(s) int((s).size())
#define Fill(s,v) memset(s,v,sizeof(s))
#define f(i,n) for (int i=0; i<n; i++)
#define f1(i,n) for (int i=1; i<=n; i++)
#define fI(i,a,b) for (int i=a; i<=b; i++)
int n;
string s;
int val[27];
int mxlen=0,mnp=1e9;
ll mem[1003][1003];

ll cont(int i,int l,int mn){
if(i==n-1){
        return 1;
}

ll &ans=mem[i][l];
if(ans!=-1)return ans;
ans=0;
ans+=cont(i+1,1,val[s[i+1]-'a']);
if(min(mn,val[s[i+1]-'a'])>l)ans+=cont(i+1,l+1,min(mn,val[s[i+1]-'a']));
return ans;
}

set<pair<int,int> > st;

int main()
{
  memset(mem,-1,sizeof mem);
cin>>n>>s;
f(i,26)cin>>val[i];

int l=0,mn=1e9,c=0;
for(int i=0; i<n; i++){
    l++; mn=min(mn,val[s[i]-'a']);
    if(l==mn)l=0,mn=1e9,c++;
    else if(l>mn)l=1,mn=val[s[i]-'a'],c++;
}
if(l<mn && l)c++;

for(int i=0; i<n; i++){

        st.insert({val[s[i]-'a'],i});
  int mnv=st.begin()->F;

    while(mnv<st.size() && st.size()>0){
            int ind=i-st.size()+1;
        st.erase({val[s[ind]-'a'],ind});
    mnv=st.begin()->F;
    }

    mxlen=max(mxlen,(int)st.size());
}

cout<<cont(0,1,val[s[0]-'a'])<<endl;
cout<<mxlen<<endl<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1009
#define ll long long

ll const mod = 1000000007;
const int inf = 99999999;

void pre_process();
ll fn_cnt(int i);
int fn(int i, int mode);
int check(int s, int e);

char arr[MAX];
int sum[30][MAX], con[30];
int dp[MAX][2], n;
ll dp_cnt[MAX];

int main()
{
    scanf("%d", &n);
    scanf("%s", arr);

    for(int i = 0; i < 26; i++)
        scanf("%d", &con[i]);

    pre_process();

    //  printf("vvc %d\n",check(2,3));

    int small = fn(0, 0);
    int big = fn(0, 1);
    ll cnt = fn_cnt(0);

    printf("%lld\n%d\n%d\n", cnt, big, small);

    return 0;
}

void pre_process()
{
    memset(sum, 0, sizeof(sum));
    memset(dp, -1, sizeof(dp));
    memset(dp_cnt, -1, sizeof(dp_cnt));

    ///shift
    for(int j = 0; j < 26; j++)
        for(int i = 0; i < n; i++)
            sum[j][i + 1] = sum[j][i - 1 + 1] += (arr[i] == ('a' + j));

}

ll fn_cnt(int i)
{
    if(i == n)
        return 1;

    ll &ret = dp_cnt[i];
    if(ret != -1)
        return ret;

    ///0 min
    ret = 0;

    for(int j = i + 1; j <= n; j++)
        if(check(i, j))
            ret += fn_cnt(j), ret %= mod;

    return ret;
}

int fn(int i, int mode)
{
    if(i == n)
        return 0;

    int &ret = dp[i][mode];
    if(ret != -1)
        return ret;

    ///0 min
    ret = mode == 0 ? inf : -inf;

    for(int j = i + 1; j <= n; j++)
    {
        if(check(i, j))
        {
            if(mode == 0)
                ret = min(ret, min(ret, fn(j, mode) + 1));
            else
            {
                if(fn(j, mode) != -inf)
                    ret = max(ret, max(fn(j, mode), (j - i)));
            }
        }
    }

    return ret;
}

int check(int s, int e)
{
    for(int i = 0; i < 26; i++)
    {
        if(e - s > con[i] && sum[i][e - 1 + 1] - sum[i][s - 1 + 1])
            return 0;
    }

    return 1;
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1009
#define ll long long

ll const mod = 1000000007;
const int inf = 9999999;

void pre_process();
ll fn_cnt(int i);
int fn(int i, int mode);
int check(int s, int e);

char arr[MAX];
int sum[30][MAX], con[30];
int dp[MAX][2], n;
ll dp_cnt[MAX];

int main()
{
    scanf("%d", &n);
    scanf("%s", arr);

    for(int i = 0; i < 26; i++)
        scanf("%d", &con[i]);

    pre_process();

    //  printf("vvc %d\n",check(2,3));

    int small = fn(0, 0);
    int big = fn(0, 1);
    ll cnt = fn_cnt(0);

    printf("%lld\n%d\n%d\n", cnt, big, small);

    return 0;
}

void pre_process()
{
    memset(sum, 0, sizeof(sum));
    memset(dp, -1, sizeof(dp));
    memset(dp_cnt, -1, sizeof(dp_cnt));

    ///shift
    for(int j = 0; j < 26; j++)
    {
        for(int i = 0; i < n; i++)
            sum[j][i + 1] = sum[j][i - 1 + 1] += (arr[i] == ('a' + j));

        int i = n;
        sum[j][i + 1] = sum[j][i - 1 + 1];

    }

}

ll fn_cnt(int i)
{
    if(i == n)
        return 1;

    ll &ret = dp_cnt[i];
    if(ret != -1)
        return ret;

    ret = 0;

    for(int j = i + 1; j <= n; j++)
        if(check(i, j))
            ret += fn_cnt(j), ret %= mod;

    return ret;
}

int fn(int i, int mode)
{
    if(i == n)
        return 0;

    int &ret = dp[i][mode];
    if(ret != -1)
        return ret;

    ///0 min
    ret = mode == 0 ? inf : -inf;

    for(int j = i + 1; j <= n; j++)
    {
        if(check(i, j))
        {
            if(mode == 0)
                ret = min(ret, fn(j, mode) + 1);
            else
            {
                if(fn(j, mode) != -inf)
                    ret = max(ret, max(fn(j, mode), (j - i)));
            }
        }
    }

    return ret;
}

int check(int s, int e)
{
    for(int i = 0; i < 26; i++)
    {
        if(e - s > con[i] && sum[i][e - 1 + 1] - sum[i][s - 1 + 1])
            return 0;
    }

    return 1;
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1009
#define ll long long

ll const mod = (ll)1000000007;
const int inf = 9999999;

void pre_process();
ll fn_cnt(int i);
int fn(int i, int mode);
int check(int s, int e);

char arr[MAX];
int sum[30][MAX], con[30];
int dp[MAX][2], n;
ll dp_cnt[MAX];

int main()
{
    scanf("%d", &n);
    scanf("%s", arr);

    for(int i = 0; i < 26; i++)
        scanf("%d", &con[i]);

    pre_process();
    /* for(int j = 0; j < 26; j++)
     {
         for(int i = 0; i <= n; i++)
             printf("%d ", sum[j][i]);

         printf("\n");

     }
     */
    //  printf("vvc %d\n",check(2,3));

    int small = fn(0, 0);
    int big = fn(0, 1);
    ll cnt = fn_cnt(0);

    printf("%lld\n%d\n%d\n", cnt, big, small);

    return 0;
}

void pre_process()
{
    memset(sum, 0, sizeof(sum));
    memset(dp, -1, sizeof(dp));
    memset(dp_cnt, -1, sizeof(dp_cnt));

    for(int j = 0; j < 26; j++)
    {
        for(int i = 0; i < n; i++)
            sum[j][i + 1] = sum[j][i - 1 + 1] + (arr[i] == ('a' + j));

        int i = n;
        sum[j][i + 1] = sum[j][i - 1 + 1];

    }

}

ll fn_cnt(int i)
{
    if(i == n)
        return 1;

    ll &ret = dp_cnt[i];
    if(ret != -1)
        return ret;

    ret = 0;

    for(int j = i + 1; j <= n; j++)
        if(check(i, j))
            ret += fn_cnt(j), ret = ret % mod;

    return ret;
}

int fn(int i, int mode)
{
    if(i == n)
        return 0;

    int &ret = dp[i][mode];
    if(ret != -1)
        return ret;

    ///0 min
    ret = mode == 0 ? inf : -inf;

    for(int j = i + 1; j <= n; j++)
    {
        if(check(i, j))
        {
            if(mode == 0)
                ret = min(ret, fn(j, mode) + 1);
            else
            {
                if(fn(j, mode) != -inf)
                    ret = max(ret, max(fn(j, mode), (j - i)));
            }
        }
    }

    return ret;
}

int check(int s, int e)
{
    for(int i = 0; i < 26; i++)
    {
        if(e - s > con[i] && sum[i][e - 1 + 1] - sum[i][s - 1 + 1])
            return 0;
    }

    return 1;
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1009
#define ll long long

ll const mod = 1000000007;
const int inf = 999999999;

void pre_process();
ll fn_cnt(int i);
int fn(int i, int mode);
int check(int s, int e);

char arr[MAX];
int sum[30][MAX], con[30];
int dp[MAX][2], n;
ll dp_cnt[MAX];

int main()
{
    scanf("%d", &n);
    scanf("%s", arr);

    for(int i = 0; i < 26; i++)
        scanf("%d", &con[i]);

    pre_process();

    //  printf("vvc %d\n",check(2,3));

    int small = fn(0, 0);
    int big = fn(0, 1);
    ll cnt = fn_cnt(0);

    printf("%lld\n%d\n%d\n", cnt, big, small);

    return 0;
}

void pre_process()
{
    memset(sum, 0, sizeof(sum));
    memset(dp, -1, sizeof(dp));
    memset(dp_cnt, -1, sizeof(dp_cnt));

    ///shift
    for(int j = 0; j < 26; j++)
        for(int i = 0; i < n; i++)
            sum[j][i + 1] = sum[j][i] += arr[i] == ('a' + j);

}

ll fn_cnt(int i)
{
    if(i == n)
        return 1;

    ll &ret = dp_cnt[i];
    if(ret != -1)
        return ret;

    ///0 min
    ret = 0;

    for(int j = i + 1; j <= n; j++)
        if(check(i, j))
            ret += fn_cnt(j), ret %= mod;

    return ret;
}

int fn(int i, int mode)
{
    if(i == n)
        return 0;

    int &ret = dp[i][mode];
    if(ret != -1)
        return ret;

    ///0 min
    ret = mode == 0 ? inf : -inf;

    for(int j = i + 1; j <= n; j++)
    {
        if(check(i, j) && fn_cnt(j))
        {
            if(mode==0)
                ret=min(ret,min(ret, fn(j, mode) + 1));
            else
                ret=max(ret,max(fn(j, mode),(j-i)));
        }
    }

    return ret;
}

int check(int s, int e)
{
    for(int i = 0; i < 26; i++)
    {
        if(e - s > con[i] && sum[i][e + 1] - sum[i][s - 1 + 1])
            return 0;
    }

    return 1;
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1009
#define ll long long

ll const mod = 1000000007;
const int inf = 999999999;

void pre_process();
ll fn_cnt(int i);
int fn(int i, int mode);
int check(int s, int e);

char arr[MAX];
int sum[30][MAX], con[30];
int dp[MAX][2], n;
ll dp_cnt[MAX];

int main()
{
    scanf("%d", &n);
    scanf("%s", arr);

    for(int i = 0; i < 26; i++)
        scanf("%d", &con[i]);

    pre_process();

    //  printf("vvc %d\n",check(2,3));

    int small = fn(0, 0);
    int big = fn(0, 1);
    ll cnt = fn_cnt(0);

    printf("%lld\n%d\n%d\n", cnt, big, small);

    return 0;
}

void pre_process()
{
    memset(sum, 0, sizeof(sum));
    memset(dp, -1, sizeof(dp));
    memset(dp_cnt, -1, sizeof(dp_cnt));

    ///shift
    for(int j = 0; j < 26; j++)
        for(int i = 0; i < n; i++)
            sum[j][i + 1] = sum[j][i] += arr[i] == ('a' + j);

}

ll fn_cnt(int i)
{
    if(i == n)
        return 1;

    ll &ret = dp_cnt[i];
    if(ret != -1)
        return ret;

    ///0 min
    ret = 0;

    for(int j = i + 1; j <= n; j++)
        if(check(i, j))
            ret += fn_cnt(j), ret %= mod;

    return ret;
}

int fn(int i, int mode)
{
    if(i == n)
        return 0;

    int &ret = dp[i][mode];
    if(ret != -1)
        return ret;

    ///0 min
    ret = mode == 0 ? inf : -inf;

    for(int j = i + 1; j <= n; j++)
    {
        if(check(i, j))
        {
            if(mode == 0)
                ret = min(ret, min(ret, fn(j, mode) + 1));
            else
            {
                if(fn(j, mode) != -inf)
                    ret = max(ret, max(fn(j, mode), (j - i)));
            }
        }
    }

    return ret;
}

int check(int s, int e)
{
    for(int i = 0; i < 26; i++)
    {
        if(e - s > con[i] && sum[i][e + 1] - sum[i][s - 1 + 1])
            return 0;
    }

    return 1;
}