from collections import defaultdict def main(): S_counts = list(map(int, input().split())) T = input().strip() # Process T into runs R_T = [] prev_char = None for c in T: if c != prev_char: R_T.append(c) prev_char = c # Count frequency of each character in R_T freq = defaultdict(int) for c in R_T: freq[c] += 1 # Check if any character's frequency exceeds S's count for c in freq: idx = ord(c) - ord('a') if freq[c] > S_counts[idx]: print(0) return # Calculate the product product = 1 for c in freq: idx = ord(c) - ord('a') m = freq[c] s = S_counts[idx] q, r = divmod(s, m) term = ( (q + 1) ** r ) * ( q ** (m - r) ) product *= term if product >= (1 << 62): print("hel") return print(product) if __name__ == "__main__": main()