MOD = 10**6 + 3 def compress(s): if not s: return [] res = [s[0]] for c in s[1:]: if c != res[-1]: res.append(c) return res # Read input S_counts = list(map(int, input().split())) T = input().strip() ct = compress(T) if not ct: print(0) exit() from collections import defaultdict m = defaultdict(int) for c in ct: m[c] += 1 # Check if all required characters have at least the necessary count valid = True for c in m: idx = ord(c) - ord('a') if S_counts[idx] < m[c]: valid = False break if not valid: print(0) exit() # Calculate the product count = defaultdict(int) result = 1 for c in ct: alpha = c idx = ord(alpha) - ord('a') m_alpha = m[alpha] R = S_counts[idx] - m_alpha base = R // m_alpha rem = R % m_alpha current_count = count[alpha] + 1 count[alpha] = current_count add = 1 if current_count <= rem else 0 current_val = 1 + base + add result = (result * current_val) % MOD print(result)