#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; template struct value_compression : vector { bool built = false; using VS = vector; using VS::VS; value_compression(vector v) : vector(move(v)) {} void build() { sort(this->begin(), this->end()); this->erase(unique(this->begin(), this->end()), this->end()); built = true; } template void convert(T first, T last) { assert(built); for (; first != last; ++first) *first = (*this)(*first); } int operator()(S x) { assert(built); return lower_bound(this->begin(), this->end(), x) - this->begin(); } void clear() { this->clear(); built = false; } }; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, l, p; cin >> n >> k >> l >> p; vector>> ps1{{{0, 0}}}, ps2{{{0, 0}}}; rep(_, n) { int a, b; cin >> a >> b; int sz = ps1.size(); ps1.emplace_back(); rrep(i, sz) { int psz = ps1[i+1].size(); for(auto [x, y]: ps1[i]) { ps1[i+1].emplace_back(x + a, y + b); } inplace_merge(ps1[i+1].begin(), ps1[i+1].begin() + psz, ps1[i+1].end()); } swap(ps1, ps2); } int sz1 = ps1.size(), sz2 = ps2.size(); value_compression vc; rep(i, sz1) for(auto [x, y]: ps1[i]) vc.emplace_back(y); vc.build(); rep(i, sz1) for(auto& [_, y]: ps1[i]) y = vc(y); rep(i, sz2) reverse(all(ps2[i])); vector> d; int included = 0; ll ans = 0; rrep(k2, sz2) { int k1 = min(sz1 - 1, k - k2) + 1; if (k1 <= 0) continue; while(included < k1) { int dsz = d.size(); d.insert(d.end(), all(ps1[included])); included++; inplace_merge(d.begin(), d.begin() + dsz, d.end()); } int dsz = d.size(); int ptr = 0; int m = vc.size(); fenwick_tree ft(m); for(auto [x, y]: ps2[k2]) { while(ptr < dsz && d[ptr].first <= l - x) { auto [_, yi] = d[ptr++]; ft.add(yi, 1); } ans += ft.sum(vc(p - y), m); } } cout << ans << '\n'; }