func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long lcm = 840;   long long w, cnt[10];   long long dp[10][lcm * 8 + 5];   int main() {     ios::sync_with_stdio(false);     cin >> w;     for (int i = 1; i <= 8; i++) {       cin >> cnt[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i <= 8; i++) {       for (int j = 0; j < 8 * lcm; j++) {         long long xx = min(lcm / i - 1, cnt[i]);         for (int k = 0; k <= xx; k++) {           if (j - k * i >= 0 && dp[i - 1][j - k * i] != -1)             dp[i][j] = max(dp[i][j], dp[i - 1][j - k * i] +                                          (cnt[i] - k) / (lcm / (long long)i));         }       }     }     long long ans = 0;     for (long long i = 0; i < 8 * lcm; i++) {       if (dp[8][i] == -1 || i > w) continue;       ans = max(ans, i + lcm * min(dp[8][i], (w - i) / lcm));     }     cout << ans;     return 0;   }   