Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.

Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.

A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.

While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:   How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7.  What is the maximum length of a substring that can appear in some valid splitting?  What is the minimum number of substrings the message can be spit in? 

Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".


-----Input-----

The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.

The second line contains the message s of length n that consists of lowercase English letters.

The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.


-----Output-----

Print three lines.

In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9  +  7.

In the second line print the length of the longest substring over all the ways.

In the third line print the minimum number of substrings over all the ways.


-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output
3
2
2

Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output
401
4
3



-----Note-----

In the first example the three ways to split the message are:   a|a|b  aa|b  a|ab 

The longest substrings are "aa" and "ab" of length 2.

The minimum number of substrings is 2 in "a|ab" or "aa|b".

Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2.

Difficulty: interview

Starter code:

Solutions:
read = lambda: map(int, input().split())
n = int(input())
s = input()
a = list(read())
dp = [0] * (n + 2)
mn = [10 ** 4] * (n + 2)
dp[0] = dp[n + 1] = 1
mn[n + 1] = 0
mn[0] = 1
Max = 1
mod = 10 ** 9 + 7
for i in range(1, n):
    res = 0
    cur = 10 ** 4
    for j in range(i, -1, -1):
        c = ord(s[j]) - ord('a')
        cur = min(cur, a[c])
        if cur < (i - j + 1):
            break
        dp[i] = (dp[i] + dp[j - 1]) % mod
        mn[i] = min(mn[i], mn[j - 1] + 1)
        Max = max(Max, i - j + 1)
print(dp[n - 1])
print(Max)
print(mn[n - 1])

n = int(input())
s = input()
S = [ord(znak) - 97 for znak in s]
a = list(map(int, input().strip().split(' ')))
#print(n, S, a)

MOD = 10**9 + 7

st = [0]*(n+1)
st[0] = 1
maks = [0]*(n+1)
minway = [10**4]*(n+1)
minway[0] = 0
for i in range(1, n + 1):
    cnt = 0
    maks_dolzina = n
    for j in range(i, 0, -1):
        maks_dolzina = min(maks_dolzina, a[S[j - 1]])
        if i - j + 1 > maks_dolzina:
            break
        cnt += st[j-1]
        maks[i] = max(i-j+1, maks[j-1], maks[i])
        minway[i] = min(minway[i], 1 + minway[j-1])
    st[i] = cnt

print(st[-1] % MOD)
print(maks[-1])
print(minway[-1])



n = int(input())
s = list(input())
abc = 'abcdefghijklmnopqrstuvwxyz'
limit = list(map(int, input().split()))
mod = int(1e9) + 7
memo = [None] * n


def main():
    num_ways, longest, min_num = split(0)
    print(num_ways)
    print(longest)
    print(min_num)


def split(start):
    if start >= len(s):
        return 1, 0, 0

    if memo[start] is not None:
        return memo[start]

    num_ways = 0
    longest = 0
    min_num = 1e5

    max_allowed = 1e5

    for i in range(start, len(s)):
        current_length = i - start + 1
        max_allowed = min(max_allowed, limit[abc.find(s[i])])
        if current_length > max_allowed:
            break

        longest = max(current_length, longest)
        ss_num_ways, ss_longest, ss_min_num = split(i+1)
        num_ways = (num_ways + ss_num_ways) % mod
        longest = max(longest, ss_longest)
        min_num = min(min_num, ss_min_num+1)

    memo[start] = num_ways, longest, min_num
    return memo[start]

def __starting_point():
    main()

__starting_point()

#!/bin/python3
import sys
mod = 10 **9 + 7
n = int(input())
s = input()
cnt = list(map(int, input().split()))
dp = [0]
for i in range(0,n):
    dp.append(0)
dp[0] = 1
ans2 = 1
for i in range(1,n + 1):
    o = i -1
    ml = cnt[ord(s[o]) - ord('a')]
    l = 1
    while ml >= l and o >= 0:
        dp[i] += dp[o] 
        dp[i] = dp[i] % mod
        if l > ans2:
            ans2 = l
        l += 1
        o -= 1
        ml = min(ml, cnt[ord(s[o]) - ord('a')])
