import sys from collections import defaultdict def main(): S_alpha = list(map(int, sys.stdin.readline().split())) T = sys.stdin.readline().strip() if not T: print(0) return # Split T into runs runs = [T[0]] for c in T[1:]: if c != runs[-1]: runs.append(c) # Count occurrences of each character in runs m_c = defaultdict(int) for c in runs: m_c[c] += 1 # Check if each character in runs has sufficient count for c in m_c: idx = ord(c) - ord('a') if S_alpha[idx] < m_c[c]: print(0) return product = 1 threshold = (1 << 62) for c in m_c: idx = ord(c) - ord('a') s_total = S_alpha[idx] m = m_c[c] s_remaining = s_total - m if s_remaining < 0: print(0) return q, r = divmod(s_remaining, m) term = pow(q + 2, r) * pow(q + 1, m - r) product *= term if product >= threshold: print("hel") return print("hel" if product >= threshold else product) if __name__ == "__main__": main()