func_code_string: #include <bits/stdc++.h>   using namespace std;   int k;   int n1, n2, n3;   int t1, t2, t3;   int v1[3000];   int v2[3030];   int v3[3030];   int main() {     ios::sync_with_stdio(false);     cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;     int time = t1 + t2 + t3 - 1;     int pos = 0;     int res = 0;     for (int i = 0; i <= time + 1; i++) {       v1[i] = 0;       v2[i] = 0;       v3[i] = 0;     }     for (int i = 1; i <= k; i++) {       int posnew = -1;       for (int j = pos; j <= pos + time + 1; j++) {         int kk = j - pos;         if ((v1[kk] + 1 <= n1) &&             ((kk + t1 > time + 1) || (v2[kk + t1] + 1 <= n2)) &&             ((kk + t1 + t2 > time + 1) || (v3[kk + t1 + t2] + 1 <= n3))) {           posnew = j;           break;         }       }       int t = min(pos + time + 1, posnew + time);       for (int j = posnew; j <= t; j++) {         if (j <= posnew + t1 - 1)           v1[j - pos]++;         else if (j <= posnew + t1 + t2 - 1)           v2[j - pos]++;         else           v3[j - pos]++;         v1[j - posnew] = v1[j - pos];         v2[j - posnew] = v2[j - pos];         v3[j - posnew] = v3[j - pos];       }       for (int j = t + 1; j <= posnew + time; j++) {         if (j <= posnew + t1 - 1) {           v1[j - posnew] = 1;           v2[j - posnew] = 0;           v3[j - posnew] = 0;         } else if (j <= posnew + t1 + t2 - 1) {           v2[j - posnew] = 1;           v1[j - posnew] = 0;           v3[j - posnew] = 0;         } else {           v3[j - posnew] = 1;           v1[j - posnew] = 0;           v2[j - posnew] = 0;         }       }       v1[time + 1] = 0;       v2[time + 1] = 0;       v3[time + 1] = 0;       res = posnew + time;       pos = posnew;     }     cout << res + 1;     return 0;   }   