#include #include #include using namespace std; const int N = 8; int n, s, a[N]; int s1[1000005], l1; int s2[1000005], l2; void dfs1(int i, int sum) { if (i == n / 2) { s1[++l1] = sum; return; } int x = 1; while (1ll * x * a[i] + sum <= s) { x *= a[i]; dfs1(i + 1, sum + x); } } void dfs2(int i, int sum) { if (i == n) { s2[++l2] = sum; return; } int x = 1; while (1ll * x * a[i] + sum <= s) { x *= a[i]; dfs2(i + 1, sum + x); } } int main() { cin >> n >> s; for (int i = 0; i != n; i++) cin >> a[i]; dfs1(0, 0), dfs2(n / 2, 0); sort(s1 + 1, s1 + l1 + 1), sort(s2 + 1, s2 + l2 + 1); long long ans = 0; for (int i = 1, j = l2; i <= l1; i++) { while (s1[i] + s2[j] > s) j--; ans += j; } cout << ans << endl; }