ans1 = dp[n] % mod
ans3 = 0
ml = n
l = 0
for i in range(n):
    ml = min(ml,cnt[ord(s[i]) - ord('a')])
    l+=1
    if l > ml:
        ans3+=1
        l = 1
        ml = cnt[ord(s[i]) - ord('a')]
ans3 += 1
print(ans1)
print(ans2)
print(ans3)

#!/usr/bin/env python3
def ri():
    return list(map(int, input().split()))


n = int(input())
s = input()
s = [ord(x) - ord('a') for x in s]
a = list(ri())

T = [0 for i in range(n)]

maxs = 0
mins = 0
lasts = 0
for i in range(len(s)):
    if i == 0:
        maxs = 1
        T[i] = 1
        mins +=1
        continue
    mm = i
    smin = 10**9
    for j in range(i, max(i-a[s[i]], -1), -1):
        length = i-j+1
        flag = 0
        smin = min(a[s[j]], smin)
        if smin < length:
                break
        else:
            mm = j
            if j == 0:
                adding = 1
            else:
                adding = T[j-1]
            T[i] += adding
            T[i] = T[i]%(10**9 + 7)
    maxs = max(maxs, i-mm+1)
    if mm > lasts:
        mins+=1
        lasts = i

print(T[n-1])
print(maxs)
print(mins)







import sys
mod = pow(10, 9) + 7

n = int(sys.stdin.readline())
s = sys.stdin.readline()[:-1]
a = [int(x) for x in sys.stdin.readline().split()]

dp = [0 for _ in range(n+1)]
dp[0] = 1


def ci(c):
    return ord(c)-ord('a')


l = 0
for i in range(1, n+1):
    # f: represents the farther
    # we can get from x (going from
    # right to left) without breaking
    # the splitting rules
    f = 0
    for x in range(i-1, -1, -1):
        f = max(f, i-a[ci(s[x])])
        if f > x:
            # we broke the rule
            continue
        dp[i] = (dp[i]+dp[x]) % mod
        l = max(l, i-x)

print(dp[n])
print(l)

res = 1
m = 9999
j = 0
for i in range(n):
    m = min([a[ci(s[x])] for x in range(j, i+1)])
    if m < i-j+1:
        res += 1
        j = i
print(res)


import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def get_minsp(message, As):
    min_sp = 0
    max_len = 0
    cur_len = 0
    capa = 0

    for ch in message:
        index = ord(ch) - ord('a')

        if cur_len == 0:
            cur_len += 1
            max_len = 1
            capa = As[index]
        else:
            capa = min(capa, As[index])

            if cur_len + 1 <= capa:
                cur_len += 1
                max_len = max(max_len, cur_len)
            else:
                min_sp += 1
                cur_len = 1
                capa = As[index]

    return max_len, min_sp + 1

def solve():
    MOD = 10**9 + 7
    n = int(input())
    message = input()
    As = [int(i) for i in input().split()]

    capas = []

    for ch in message:
        i = ord(ch) - ord('a')
        capas.append(As[i])

    deq = deque()
    cur_len = 0
    max_len = 0
    min_sp = 0
    capa = 0

    for i, capa in enumerate(capas):
        if not deq:
            deq.append(1)
            cur_len = 1
            max_len = 1
        else:
            limit = capa
            lim_len = capa

            for j in range(1, min(i + 1, capa)):
                if min(limit, capas[i - j]) < j + 1:
                    lim_len = j
                    break
                limit = min(limit, capas[i - j])
            else:
                lim_len = min(i + 1, capa)

            if cur_len + 1 <= lim_len:
                cur_len += 1
                max_len = max(cur_len, max_len)
                deq.appendleft(sum(deq) % MOD)
            else:
                deq.appendleft(sum(deq) % MOD)
                num_del = cur_len - (lim_len - 1)

                for i in range(num_del):
                    deq.pop()

                cur_len = lim_len

        # debug(deq, locals())
        # debug(cur_len, locals())

    _, min_sp = get_minsp(message, As)

    print(sum(deq) % MOD)
    print(max_len)
    print(min_sp)




