#include using namespace std; #define rep(i, n) for (int i=0; i node; BIT(int n) { size = n; node.resize(n+1); } void add(int i, int x) { i++; while (i<=size) { node[i] += x; i += i&(-i); } } int acc(int i) { int s = 0; while (i>0) { s += node[i]; i -= i&(-i); } return s; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K, L, P; cin >> N >> K >> L >> P; ll A[N], B[N]; rep(i, N) cin >> A[i] >> B[i]; int N1 = N/2; vector> L1[N1+1]; rep(S, 1<>i)&1) { cnt++; as += A[i]; bs += B[i]; } L1[cnt].pb(make_pair(as, bs)); } rep(i, N1+1) sort(L1[i].rbegin(), L1[i].rend()); int N2 = N-N1; vector> L2[N2+1]; rep(S, 1<>i)&1) { cnt++; as += A[N1+i]; bs += B[N1+i]; } L2[cnt].pb(make_pair(as, bs)); } rep(i, N2+1) sort(L2[i].begin(), L2[i].end()); ll ans = 0ll; rep(c1, N1+1) rep(c2, N2+1) { if (c1+c2>K) continue; vector values; rep(i, L1[c1].size()) values.pb(P-L1[c1][i].second); rep(i, L2[c2].size()) values.pb(L2[c2][i].second); sort(values.begin(), values.end()); values.erase(unique(values.begin(), values.end()), values.end()); map idx; rep(i, values.size()) idx[values[i]] = i; BIT bit(values.size()); int j = 0; rep(i, L1[c1].size()) { while (j