from collections import defaultdict import sys def solve(): input = sys.stdin.readline lim = 2 ** 62 pre_size = 500 bin_table = [[1]] for i in range(1, pre_size): t = [1] * (i + 1) p = bin_table[-1] for j in range(1, i): t[j] = min(lim, p[j - 1] + p[j]) bin_table += [t] def binom(n, k): assert(0 <= k and k <= n) if n < pre_size: return bin_table[n][k] ret = 1 for i in range(k): ret = ret * (n - i) // (i + 1) if ret >= lim: return lim return ret def estimate(rest, now, lens, cumu): n = len(lens) - now needed = lens[now] + cumu[now] q, r = divmod(rest - needed, n) ret = 1 for i in range(n): ret *= binom(lens[now + i] + q + (i < r), lens[now + i]) if ret >= lim: return lim return ret def rec(rest, now, lens, cumu, memo): if now + 1 == len(lens): return binom(rest, lens[now]) if not (rest, now) in memo: ret = estimate(rest, now, lens, cumu) if ret < lim: for i in range(rest - cumu[now], lens[now] - 1, -1): cnt = binom(i, lens[now]) if cnt >= lim: ret = lim break cnt *= rec(rest - i, now + 1, lens, cumu, memo) if cnt >= lim: ret = lim break ret = max(ret, cnt) memo[rest, now] = ret return memo[rest, now] for line in sys.stdin: counts = map(int, line.split()) st = input().rstrip() freqs = [0] * 26 lens = [[] for i in range(26)] i = 0 while i < len(st): c = st[i] j = i + 1 while j < len(st) and st[j] == c: j += 1 k = ord(c) - ord("a") lens[k] += [j - i] freqs[k] += j - i i = j ans = 0 for i in range(26): if freqs[i] > counts[i]: break else: ans = 1 for i in range(26): if len(lens[i]) > 0: lens[i] = sorted(lens[i]) cumu = [0] + lens[i][:-1] for j in range(1, len(cumu)): cumu[j] += cumu[j - 1] lens[i] = lens[i][::-1] cumu = cumu[::-1] memo = defaultdict(int) cnt = rec(counts[i], 0, lens[i], cumu, memo) ans = ans * cnt if ans >= lim: break print(ans if ans < lim else "hel") solve()