void main() { runSolver(); } void problem() { auto N = scan!int; auto S = scan!long; auto A = scan!long(N); auto solve() { long[long] dp, pre; const half = (N + 1) / 2; dp.clear; dp[0] = 1; foreach(a; A[0..half]) { swap(dp, pre); dp.clear; foreach(ps, pv; pre) { for(long k = a; ps + k <= S; k *= a) { dp[ps + k] += pv; } } } auto halfs = dp.dup; dp.clear; dp[0] = 1; foreach(a; A[half..$]) { swap(dp, pre); dp.clear; foreach(ps, pv; pre) { for(long k = a; ps + k <= S; k *= a) { dp[ps + k] += pv; } } } if (dp.empty) { dp[0] = 1; } auto k1 = halfs.keys.map!(k => [k, halfs[k]]).array.sort!"a[0] < b[0]"; long ans; foreach(s, v; dp) { foreach(hs; k1.lowerBound([S - s + 1, 0])) { ans += v * hs[1]; } } return ans; } outputForAtCoder(&solve); } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop; T[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Point = Tuple!(long, "x", long, "y"); Point invert(Point p) { return Point(p.y, p.x); } long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; } bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; } bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; } string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; } ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}} string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; } struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x>>".writefln(benchmark!problem(1)); BORDER.writeln; } } else problem(); } enum YESNO = [true: "Yes", false: "No"]; // ----------------------------------------------- struct FermetCalculator(uint MD) { long[] factrial; // 階乗 long[] inverse; // 逆元 this(long size) { factrial = new long[size + 1]; inverse = new long[size + 1]; factrial[0] = 1; inverse[0] = 1; for (long i = 1; i <= size; i++) { factrial[i] = (factrial[i - 1] * i) % MD; // 階乗を求める inverse[i] = pow(factrial[i], MD - 2) % MD; // フェルマーの小定理で逆元を求める } } long combine(long n, long k) { if (n < k) return 1; return factrial[n] * inverse[k] % MD * inverse[n - k] % MD; } long pow(long x, long n) { //x^n 計算量O(logn) long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans = ans * x % MD; } x = x * x % MD; //一周する度にx, x^2, x^4, x^8となる n >>= 1; //桁をずらす n = n >> 1 } return ans; } }