Language: C++

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5 + 10;
int a[MAXN];
int dp[MAXN][2][3];
bool visit[MAXN][2][3];
int n;

int rec_even(int idx,int type,int cnt){
    if(idx > n) return 0;
    int &ans = dp[idx][type][cnt];

    if(visit[idx][type][cnt]) return ans;
    visit[idx][type][cnt] = 1;

    ans = -1e16;

    if(type == 0) {
        ans = max(ans,rec_even(idx+1,1,cnt));
        if(cnt == 0) ans = max(ans,rec_even(idx+1,0,cnt+1));
    }else {
        ans = max(ans,rec_even(idx+1,0,cnt) + a[idx]);
    }

    return ans;
}

int rec_odd(int idx,int type,int cnt){
    if(idx > n) return 0;
    int &ans = dp[idx][type][cnt];

    if(visit[idx][type][cnt]) return ans;
    visit[idx][type][cnt] = 1;

    ans = -1e16;

    if(type == 0) {
        ans = max(ans,rec_odd(idx+1,1,cnt));
        if(cnt < 2) ans = max(ans,rec_odd(idx+1,0,cnt+1));
    }else {
        ans = max(ans,rec_odd(idx+1,0,cnt) + a[idx]);
    }

    return ans;
}
void solve(){
    cin>>n;

    FOR(i,1,n) cin>>a[i];

    if(n%2 == 0){
        int ans = 0;
        for(int i=2;i<=n;i+=2) ans = ans + a[i];
        ZERO(visit);
        ans = max(ans,rec_even(1,1,0));
        cout<<ans<<endl;
    }else {
        int ans = 0;
        for(int i=3;i<=n;i+=2) ans = ans + a[i];
        ZERO(visit);
        ans = max(ans,rec_odd(1,1,0));
        ZERO(visit);
        ans = max(ans,rec_even(2,1,0));
        cout<<ans<<endl;
    }
}

signed main(){

   FastRead; 


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}





Compiler output:
a.cc: In function 'long long int rec_even(long long int, long long int, long long int)':
a.cc:43:8: error: reference to 'visit' is ambiguous
   43 |     if(visit[idx][type][cnt]) return ans;
      |        ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:4:
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:44:5: error: reference to 'visit' is ambiguous
   44 |     visit[idx][type][cnt] = 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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc: In function 'long long int rec_odd(long long int, long long int, long long int)':
a.cc:62:8: error: reference to 'visit' is ambiguous
   62 |     if(visit[idx][type][cnt]) return ans;
      |        ^~~~~
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:63:5: error: reference to 'visit' is ambiguous
   63 |     visit[idx][type][cnt] = 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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc: In function 'void solve()':
a.cc:84:14: error: reference to 'visit' is ambiguous
   84 |         ZERO(visit);
      |              ^~~~~
a.cc:16:25: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                         ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:84:14: error: reference to 'visit' is ambiguous
   84 |         ZERO(visit);
      |              ^~~~~
a.cc:16:38: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                                      ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:90:14: error: reference to 'visit' is ambiguous
   90 |         ZERO(visit);
      |              ^~~~~
a.cc:16:25: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                         ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:90:14: error: reference to 'visit' is ambiguous
   90 |         ZERO(visit);
      |              ^~~~~
a.cc:16:38: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                                      ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:92:14: error: reference to 'visit' is ambiguous
   92 |         ZERO(visit);
      |              ^~~~~
a.cc:16:25: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                         ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~
a.cc:92:14: error: reference to 'visit' is ambiguous
   92 |         ZERO(visit);
      |              ^~~~~
a.cc:16:38: note: in definition of macro 'ZERO'
   16 | #define ZERO(a) memset((a),0,sizeof((a)))
      |                                      ^
/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:36:6: note:                 'bool visit [200010][2][3]'
   36 | bool visit[MAXN][2][3];
      |      ^~~~~