n, m, q = read_line.split.map(&.to_i) abs = Array.new(n) { read_line.split.map(&.to_i64) } sum_a = Array.new(1 << n, 0i64) sum_b = Array.new(1 << n, 0i64) 1.upto((1 << n) - 1) do |i| mi = i.trailing_zeros_count sum_a[i] = sum_a[i - (1 << mi)] + abs[mi][0] sum_b[i] = sum_b[i - (1 << mi)] + abs[mi][1] end ans = 0i64 (1 << n).times do |t| if sum_a[t] <= m || sum_a[t] <= q ans = {ans, sum_b[t]}.max end s = t while s > 0 s2 = t ^ s if sum_a[s] <= m && sum_a[s2] <= q ans = {ans, sum_b[t]}.max end s = (s - 1) & t end end puts ans