def __starting_point():
    solve()
__starting_point()

import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def get_minsp(message, As):
    min_sp = 1
    cur_len = 0
    capa = 0

    for ch in message:
        index = ord(ch) - ord('a')

        if cur_len == 0:
            cur_len += 1
            capa = As[index]
        else:
            capa = min(capa, As[index])

            if cur_len + 1 <= capa:
                cur_len += 1
            else:
                min_sp += 1
                cur_len = 1
                capa = As[index]

    return min_sp

def solve():
    MOD = 10**9 + 7
    n = int(input())
    message = input()
    As = [int(i) for i in input().split()]

    capas = []

    for ch in message:
        i = ord(ch) - ord('a')
        capas.append(As[i])

    deq = deque()
    cur_len = 0
    max_len = 0
    min_sp = 0
    capa = 0

    for i, capa in enumerate(capas):
        if not deq:
            deq.append(1)
            cur_len = 1
            max_len = 1
        else:
            limit = capa
            lim_len = capa

            for j in range(1, min(i + 1, capa)):
                if min(limit, capas[i - j]) < j + 1:
                    lim_len = j
                    break
                limit = min(limit, capas[i - j])
            else:
                lim_len = min(i + 1, capa)

            deq.appendleft(sum(deq) % MOD)

            if cur_len + 1 <= lim_len:
                cur_len += 1
                max_len = max(cur_len, max_len)
            else:
                num_del = cur_len + 1 - lim_len

                for j in range(num_del):
                    deq.pop()

                cur_len = lim_len

    min_sp = get_minsp(message, As)

    print(sum(deq) % MOD)
    print(max_len)
    print(min_sp)

def __starting_point():
    solve()
__starting_point()

read = lambda: map(int, input().split())
n = int(input())
s = input()
a = list(read())
dp = [0] * (n + 2)
mn = [10 ** 4] * (n + 2)
dp[0] = dp[n + 1] = 1
mn[n + 1] = 0
mn[0] = 1
Max = 1
mod = 10 ** 9 + 7
for i in range(1, n):
    res = 0
    cur = 10 ** 4
    for j in range(i, -1, -1):
        c = ord(s[j]) - ord('a')
        cur = min(cur, a[c])
        if cur < (i - j + 1):
            break
        dp[i] = (dp[i] + dp[j - 1]) % mod
        mn[i] = min(mn[i], mn[j - 1] + 1)
        Max = max(Max, i - j + 1)
print(dp[n - 1])
print(Max)
print(mn[n - 1])

import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def get_minsp(message, As):
    min_sp = 1
    cur_len = 0
    capa = 0

    for ch in message:
        index = ord(ch) - ord('a')

        if cur_len == 0:
            cur_len += 1
            capa = As[index]
        else:
            capa = min(capa, As[index])

            if cur_len + 1 <= capa:
                cur_len += 1
            else:
                min_sp += 1
                cur_len = 1
                capa = As[index]

    return min_sp

def solve():
    MOD = 10**9 + 7
    n = int(input())
    msg = input()
    As = [int(i) for i in input().split()]
    caps = []

    for ch in msg:
        idx = ord(ch) - ord('a')
        caps.append(As[idx])

    dp = [0] * (n + 1)
    dp[0] = 1
    max_len = 0
    lim = 0

    for i in range(1, n + 1):
        lim = caps[i - 1]
        cur_len = 1
        for j in range(i - 1, -1, -1):
            if cur_len > lim:
                break

            max_len = max(max_len, cur_len)
            dp[i] += dp[j]
            dp[i] %= MOD
            lim = min(lim, caps[j - 1])
            cur_len += 1

    min_sp = get_minsp(msg, As)

    # debug(dp, locals())
    print(dp[n])
    print(max_len)
    print(min_sp)



def __starting_point():
    solve()
__starting_point()


cin=lambda: list(map(int,input().split()))
n=int(input())
st=input()
a=list(cin())
dp=[0]*(n+2)
mn=[10**4]*(n+2)
mx=1
dp[0]=1
dp[-1]=1
mn[0]=1
mn[-1]=0
mod=int(1e9)+7

