Language: C++

#include <bits/stdc++.h>
using namespace std; 
const int maxn = 100500;
const int mod = 1e9 + 7;
#define int long long

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    int gg[2], ss[2], bb[2];
    cin >> n;
    for(int i = 0 ; i < 2 ; ++i)
        cin >> gg[i] >> ss[i] >> bb[i];
    vector < pair < int, int > > a, b;
    if(gg[0] > gg[1]) a.push_back({gg[1], gg[0]});
    else b.push_back({gg[0], gg[1]});
    if(ss[0] > ss[1]) a.push_back({ss[1], ss[0]});
    else b.push_back({ss[0], ss[1]});
    if(bb[0] > bb[1]) a.push_back({bb[1], bb[0]});
    else b.push_back({bb[0], bb[1]});
    int ans = n;
    if((int)b.size() > 0){
        if((int)b.size() == 1) ans = b[0].second * (ans / b[0].first) + ans % b[0].first;
        if((int)b.size() == 2){
            int bst = 0;
            for(int i = 0 ; i <= ans ; ++i){
                if(i * b[0].first > ans) break;
                ll sm = b[0].second * i;
                int rem = ans - i * b[0].first;
                sm += b[1].second * (rem / b[1].second);
                sm += rem % b[1].second;
                bst = max(bst, sm);
            }
            ans = max(ans, bst);
        }
        if((int)b.size() == 3){
            int bst = 0;
            for(int i = 0 ; i <= ans ; ++i)
                for(int j = 0 ; j <= ans; ++j){
                    if(i * gg[0] + j * ss[0] > ans) continue;
                    int sm = (i * gg[1]) + (j * ss[1]);
                    int rem = ans - i * gg[0] - j * ss[0];
                    sm += bb[1] * (rem / bb[0]);
                    rem %= bb[0];
                    bst = max(bst, sm + rem);
                }
            ans = max(ans, bst);
        }
    } 

    if((int)a.size() > 0){
        if((int)a.size() == 1) ans = a[0].second * (ans / a[0].first) + ans % a[0].first;
        if((int)a.size() == 2){
            int bst = 0;
            for(int i = 0 ; i <= ans ; ++i){
                if(i * a[0].first > ans) break;
                ll sm = a[0].second * i;
                int rem = ans - i * a[0].first;
                sm += a[1].second * (rem / a[1].second);
                sm += rem % a[1].second;
                bst = max(bst, sm);
            }
            ans = max(ans, bst);
        }
        if((int)a.size() == 3){
            int bst = 0;
            for(int i = 0 ; i <= ans ; ++i)
                for(int j = 0 ; j <= ans; ++j){
                    if(i * gg[1] + j * ss[1] > ans) continue;
                    int sm = (i * gg[0]) + (j * ss[0]);
                    int rem = ans - i * gg[1] - j * ss[1];
                    sm += bb[0] * (rem / bb[1]);
                    rem %= bb[1];
                    bst = max(bst, sm + rem);
                }
            ans = max(ans, bst);
        }
    }
    cout << ans << '\n';
    return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:17: error: 'll' was not declared in this scope
   29 |                 ll sm = b[0].second * i;
      |                 ^~
a.cc:31:17: error: 'sm' was not declared in this scope; did you mean 'ss'?
   31 |                 sm += b[1].second * (rem / b[1].second);
      |                 ^~
      |                 ss
a.cc:58:17: error: 'll' was not declared in this scope
   58 |                 ll sm = a[0].second * i;
      |                 ^~
a.cc:60:17: error: 'sm' was not declared in this scope; did you mean 'ss'?
   60 |                 sm += a[1].second * (rem / a[1].second);
      |                 ^~
      |                 ss