Language: C++

#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

const int N=2*1e5+1;
const int inf = 1e18;
int dp[N][4];
int visit[N][4];

int n;
int a[N];

int solve(int id,int have){
	if(id>n){
		if(have<=1)
			return 0;
		return -inf;
	}
	
	int &tmp = dp[id][have];
	if(visit[id][have])
		return tmp;
	visit[id][have]=1;
	if(!have)
		tmp = solve(id+2,have)+a[id];
	else{
		tmp = max(tmp,solve(id+2,have)+a[id]);
		tmp = max(tmp,solve(id+1,have-1));
	}
	return tmp;
}

int32_t main() { 
    boost;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    memset(visit,0,sizeof visit);
    int ans ;
    if(n%2)
    	ans = max(solve(1,2),solve(2,1));
    else
    	ans = max(solve(1,1),solve(2,0));
    cout<<ans<<endl;
}           





Compiler output:
a.cc: In function 'long long int solve(long long int, long long int)':
a.cc:27:12: error: reference to 'visit' is ambiguous
   27 |         if(visit[id][have])
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:14:5: note:                 'long long int visit [200001][4]'
   14 | int visit[N][4];
      |     ^~~~~
a.cc:29:9: error: reference to 'visit' is ambiguous
   29 |         visit[id][have]=1;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:14:5: note:                 'long long int visit [200001][4]'
   14 | int visit[N][4];
      |     ^~~~~
a.cc: In function 'int32_t main()':
a.cc:44:12: error: reference to 'visit' is ambiguous
   44 |     memset(visit,0,sizeof visit);
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:14:5: note:                 'long long int visit [200001][4]'
   14 | int visit[N][4];
      |     ^~~~~
a.cc:44:27: error: reference to 'visit' is ambiguous
   44 |     memset(visit,0,sizeof visit);
      |                           ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:14:5: note:                 'long long int visit [200001][4]'
   14 | int visit[N][4];
      |     ^~~~~