#include using namespace std; #define rep(i, l, r) for (int i = (l); i < (r); i++) #define ll long long #define all(x) (x).begin(), (x).end() #define siz(x) (int)x.size() #define debug(x) cout << #x << " : " << endl; for (auto u : x) cout << u << " "; cout << endl template bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const int inf = 1e9; const ll INF = 4e18; int main() { int N, B; cin >> N >> B; vector dp(B + 1, 0); rep(i, 0, N) { int p, c, s, d; cin >> p >> c >> s >> d; vector ep(B + 1, 0); rep(j, 0, B + 1) rep(k, 0, c + 1) { int satis = k * (s - (k - 1) * d); if (j + k * p <= B) chmax(ep[j + k * p], dp[j] + satis); } swap(dp, ep); } cout << dp[B] << endl; }