#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } template void bAdd(vector &bit, int pos, const T &val) { const int bitN = bit.size(); for (int x = pos; x < bitN; x |= x + 1) bit[x] += val; } template T bSum(const vector &bit, int pos) { T ret = 0; for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) ret += bit[x]; return ret; } template T bSum(const vector &bit, int pos0, int pos1) { return bSum(bit, pos1) - bSum(bit, pos0); } int N, K; Int L, P; vector A, B; int main() { for (; ~scanf("%d%d%lld%lld", &N, &K, &L, &P); ) { A.resize(N); B.resize(N); for (int i = 0; i < N; ++i) { scanf("%lld%lld", &A[i], &B[i]); } const int half = N / 2; vector ASum0(1 << half, 0); vector BSum0(1 << half, 0); for (int i = 0; i < half; ++i) { for (int h = 0; h < 1 << i; ++h) { ASum0[h | 1 << i] = ASum0[h] + A[i]; BSum0[h | 1 << i] = BSum0[h] + B[i]; } } vector ASum1(1 << (N - half), 0); vector BSum1(1 << (N - half), 0); for (int i = 0; i < N - half; ++i) { for (int h = 0; h < 1 << i; ++h) { ASum1[h | 1 << i] = ASum1[h] + A[half + i]; BSum1[h | 1 << i] = BSum1[h] + B[half + i]; } } vector>> pss(half + 1); vector>> qss(N - half + 1); for (int h = 0; h < 1 << half; ++h) { pss[__builtin_popcount(h)].emplace_back(ASum0[h], BSum0[h]); } for (int h = 0; h < 1 << (N - half); ++h) { qss[__builtin_popcount(h)].emplace_back(ASum1[h], BSum1[h]); } // cerr<<"pss = "<