import sys from functools import lru_cache import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 2**62 S = tuple(map(int, readline().split())) T = tuple(x - ord('a') for x in read().rstrip()) L = [[] for _ in range(26)] last_ch = -1 last_len = 0 for x in T: if x != last_ch: L[x].append(1) else: L[x][-1] += 1 last_ch = x def check_zero(S, L): for a in range(26): # if S[a] > 0 and (not L[a]): # return True if S[a] < sum(L[a]): return True if check_zero(S, L): print(0) @lru_cache(None) def comb(n, k): if k < 0 or k > n: return 0 k = min(k, n - k) x = 1 for i in range(k): x *= (n - i) x //= (i + 1) if x >= INF: return INF return x def compute(n, nums): if not nums: return 1 n -= sum(nums) if not n: return 1 nums.sort(reverse=True) nums = nums[:70] if sum(nums) >= 6 and n > 10**4: return INF if n <= 10**4: A = nums[:] for _ in range(n): # 1 増やすと美味しいところを増やす i = max(range(len(nums)), key=lambda i: (A[i] + 1) / (A[i] - nums[i] + 1)) A[i] += 1 x = 1 for a, k in zip(A, nums): x *= comb(a, k) return x # n が大きくて、kは2種類 # 基本的には、同じくらいの大きさにすればよいので ret = 1 n += sum(nums) avg = n // len(nums) for p in itertools.product(range(avg - 4, avg + 5), repeat=len(nums)): if sum(p) != n: continue x = 1 for a, k in zip(p, nums): x *= comb(a, k) if ret < x: ret = x return ret x = 1 for n, nums in zip(S, L): x *= compute(n, nums) if x >= INF: x = 'hel' print(x)