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) if len(L)==1: x=L[0] c=k for i in range(x): ANS[0]=ANS[0]*c c-=1 c=1 for i in range(x): ANS[0]=ANS[0]//c c+=1 return if len(L)==2: MIN=0 MAX=rest while MAX-MIN>5: mid1=MIN+(MAX-MIN)//3 mid2=MIN+(MAX-MIN)//3*2 score=1 c=mid1+L[0] for i in range(L[0]): score=score*c c-=1 c=(rest-mid1)+L[1] for i in range(L[1]): score=score*c c-=1 score2=1 c=mid2+L[0] for i in range(L[0]): score2=score2*c c-=1 c=(rest-mid2)+L[1] for i in range(L[1]): score2=score2*c c-=1 if score>score2: MAX=mid2 else: MIN=mid1 ANSX=-1 for mid in range(MIN,MAX+1): score=1 c=mid+L[0] for i in range(L[0]): score=score*c c-=1 c=(rest-mid)+L[1] for i in range(L[1]): score=score*c c-=1 ANSX=max(score,ANSX) c=1 for i in range(L[0]): ANSX=ANSX//c c+=1 c=1 for i in range(L[1]): ANSX=ANSX//c c+=1 ANS[0]=ANS[0]*ANSX return if len(L)>=3 and k>=10**8: print("hel") exit() 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]) if ANS[0]>=(2**62): print("hel") exit() if ANS[0]>=(2**62): print("hel") else: print(ANS[0])