import sys input = sys.stdin.readline from heapq import heappop,heappush A=list(map(int,input().split())) T=input().strip() T2=[ord(t)-97 for t in T] B=[0]*26 for t in T2: B[t]+=1 for i in range(26): if A[i]=0 and T2[i]==T2[i-1]: count+=1 else: if now!=-1: LIST[now].append(count) count=1 now=T2[i] if now!=-1: LIST[now].append(count) #print(LIST) def calc(L,k): rest=k-sum(L) Q=[] for x in L: heappush(Q,(-(x+1),x+1,1)) for i in range(rest): #print(Q) com,x,y=heappop(Q) ANS[0]=ANS[0]*x//y x+=1 y+=1 heappush(Q,(-x/y,x,y)) if ANS[0]>(2**62): print("hel") exit() ANS=[1] for i in range(26): if LIST[i]==[]: continue calc(LIST[i],A[i]) print(ANS[0])