for i in range(1,n):
    c=10**4
    for j in range(i,-1,-1):
        ind=ord(st[j])-ord('a')
        c=min(c,a[ind])
        if c<i-j+1:break
        dp[i] += dp[j-1]
        mn[i] = min(mn[i],mn[j-1]+1)
        mx=max(mx,i-j+1)    

print('\n'.join(map(str,[dp[n-1]%mod,mx,mn[n-1]])))


N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
	tmp = 0
	for i in range(len(arr)):
		arr[i][1] = min(arr[i][1],l[c])
		if i + 1 >= arr[i][1]:
			arr = arr[:i]
			if(t > i):
				t = 0
				mi += 1
			break
		else:
			tmp += arr[i][0]
	t += 1
	arr.insert(0, [total, l[c]])
	ma = max(ma, len(arr))
	total += tmp
	total %= 10 ** 9 + 7;
print(total)
print(ma)
print(mi)



M = 1000000007

n = int(input())
s = input()
a = list(map(int, input().split()))

ans2 = 0
dp = [0] * n + [1]
for i in range(n):
    maxlen = 9001
    for j in range(1, i+2):
        maxlen = min(maxlen, a[ord(s[i-j+1]) - ord('a')])
        if maxlen >= j:
            dp[i] = (dp[i] + dp[i-j]) % M
        else:
            break
        ans2 = max(ans2, j)


print(dp[n-1])
print(ans2)

ans3 = 1
acc = 0
maxlen = 9001
for i in range(n):
    acc += 1
    maxlen = min(maxlen, a[ord(s[i]) - ord('a')])
    if acc > maxlen:
        acc = 1
        ans3 += 1
        maxlen = a[ord(s[i]) - ord('a')]

print(ans3)


M = 10 ** 9 + 7

def o(i):
	return ord(s[i]) - 97

n = int(input())
s = input()
a = [int(item) for item in input().split()]

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
mn = float("inf")
longest = -float("inf")
maxNb = 1
ii = 1
tmp = a[o(0)]
if a[o(0)] == 1 and n != 1:
	maxNb += 1
	tmp = float("inf")
	ii = 0
if n == 1:
	longest = 1

for i in range(2, n + 1):
	ii += 1
	j = 0
	mn = a[o(i - 1)]
	k = -1
	while j <= i and j <= mn:
		mn = min(mn, a[o(i - j - 1)])
		dp[i] += dp[i - j] % M
		j += 1
		k += 1
	dp[i] %= M
	longest = max(longest, k)
	tmp = min(tmp, a[o(i - 1)])
	#print(tmp, i, ii)
	if i == n:break
	if tmp == ii:
		ii = 0
		tmp = float("inf")
		maxNb += 1
		#print(s[:i])

	elif tmp < ii:
		ii = 1
		maxNb += 1
		tmp = a[o(i - 1)]
		if i == n - 1:maxNb += 1
		#print(s[:i - 1])
	
	elif i == n - 1:
		if a[o(i)] < ii + 1:
			maxNb += 1
			#print(s[:i])
		

print(dp[n] % M)
print(longest)
print(maxNb)

n = int(input())
s = input()
alf = list(map(int, input().split()))
d = [0 for i in range(n + 1)]
div = int(10**9 + 7)
d[0] = 1
maxlen = -1
a = ord('a')
INF = int(10**10)
md = [INF for i in range(n + 1)]
md[0] = 0
for i in range(1,n + 1):
    l = alf[ord(s[i - 1]) - a]
    minlen = l
    for j in range(l):
        if i - j < 1:
            break
        minlen = min(minlen, alf[ord(s[i - j - 1]) - a])
        if minlen < j + 1:
            break
        maxlen = max(maxlen, j + 1)
        d[i] += d[i - j - 1] % div
        d[i] %= div
        md[i] = min(md[i], 1 + md[i - j - 1])
print(d[n])
print(maxlen)
print(md[n])


import sys

mod = 10**9 + 7
inf = 1<<30

