Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  long long ans=0;
  if(n%2==0){
    for(int i=0;i<n;i+=2) ans+=a[i];
    long long x=0;
    for(int i=1;i<n;i+=2) x+=a[i];
    ans=max(ans,x);
    cout<<ans<<endl;
  }
  else{
    vector<vector<long long>>dp(3,vector<long, long>(n/2+1));
    dp[0][0]=0;
    dp[1][0]=0;
    dp[2][0]=0;
    for(int i=1;i<n/2+1;i++){
      dp[0][i]=dp[0][i-1]+a[2*(i-1)];
      dp[1][i]=dp[1][i-1]+a[2*(i-1)+1];
      dp[2][i]=dp[2][i-1]+a[2*(i-1)+1];
    }
    for(int i=0;i<n/2+1;i++){
      for(int j=i;j<n/2+1;j++){
        ans=max(ans,dp[0][i]+dp[1][j]-dp[1][i]+dp[2][n/2]-dp[2][j]);
      }
    }
    cout<<ans<<endl;
  }               
}

Compiler output:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'struct std::_Vector_base<long int, long int>':
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<long int, long int>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:18:59:   required from here
   18 |     vector<vector<long long>>dp(3,vector<long, long>(n/2+1));
      |                                                           ^
/usr/include/c++/14/bits/stl_vector.h:87:28: error: 'long int' is not a class, struct, or union type
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:89:9: error: 'long int' is not a class, struct, or union type
   89 |         pointer;
      |         ^~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'class std::vector<long int, long int>':
a.cc:18:59:   required from here
   18 |     vector<vector<long long>>dp(3,vector<long, long>(n/2+1));
      |                                                           ^
/usr/include/c++/14/bits/stl_vector.h:518:20: error: '_M_allocate' has not been declared in 'std::vector<long int, long int>::_Base'
  518 |       using _Base::_M_allocate;
      |                    ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:519:20: error: '_M_deallocate' has not been declared in 'std::vector<long int, long int>::_Base'
  519 |       using _Base::_M_deallocate;
      |                    ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:521:20: error: '_M_get_Tp_allocator' has not been declared in 'std::vector<long int, long int>::_Base'
  521 |       using _Base::_M_get_Tp_allocator;
      |                    ^~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:18:59: error: call of overloaded 'vector(int)' is ambiguous
   18 |     vector<vector<long long>>dp(3,vector<long, long>(n/2+1));
      |                                                           ^
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = long int; _Alloc = long int]'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = long int; _Alloc = long int]'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = long int; _Alloc = long int; size_type = long unsigned int; allocator_type = long int]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = long int; _Alloc = long int; allocator_type = long int]'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~