import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.readline().rstrip().encode() def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 # md = 998244353 md = 10**9+7 from heapq import * def RLE(s): cc=[] ww=[] pc=s[0] w=0 for c in s: if c==pc:w+=1 else: cc.append(pc) ww.append(w) w=1 pc=c cc.append(pc) ww.append(w) return cc,ww lim=1<<62 aa=LI() s=BI() cc,ll=RLE(s) cnt=[[] for _ in range(26)] for c,l in zip(cc,ll): cnt[c-97].append(l) # print(cnt) ans=1 for i,(a,cc) in enumerate(zip(aa,cnt)): if not cc:continue s=sum(cc) if a10000000 and sum(cc)>2: print("hel") exit() if sum(cc)==1: cur=a+1 elif sum(cc)==2: a += 2 if len(cc)==1: cur=a*(a-1)//2 else: cur=(a//2)*(a-a//2) else: hp=[] cur=1 for c in cc: heappush(hp,(-(c+1)/(c-c+1),c,c)) cur=1 for _ in range(a): m,n,r=heappop(hp) cur=round(-m*cur) heappush(hp,(-(n+2)/(n-r+2),n+1,r)) ans*=cur if ans>=lim: print("hel") exit() print(ans)