func_code_string: #include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0;     int zf = 1;     char ch =    ;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   long long val[1000005];   long long f[1000005];   int n;   long long cnt[9];   int main() {     long long w = read(), tmp = w, sum = 0;     for (int i = 1; i <= 8; ++i) cnt[i] = read(), sum += cnt[i] * i;     if (sum < w) {       printf( %lld , sum);       return 0;     }     if (w > 900) {       long long w2 = w - 900, use;       for (int i = 8; i >= 1 && w2; --i) {         if (cnt[i] * i <= w2)           w2 -= cnt[i] * i;         else {           use = (w2 / i) + 1;           cnt[i] -= use;           w2 -= use * i;           break;         }       }       w = 900 + w2;     }     for (int i = 1; i <= 8; ++i) {       long long j = 1;       while (cnt[i] >= j) {         cnt[i] -= j;         val[++n] = i * j;         j <<= 1;       }       if (cnt[i]) val[++n] = cnt[i] * i;     }     for (int i = 1; i <= n; ++i)       for (int j = w; j >= val[i]; --j) f[j] = max(f[j - val[i]] + val[i], f[j]);     printf( %lld , tmp - (w - f[w]));     return 0;   }   