*a, = map(int,input().split()) d = {} t = input()+"Z" cnt = 0 now = "A" for i in t: if i == now: cnt += 1 else: if now in d: d[now].append(cnt) else: d[now] = [cnt] now = i cnt = 1 V = [0]*26 from heapq import * for i,ai in enumerate(a): s = chr(i+97) if s not in d: continue v = ai - sum(d[s]) V[i] = v if v < 0: print(0) exit() def hel(ans): if ans >= MAX: print("hel") exit() ans = 1 MAX = 1<<62 for i,ai in enumerate(a): s = chr(i+97) if s not in d: continue v = V[i] if v==0: continue q = [(-(i+1.0),i,i) for i in d[s]] # 倍率、先頭、長さ if len(q) == 1: for i in range(q[0][-1]): ans *= ai-i ans //= i+1 hel(ans) continue if len(q) == 2 == sum(d[s]): x = ai//2 for aa in [x,ai-x]: ans *= aa hel(ans) continue #if (v//len(q)) > (MAX+10)**(1/len(q)): # hel(1<<64) if v > 64 and len(q) > 64: hel(1<<64) heapify(q) for _ in range(v): __,x,y = heappop(q) ans = ans*(y+1)//(y-x+1) heappush(q,(-(y+2)/(y+2-x),x,y+1)) hel(ans) print(ans)