import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.container; // SList, DList, BinaryHeap import std.bigint; // BigInt import std.regex; // Regex void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;} T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;} const inf = BigInt(1L<<62); void main() { auto s = readArray!long(26); string t; readV(t); auto d = BigInt(1); foreach (i, si; s) { d *= calc(BigInt(si), t, cast(char)('a'+i)); if (d >= inf) { writeln("hel"); return; } } writeln(d); } auto calc(BigInt s, string t, char c) { auto y = t.matchAll(regex(c.to!string ~ '+')).map!((m) => m[0].length.to!int).array; auto ny = y.length.to!int; if (y.empty || s < y.sum) return BigInt(1); if (s > 10^^7) { if (ny == 1) { if (y[0] == 1) return s; if (y[0] == 2) return s*(s-1)/2; } else if (ny == 2) { if (y[0] == 1 && y[1] == 1) return s/2*(s-s/2); } return inf; } auto r = new Rat[](ny); foreach (i, yi; y) r[i] = Rat(BigInt(yi+1), BigInt(1), yi+1, yi); auto h = heapify(r), d = BigInt(1); foreach (i; 0..(s-y.sum).to!int) { auto ri = h.front; d = d * ri.num / ri.den; if (d >= inf) return inf; h.replaceFront(Rat(BigInt(ri.n+1), BigInt(ri.n+1-ri.r), ri.n+1, ri.r)); } return d; } struct Rat { BigInt num, den; int n, r; auto opCmp(Rat b) { auto c = num*b.den - b.num*den; return c == 0 ? 0 : c < 0 ? -1 : 1; } }