MOD = 10**6 + 3 # Read input s_alpha = list(map(int, input().split())) T = input().strip() # Handle empty T (though problem states T is at least length 1) if not T: print(0) exit() # Compress T by removing consecutive duplicates t_compressed = [T[0]] for c in T[1:]: if c != t_compressed[-1]: t_compressed.append(c) # Check each character in compressed T has at least 1 available for c in t_compressed: idx = ord(c) - ord('a') if s_alpha[idx] < 1: print(0) exit() # Count occurrences of each character in compressed T from collections import defaultdict char_counts = defaultdict(int) for c in t_compressed: char_counts[c] += 1 # Check if each character has enough total occurrences for its groups for c in char_counts: idx = ord(c) - ord('a') required = char_counts[c] if s_alpha[idx] < required: print(0) exit() # Calculate the product of contributions for each character result = 1 for c in char_counts: cnt = char_counts[c] idx = ord(c) - ord('a') s = s_alpha[idx] q, r = divmod(s, cnt) part1 = pow(q + 1, r, MOD) part2 = pow(q, cnt - r, MOD) contribution = (part1 * part2) % MOD result = (result * contribution) % MOD print(result)