import sys from collections import defaultdict def main(): # Read the 26 S_alpha values s_alpha = list(map(int, sys.stdin.readline().split())) # Read T T = sys.stdin.readline().strip() # Process T to get the run sequence R R = [] prev = None for c in T: if c != prev: R.append(c) prev = c K = len(R) # For each character in R, collect the indices of their occurrences indices = defaultdict(list) for i, c in enumerate(R): indices[c].append(i) # Initialize the list to hold the length of each run in S l = [0] * K # Process each character's runs for c in indices: m_c = len(indices[c]) # Get the available count for this character in S sa = s_alpha[ord(c) - ord('a')] if sa < m_c: print(0) return s_c = sa q = s_c // m_c r = s_c % m_c # Assign q+1 to the first r positions, q to the rest for idx in indices[c][:r]: l[idx] = q + 1 for idx in indices[c][r:]: l[idx] = q # Compute the product of all run lengths mod = 2 ** 62 product = 1 for run_length in l: product *= run_length if product >= mod: print("hel") return print(product) if __name__ == "__main__": main()