vector<int> t(n); for (int i = 0; i < n; i++) { cin >> t[i]; }
vector<int> t1, t2; for (int i = 0; i < n / 2; i++) { t1.push_back(t[i]); } for (int i = n / 2; i < n; i++) { t2.push_back(t[i]); }
vector<longlong> a, b; auto cal = [](auto v, auto &res) { int c = v.size(); for (int i = 0; i < (1 << c); i++) { longlong sum = 0; for (int j = 0; j < c; j++) { if (i & (1 << j)) { sum += v[j]; } } res.push_back(sum); } }; cal(t1, a), cal(t2, b); sort(a.begin(), a.end()); sort(b.begin(), b.end());
longlong ans = 0; for (auto val : a) { ans += upper_bound(b.begin(), b.end(), x - val) - lower_bound(b.begin(), b.end(), x - val); } cout << ans << "\n";