#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
long wine[10001];
long didAteBefore[10001]; // i칸 , i-1칸 마심
long didAteBeforeBefore[10001]; //i칸, i-2칸 마심
long didAteBeforeBeforeBefore[10001]; //i칸, i-3칸 마심
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i<n; i++){
cin >> wine[i];
}
didAteBefore[0] = wine[0];
didAteBeforeBefore[0] = wine[0];
didAteBeforeBeforeBefore[0] = wine[0];
if (n == 0){
cout << wine[0];
return 0;
}else if (n==1){
cout << wine[0]+ wine[1];
return 0;
}
/**
* X O X
* X O O X
* X O O O X
*
*/
didAteBefore[1] = wine[0] + wine[1];
didAteBeforeBefore[1] = wine[1];
didAteBeforeBeforeBefore[1] = wine[1];
didAteBefore[2] = wine[1] + wine[2];
didAteBeforeBefore[2] = wine[0] + wine[2];
didAteBeforeBeforeBefore[2] = wine[2];
if (n==2 ){
cout << max(didAteBefore[1], max(didAteBefore[2], didAteBeforeBefore[2]));
return 0;
}
for (int i = 3; i<n; i++){
didAteBefore[i] = max(didAteBeforeBefore[i-1], didAteBeforeBeforeBefore[i-1]) + wine[i];
didAteBeforeBefore[i] = max(didAteBefore[i-2], max( didAteBeforeBefore[i-2], didAteBeforeBeforeBefore[i-2])) + wine[i];
didAteBeforeBeforeBefore[i] = max(didAteBefore[i-3], max(didAteBeforeBefore[i-3], didAteBeforeBeforeBefore[i-3])) + wine[i];
}
long a = max (max(didAteBefore[n-1], didAteBeforeBefore[n-1]), didAteBeforeBeforeBefore[n-1]);
long b = max (max(didAteBefore[n-2], didAteBeforeBefore[n-2]), didAteBeforeBeforeBefore[n-2]);
cout << max(a,b);
return 0;
}