def solve():
    n = int(input())
    msg = input()
    clim = [int(i) for i in input().split()]

    dp = [0]*(n + 1)
    dp[0] = 1
    max_len = 0

    for i in range(1, n + 1):
        limlen = inf
        cur_len = 0

        for j in range(i, 0, -1):
            alpha = ord(msg[j-1]) - ord('a')
            limlen = min(limlen, clim[alpha])
            cur_len += 1

            if cur_len > limlen:
                break

            max_len = max(max_len, cur_len)
            dp[i] = (dp[i] + dp[j - 1]) % mod

    min_sp = 0
    cur_len = 0
    limlen = inf

    for ch in msg:
        cur_len += 1
        alpha = ord(ch) - ord('a')
        limlen = min(limlen, clim[alpha])

        if cur_len > limlen:
            cur_len = 1
            min_sp += 1
            limlen = clim[alpha]

    print(dp[n])
    print(max_len)
    print(min_sp + 1)

def __starting_point():
    solve()
__starting_point()

import sys
import copy
import os

# sys.stdin = open(os.path.join(os.path.dirname(__file__), '2.in'))


def solve():
    MOD = int(1e9+7)

    f = 0
    n = int(input())

    s = input()

    alphabet ={ chr(ord('a')+i):num for i,num in enumerate( map(lambda x :int(x),input().split()) ) }
    dp =[0 for _ in range(n)]; minlen = 2<<20; maxlen=0
    minsplitnum =[2<<20 for _ in range(n)]

    def check(newstr,start,end):
        nl = end-start
        while start < end:
            if alphabet[newstr[start]] < nl:
                return False 
            start+=1
        # print(newstr)
        return True

    i = 0
    while i < n:
    # for i in range(n):
        if i == 0:
            dp[i] = 1
            maxlen = 1
            minsplitnum[i] = 1
        else:
            f = 0
            # divide the element to one
            dp[i] = (dp[i-1] + dp[i])%MOD 
            minsplitnum[i] = minsplitnum[i-1]+1 if minsplitnum[i] > minsplitnum[i-1]+1 else minsplitnum[i]
            # divide the element to before
            j = i-1
            f = i + 1 - alphabet[s[i]] if i + 1 - alphabet[s[i]] > f else f
            while j >= 0:
                # print('j',j)
                f = i + 1 - alphabet[s[j]] if i + 1 - alphabet[s[j]] > f else f
                if j >= f:
                    if j == 0:
                        dp[i] = (1 + dp[i])%MOD 
                    else:
                        dp[i] = (dp[j-1] + dp[i])%MOD 
                    maxlen = i-j+1 if i -j + 1 > maxlen else maxlen
                    if j == 0:
                        minsplitnum[i] = 1 if 1 < minsplitnum[i] else minsplitnum[i]
                    else:
                        minsplitnum[i] = minsplitnum[j-1]+1 if minsplitnum[j-1]+1 < minsplitnum[i] else minsplitnum[i]
                    j -= 1
                else:
                    j -= 1
                    continue
                
        i += 1
        # print(dp[i])
    print(int(dp[n-1]))
    print(maxlen)
    print(int(minsplitnum[n-1]))


solve()

import sys
import copy
import os

# sys.stdin = open(os.path.join(os.path.dirname(__file__), '2.in'))


