Language: C++

#include<bits/stdc++.h>
using namespace std;	
int n;
int a[3],b[3],forward[5005],back[5005];
int main(){
	scanf("%d",&n);
	for(int i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<3;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			if(i-a[j]>=0) forward[i]=max(forward[i],forward[i-a[j]]+b[j]-a[j]);
		}
	}
	n+=forward[n];
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			if(i-b[j]>=0) back[i]=max(back[i],back[i-b[j]]+a[j]-b[j]);
		}
	}
	n+=back[n];
	printf("%d",n);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:39: error: reference to 'forward' is ambiguous
   15 |                         if(i-a[j]>=0) forward[i]=max(forward[i],forward[i-a[j]]+b[j]-a[j]);
      |                                       ^~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:15: note:                 'int forward [5005]'
    4 | int a[3],b[3],forward[5005],back[5005];
      |               ^~~~~~~
a.cc:15:54: error: reference to 'forward' is ambiguous
   15 |                         if(i-a[j]>=0) forward[i]=max(forward[i],forward[i-a[j]]+b[j]-a[j]);
      |                                                      ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:15: note:                 'int forward [5005]'
    4 | int a[3],b[3],forward[5005],back[5005];
      |               ^~~~~~~
a.cc:15:65: error: reference to 'forward' is ambiguous
   15 |                         if(i-a[j]>=0) forward[i]=max(forward[i],forward[i-a[j]]+b[j]-a[j]);
      |                                                                 ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:15: note:                 'int forward [5005]'
    4 | int a[3],b[3],forward[5005],back[5005];
      |               ^~~~~~~
a.cc:18:12: error: reference to 'forward' is ambiguous
   18 |         n+=forward[n];
      |            ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:15: note:                 'int forward [5005]'
    4 | int a[3],b[3],forward[5005],back[5005];
      |               ^~~~~~~