#pragma GCC optimize ("O3") #pragma GCC target ("avx") // yukicoder // #pragma GCC target ("sse4.2") // SPOJ, codechef #include #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i64 = long long; using u8 = unsigned char; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; int A[100], poly[50010]; const int MOD = 1234567891; // MOD < 2^31 まで動作し,かつ,効率良くベクトル化される. int add_mod(int a, int b) { return (a += b - MOD) < 0 ? a + MOD : a; } // overlap も考慮してベクトル化される. void vec_add(int n, int* a, int* b) { for (int i = n - 1; i >= 0; --i) { a[i] = add_mod(a[i], b[i]); } } void solve() { i64 N, M; while (~scanf("%lld %lld", &N, &M)) { i64 s = 0; rep(i, N) scanf("%d", &A[i]), s += A[i]; sort(A, A + N); int t = 0; poly[t++] = 1; while (M) { fill(poly + t, poly + s + t, 0); rep(i, N) { vec_add(t, poly + A[i], poly); t += A[i]; } int p = M & 1; M >>= 1; t = (t + 1 - p) >> 1; rep(i, t) poly[i] = poly[2 * i + p]; } printf("%d\n", poly[0]); } } int main() { clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }