MOD = 10**6 + 3 # Read input s_counts = list(map(int, input().split())) s = {chr(ord('a') + i): s_counts[i] for i in range(26)} T = input().strip() # Process T to get runs and count occurrences per character Run_T = [] prev_char = None for c in T: if c != prev_char: Run_T.append(c) prev_char = c from collections import defaultdict count_runs = defaultdict(int) for c in Run_T: count_runs[c] += 1 # Check if any character in T's runs has insufficient count in S for c, m in count_runs.items(): if s[c] < m: print(0) exit() result = 1 # Calculate contribution for each character in the runs for c, m in count_runs.items(): sc = s[c] k = sc - m # Remaining characters after accounting for minimum needed per run base = k // m rem = k % m a = (base + 2) % MOD b = (base + 1) % MOD # Compute (a^rem * b^(m - rem)) mod MOD term = (pow(a, rem, MOD) * pow(b, m - rem, MOD)) % MOD result = (result * term) % MOD print(result)