#include using namespace std; template struct BinaryIndexedTree { int N; vectorbit; BinaryIndexedTree(){} BinaryIndexedTree(int x) { N = x; bit.resize(x+1); } void add(int x,T y) { while(x <= N) { bit[x] += y; x += x&-x; } } T sum(int x) { T res = 0; while(x) { res += bit[x]; x -= x&-x; } return res; } inline T sum(int l, int r) {//[l,r] return sum(r)-sum(l-1); } inline T operator[](int k) { return sum(k)-sum(k-1); } }; int main() { int N,K,L,P; cin >> N >> K >> L >> P; vectorA(N),B(N); for(int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } int a = N/2,b = N-a; vector>>tmp1(a+1),tmp2(b+1); for(int i = 0; i < (1 << a); i++) { long long sum1 = 0,sum2 = 0; for(int j = 0; j < a; j++) { if(1 & (i >> j)) { sum1 += A[j]; sum2 += B[j]; } } if(sum1 <= L) { if(sum2 >= P) sum2 = P; tmp1[__builtin_popcount(i)].push_back({sum1,sum2}); } } for(int i = 0; i < (1 << b); i++) { long long sum1 = 0,sum2 = 0; for(int j = 0; j < b; j++) { if(1 & (i >> j)) { sum1 += A[a+j]; sum2 += B[a+j]; } } if(sum1 <= L) { if(sum2 >= P) sum2 = P; tmp2[__builtin_popcount(i)].push_back({sum1,sum2}); } } long long ans = 0; for(int i = min(a,K); i >= 0; i--) { vector>c,d; for(int j = 0; j < tmp1[i].size(); j++) { c.push_back(tmp1[i][j]); } sort(c.rbegin(),c.rend()); vectorcmp; for(int j = min(b,K-i); j >= 0; j--) { for(int k = 0; k < tmp2[j].size(); k++) { d.push_back(tmp2[j][k]); cmp.push_back(tmp2[j][k].second); } } sort(d.begin(),d.end()); sort(cmp.begin(),cmp.end()); cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end()); BinaryIndexedTreebit(cmp.size()); int now = 0; for(int j = 0; j < c.size(); j++) { while(now < d.size() && c[j].first+d[now].first <= L) { int it = lower_bound(cmp.begin(),cmp.end(),d[now].second)-cmp.begin(); bit.add(it+1,1); now++; } int it = lower_bound(cmp.begin(),cmp.end(),P-c[j].second)-cmp.begin(); if(it < cmp.size()) { ans += bit.sum(it+1,cmp.size()); } } } cout << ans << endl; }