Language: C++

#pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> // Common file  
    #include <ext/pb_ds/tree_policy.hpp>  
    #include <functional> // for less  
    #include <iostream>  
    using namespace __gnu_pbds;  
    using namespace std;
    #define ll long long
    typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
    using namespace std;
     
    #define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
    #define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
    #define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
    #define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
    #define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
    #define fill(ar,val) memset(ar, val, sizeof(ar))
    #define fill0(ar) fill((ar), 0)
    #define fillinf(ar, n) fr(i,0,(n)) ar[i] = INF
    #define debug(x) cout<<#x<<": "<<x<<endl
    #define arr1d(a,n) cout << #a << " : "; fr(_,1,n) cout << a[_] << ' '; cout << endl;
    #define arr1d0(a,n) cout << #a << " : "; rep(_,n) cout << a[_] << ' '; cout << endl;
    #define arr2d(a,n,m) cout << #a << " :" << endl; fr(_,1,n) {fr(__,1,m) cout << a[_][__] << ' '; cout << endl;}
    #define arr2d0(a,n,m) cout << #a << " :" << endl; rep(_,n) {rep(__,m) cout << a[_][__] << ' '; cout << endl;}
    /*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
    /*IIT Roorkee = <3 */
    #define ull unsigned long long
    #define ld long double
    #define ui unsigned int
    #define all(ar) ar.begin(), ar.end()
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define y0 yyyyyy0
    auto clk=clock();
    #define y1 yyyyyy1
    #define setb __builtin_popcount
    #define BIT(n) (1<<(n))
    #define SQR(x) ((x) * (x))
    #define CUBE(x) ((x) * (x) * (x))
    #define LSOne(S) (S) & (-S)
    inline bool EQ(double a, double b) {return fabs(a - b) < 1e-9;}
     
    typedef pair<int, int> ii;
    typedef pair<int, ii> iii;
    typedef vector<ii> vii;
    typedef vector<int> vi;
    typedef vector<string> vs;
     
    template<typename T>inline T gcd(T a, T b){if (b == 0)return a;else return gcd(b, a % b);}
    // template<typename T>inline T lcm(T a, T b){return (a * b) / gcd(a, b);}
    template<typename T> string toStr(T x) {stringstream st; st << x; string s; st >> s; return s;}
    template<class T>
    void splitStr(const string &s, vector<T> &out)
    {
        istringstream in(s);
        out.clear();
        copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
    }
     
    inline int two(int n) {return 1 << n;}
    inline int isOnBit(int n, int b) {return (n >> b) & 1;}
    inline void onBit(int & n, int b) {n |= two(b);}
    inline void offBit(int & n, int b) {n &= ~two(b);}
    inline int lastBit(int n) {return n & (-n);}
    inline int cntBit(int n) {int res = 0; while(n && ++res) n -= n &(-n); return res;}
     
    const int dx4[] = {-1, 0, 1, 0};
    const int dy4[] = {0, 1, 0, -1};
    const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
    const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
     
    #define INP "test.inp"
    #define OUT "test.out"
     
    #define PI 3.1415926535897932385
    #define INF 10000000000000000ll
    #define EPS 1e-7
    #define MAXN 100000
    #define MOD 1000000009
    #define dec decr
    #define endl '\n'

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll modexp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y %2==1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
pair<ll,ll> find(ll x,int g1,int g2)
{
	ll x1=x;
	int f=x/g1;
	x-=f*g1;
	ll y=f*g2;
	ll pro=y+x-x1;
	if(pro>=0)
	{
		return mp(x,x1+pro-x);
	}
	else
	{
		return mp(x,-INF);
	}
}
int mat[2][3];
ll lel(ll n)
{
	ll ans=n;
	for(int i=0;i<=n/mat[0][0]+1;i++)
	{
		for(int j=0;j<=n/mat[0][1]+1;j++)
		{
			ll x1=0;
			if(i*mat[0][0]+j*mat[0][1]<=n)
			{
				x1+=(find(i*mat[0][0],mat[0][0],mat[1][0])).ss;
				x1+=(find(j*mat[0][1],mat[0][1],mat[1][1])).ss;
				auto x=(find(n-i*mat[0][0]-j*mat[0][1],mat[0][2],mat[1][2]));
				x1+=x.ff;
				x1+=x.ss;
				ans=max(ans,x1);
			}		
		}
	}

    return ans;
}
int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed;
    cout<<setprecision(9);
    #ifdef rg
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    rep(i,3)
    {
    	cin>>mat[0][i];
    }
    rep(i,3)
    {
    	cin>>mat[1][i];
    }
    n=lel(n);
    // cout<<n;
    rep(i,3)
    {
    	swap(mat[0][i],mat[1][i]);
    }
    n=lel(n);
    cout<<n;


    #ifdef rg
    cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}   

Compiler output:
a.cc: In function 'long long int lel(long long int)':
a.cc:36:16: error: request for member 'second' in 'std::find<int, int>((i * mat[0][0]), mat[0][0], mat[1][0])', which is of non-class type 'int'
   36 |     #define ss second
      |                ^~~~~~
a.cc:134:77: note: in expansion of macro 'ss'
  134 |                                 x1+=(find(i*mat[0][0],mat[0][0],mat[1][0])).ss;
      |                                                                             ^~
a.cc:36:16: error: request for member 'second' in 'std::find<int, int>((j * mat[0][1]), mat[0][1], mat[1][1])', which is of non-class type 'int'
   36 |     #define ss second
      |                ^~~~~~
a.cc:135:77: note: in expansion of macro 'ss'
  135 |                                 x1+=(find(j*mat[0][1],mat[0][1],mat[1][1])).ss;
      |                                                                             ^~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const int>]':
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = int]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:134:14:   required from here
  134 |                                 x1+=(find(i*mat[0][0],mat[0][0],mat[1][0])).ss;
      |                                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2153:48: error: no matching function for call to '__iterator_category(int&)'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:65:
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note: candidate: 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&)'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]':
/usr/include/c++/14/bits/stl_algobase.h:2153:34:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const int>]'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = int]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:134:14:   required from here
  134 |                                 x1+=(find(i*mat[0][0],mat[0][0],mat[1][0])).ss;
      |                                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~