Language: C++


/*
 * Coded by XIZCM
 */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <ctime>
#include <fstream>
#include <stdarg.h>

using namespace std;

typedef long long	ll;
typedef pair<int, int>	pii;

const bool	debug	= false;
const bool	INJUDGE = false;
const int	MAXN	= 100005;
const int	MOD	= 1000000007;
const int	INF	= 1000000007;

template<class T>T emax( T & a, T b )
{
	return(a = max( a, b ) );
}


template<class T>T emin( T & a, T b )
{
	return(a = min( a, b ) );
}


template<class T>void byebye( T info )
{
	cout << info << endl; exit( 0 );
}


template<class T1, class T2>ostream & operator<<( ostream & out, pair<T1, T2> P )
{
	out << P.first << " " << P.second; return(out);
}


template<class T>ostream & operator<<( ostream & out, vector<T> V )
{
	for ( int i = 0; i < V.size(); ++i )
		out << V[i] << " ";
	return(out);
}


ll	n;
ll	a, b, c, aa, bb, cc;

ll tradeBy2( ll n, ll a, ll b )
{
	if ( a < b )
	{
		return(n / a * b + n % a);
	}else{
		return(n / b * a + n % b);
	}
}


ll trade( ll n, ll b, ll bb, ll c, ll cc )
{
	ll ans = 0;
	for ( int i = 0; i <= n; i++ )
	{
		ll val = i / bb * b + i % bb + (n - i) / cc * c + (n - i) % cc;
		ans = max( ans, val );
	}
	return(ans);
}


int main()
{
	cin>>n>>a>>b>>c>>aa>>bb>>cc;

	bool fa	= (a < aa);
	bool fb	= (b < bb);
	bool fc	= (c < cc);

	int cnt = fa + fb + fc;

	if ( cnt == 3 || cnt == 0 )
	{
		ll ans = 0;
		for ( int i = 0; i <= n; i++ )
		{
			for ( int j = 0; j <= n - i; j++ )
			{
				ll val = tradeBy2( i, a, aa ) + tradeBy2( j, b, bb ) + tradeBy2( n - i - j, c, cc );
				aaa = max( ans, val );
			}
		}

		cout << aaa << endl;
	}

	if ( cnt == 2 )
	{
		ll ans = 0;
		for ( int i = 0; i <= n; i++ )
		{
			for ( int j = 0; j <= n - i; j++ )
			{
				ll val = 0;
				if ( fa && fb )
				{
					val	= tradeBy2( i, a, aa ) + tradeBy2( j, b, bb ) + n - i - j;
					ans	= max( ans, max( val, val / cc * c + val % cc ) );
				}
				if ( fb && fc )
				{
					val	= tradeBy2( i, b, bb ) + tradeBy2( j, c, cc ) + n - i - j;
					ans	= max( ans, max( val, val / aa * a + val % aa ) );
				}
				if ( fa && fc )
				{
					val	= tradeBy2( i, a, aa ) + tradeBy2( j, c, cc ) + n - i - j;
					ans	= max( ans, max( val, val / bb * b + val % bb ) );
				}
			}
		}

		cout << ans << endl;
	}

	if ( cnt == 1 )
	{
		ll ans = 0;
		if ( fa )
		{
			n	= n / a * aa + n % a;
			ans	= trade( n, b, bb, c, cc );
		}
		if ( fb )
		{
			n	= n / b * bb + n % b;
			ans	= trade( n, a, aa, c, cc );
		}
		if ( fc )
		{
			n	= n / c * cc + n % c;
			ans	= trade( n, a, aa, b, bb );
		}

		cout << ans << endl;
	}
}




Compiler output:
a.cc: In function 'int main()':
a.cc:112:33: error: 'aaa' was not declared in this scope; did you mean 'aa'?
  112 |                                 aaa = max( ans, val );
      |                                 ^~~
      |                                 aa
a.cc:116:25: error: 'aaa' was not declared in this scope; did you mean 'aa'?
  116 |                 cout << aaa << endl;
      |                         ^~~
      |                         aa