#include using ll = long long; using std::cin; using std::cout; using std::endl; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int inf = (int)1e9 + 7; constexpr long long INF = 1LL << 60; void solve() { ll n, M, Q; cin >> n >> M >> Q; std::vector w(n), v(n); for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } std::vector dp1(1 << n), dp2(1 << n); for (int S = 0; S < (1 << n); S++) { ll cost = 0; ll val = 0; for (int i = 0; i < n; i++) { if (S >> i & 1) { cost += w[i]; val += v[i]; } } if (cost <= M) { dp1[S] = val; } if (cost <= Q) { dp2[S] = val; } } for (int i = 0; i < n; i++) { for (int S = 0; S < (1 << n); S++) { if (S >> i & 1) { continue; } chmax(dp1[S | 1 << i], dp1[S]); chmax(dp2[S | 1 << i], dp2[S]); } } ll res = 0; for (int S = 0; S < (1 << n); S++) { chmax(res, dp1[S] + dp2[((1 << n) - 1) ^ S]); } cout << res << "\n"; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int kkt = 1; // cin >> kkt; while (kkt--) { solve(); } }