def solve():
    MOD = int(1e9+7)

    f = 0
    n = int(input())

    s = input()

    alphabet ={ chr(ord('a')+i):num for i,num in enumerate( map(lambda x :int(x),input().split()) ) }
    dp =[0 for _ in range(n)]; minlen = 2<<20; maxlen=0
    minsplitnum =[2<<20 for _ in range(n)]

    def check(newstr,start,end):
        nl = end-start
        while start < end:
            if alphabet[newstr[start]] < nl:
                return False 
            start+=1
        # print(newstr)
        return True

    i = 0
    while i < n:
    # for i in range(n):
        if i == 0:
            dp[i] = 1
            maxlen = 1
            minsplitnum[i] = 1
        else:
            f = 0
            # divide the element to one
            dp[i] = (dp[i-1] + dp[i])%MOD 
            minsplitnum[i] = minsplitnum[i-1]+1 if minsplitnum[i] > minsplitnum[i-1]+1 else minsplitnum[i]
            # divide the element to before
            j = i-1
            f = i + 1 - alphabet[s[i]] if i + 1 - alphabet[s[i]] > f else f
            while j >= 0:
                # print('j',j)
                f = i + 1 - alphabet[s[j]] if i + 1 - alphabet[s[j]] > f else f
                if j >= f:
                    if j == 0:
                        dp[i] = (1 + dp[i])%MOD 
                    else:
                        dp[i] = (dp[j-1] + dp[i])%MOD 
                    maxlen = i-j+1 if i -j + 1 > maxlen else maxlen
                    if j == 0:
                        minsplitnum[i] = 1 if 1 < minsplitnum[i] else minsplitnum[i]
                    else:
                        minsplitnum[i] = minsplitnum[j-1]+1 if minsplitnum[j-1]+1 < minsplitnum[i] else minsplitnum[i]
                    j -= 1
                else:
                    j -= 1
                    continue
                
        i += 1
        # print(dp[i])
    print(int(dp[n-1]))
    print(maxlen)
    print(int(minsplitnum[n-1]))


solve()

n=int(input())
d=[0]*(n+1)
way=[n]*(n+1)
s='0'+input()
m=list(map(int,input().split()))
d[1]=1
d[0]=1
way[0]=0
way[1]=1
dic=dict()
dic['0']=1000
i=0
for l in 'abcdefghijklmnopqrstuvwxyz':
    dic[l]=m[i]
    i+=1
high=1
big=10**9+7
for i in range(2,n+1):
    z=i-1
    x=i-dic[s[i]]
    while z>=0 and x<=z:
        x = max(x, i-dic[s[z]])
        high = max(high, i - z)
        d[i] += d[z]
        way[i] = way[z] + 1
        z -= 1
    d[i]=d[i]%big
    z+=1
    if not z:
        high=i
print(d[-1])
print(high)
print(way[-1])

n=int(input())
d=[0]*(n+1)
way=[n]*(n+1)
s='0'+input()
m=list(map(int,input().split()))
d[1]=1
d[0]=1
way[0]=0
way[1]=1
dic=dict()
dic['0']=1000
i=0
for l in 'abcdefghijklmnopqrstuvwxyz':
    dic[l]=m[i]
    i+=1
high=1
big=10**9+7
for i in range(2,n+1):
    z=i-1
    x=i-dic[s[i]]
    while z>=0 and x<=z:
        x = max(x, i-dic[s[z]])
        high = max(high, i - z)
        d[i] += d[z]
        way[i] = way[z] + 1
        z -= 1
    d[i]=d[i]%big
    z+=1
    if not z:
        high=i
print(d[-1])
print(high)
print(way[-1])

N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
	tmp = 0
	for i in range(len(arr)):
		arr[i][1] = min(arr[i][1],l[c])
		if i + 1 >= arr[i][1]:
			arr = arr[:i]
			if(t > i):
				t = 0
				mi += 1
			break
		else:
			tmp += arr[i][0]
	t += 1
	arr.insert(0, [total, l[c]])
	ma = max(ma, len(arr))
	total += tmp
	total %= 10 ** 9 + 7;
print(total)
print(ma)
print(mi)





# Made By Mostafa_Khaled


n = int(input())
s = input()
ai = list(map(int, input().split()))
a = ord('a')
e = 10 ** 9 + 7

dp = [1] + [0] * n
dp2 = [0] * (n + 1)
l = 0

for i in range(1, n + 1):
    dp2[i] = n
    f = i - 1
    ma = 10000
    while f >= 0:
        ma = min(ma, ai[ord(s[f]) - a])
        if ma < i - f:
            break
        dp[i] = (dp[i] + dp[f]) % e
        dp2[i] = min(dp2[i], dp2[f] + 1)
        l = max(l, i - f)
        f -= 1
print(dp[n], l, dp2[n], sep = '\n')