#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int64_t>B(1+N);
  map<int64_t,int64_t>M;
  M[1]=A.at(0);
  for(int i=2;i<=N;i++)
    if(i%2==1)
      M[i]=M.at(i-2)+A.at(i-1);
  B.at(0)=0;
  B.at(0)=0;
  B.at(2)=max(A.at(0),A.at(1));
  for(int i=3;i<=N;i++){
  if(i%2==0)
    B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+M.at(i-3));
    else
      B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+B.at(i-3));
  
  }cout<<B.at(N)<<endl;
   return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
    int i, j, n, cnt=0;
    cin >> n;
    int A[n];

    for (i = 0; i < n; i++) cin >> A[i];

    for (i = 0; i < n; i++) {
        for (j = n - 1; j > i; j--) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                cnt++;
            }
        }
    }

    for (i = 0; i < n; i++) {
        cout << A[i];
        if (i == n - 1) cout << endl;
        else cout << ' ';
    }
    cout << cnt << endl;
    return 0;
}