#include #define all(v) begin(v), end(v) using namespace std; const int MOD = 1e9 + 7; using ull = unsigned long long; using ll = long long; using ld = long double; template inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(S &a, const T &b) { if (a > b) { a = b; return true; } return false; } template using pq = priority_queue; template using pqg = priority_queue, greater>; int main() { int n, k; ll l, p; cin >> n >> k >> l >> p; vector a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; vector>> cnt(n); for (int bit = 0; bit < (1 << (n / 2)); ++bit) { bool ok = true; int num = 0; ll cost = 0, value = 0; for (int i = 0; i < n / 2; ++i) { if (num > k || cost > l) { ok = false; break; } if (bit & (1 << i)) { ++num; cost += a[i]; value += b[i]; } } if (ok) cnt[num][cost].push_back(value); } for (int i = 0; i < n; ++i) { for (auto &&[a, v] : cnt[i]) { sort(all(v)); } } ll ans = 0; for (int bit = 0; bit < (1 << (n - n / 2)); ++bit) { bool ok = true; int num = 0; ll cost = 0, value = 0; for (int i = 0; i < (n - n / 2); ++i) { if (num > k || cost > l) { ok = false; break; } if (bit & (1 << i)) { ++num; cost += a[i + n / 2]; value += b[i + n / 2]; } } if (!ok) continue; for (int i = 0; i <= k - num; ++i) { if (cnt[i].empty()) continue; for (auto &&[a, v] : cnt[i]) { if (a > (l - cost)) break; if (v.empty()) continue; ans += v.end() - lower_bound(all(v), p - value); } } } cout << ans << endl; return 0; }