func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 123;   const long double EPS = 1e-9;   const int MX = 1e9 + 1;   const int inf = 1e9 + 123;   const int MOD = 1e9 + 7;   const int N = 1e5 + 123;   const int dx[] = {0, 0, 1, -1};   const int dy[] = {1, -1, 0, 0};   int n, m;   long long dp[1001], a[13], b[13], c[13], d[13];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> c[0] >> d[0];     for (int i = 1; i <= m; ++i) {       cin >> a[i] >> b[i] >> c[i] >> d[i];     }     for (int i = 1; i <= m; ++i) {       for (int l = n; l >= 0; --l) {         for (int j = 1; j <= a[i] / b[i]; ++j) {           if (l + j * c[i] > n) {             continue;           }           dp[l + j * c[i]] = max(dp[l + j * c[i]], dp[l] + j * d[i]);         }       }     }     for (int l = n; l >= 0; --l) {       for (int j = 1; j <= n / c[0]; ++j) {         if (l + j * c[0] > n) {           continue;         }         dp[l + j * c[0]] = max(dp[l + j * c[0]], dp[l] + d[0] * j);       }     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans = max(ans, dp[i]);     }     cout << ans;     return 0;   }   