#include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace std; typedef long long ll; int n, m, q; vector p, v; template bool chmax(T &a, S b) { if (a < b) { a = b; return 1; } return 0; } int main() { cin >> n >> m >> q; p.resize(n); v.resize(n); rep(i, 0, n) cin >> p[i] >> v[i]; vector x(1 << n), y(1 << n); rep(i, 0, 1 << n) { ll sump = 0, sumv = 0; rep(j, 0, n) { if (i >> j & 1) { sump += p[j]; sumv += v[j]; } } if (sump <= m) x[i] = sumv; if (sump <= q) y[i] = sumv; } for (int bit = 0; bit < (1 << n); ++bit) { for (int i = 0; i < n; ++i) { if ((1 << i) & bit) continue; chmax(x[(1 << i) | bit], x[bit]); chmax(y[(1 << i) | bit], y[bit]); } } ll ans = 0; int mask = (1 << n) - 1; rep(i, 0, 1 << n) chmax(ans, x[i] + y[mask ^ i]); cout << ans << endl; }