// www.codechef.com/users/akshith1005
import java.util.*;
public class Main {
public static void main
(String[] args
) { new Main();
}
public Main() {
Scanner sc
= new Scanner
(System.
in); int N = sc.nextInt();
/************************/
int a[] = new int[200000];
for(N=0; sc.hasNextInt(); ++N){
a[N]=sc.nextInt();
}
/************************/
if(N<=3){
}
else{
int b[] = new int[N];
b[0]=a[0];
b[1]=a[1];
b[2]=a[2];
for(int i=3;i<N;++i){
int x = b[i-1]>b[i-2] ? b[i-2]:b[i-1];
int y = b[i-3]>x ? x : b[i-3];
b[i]= y+a[i];
}
int x = b[N-1]>b[N-2] ? b[N-2]:b[N-1];
int y = b[N-3]>x ? x : b[N-3];
}
}
}
Ci8vIHd3dy5jb2RlY2hlZi5jb20vdXNlcnMvYWtzaGl0aDEwMDUKCmltcG9ydCBqYXZhLnV0aWwuKjsKIApwdWJsaWMgY2xhc3MgTWFpbiB7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgkJbmV3IE1haW4oKTsKCX0KCQoJcHVibGljIE1haW4oKSB7CgkJU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgICAgICAgICBpbnQgTiA9IHNjLm5leHRJbnQoKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgLyoqKioqKioqKioqKioqKioqKioqKioqKi8KICAgICAgICAgICAgICAgIGludCBhW10gPSBuZXcgaW50WzIwMDAwMF07CiAgICAgICAgICAgICAgICBmb3IoTj0wOyBzYy5oYXNOZXh0SW50KCk7ICsrTil7CiAgICAgICAgICAgICAgICAgICAgYVtOXT1zYy5uZXh0SW50KCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAvKioqKioqKioqKioqKioqKioqKioqKioqLwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpZihOPD0zKXsKICAgICAgICAgICAgICAgICAgICBBcnJheXMuc29ydChhKTsKICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYVswXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlewogICAgICAgICAgICAgICAgICAgIGludCBiW10gPSBuZXcgaW50W05dOwogICAgICAgICAgICAgICAgICAgIGJbMF09YVswXTsKICAgICAgICAgICAgICAgICAgICBiWzFdPWFbMV07CiAgICAgICAgICAgICAgICAgICAgYlsyXT1hWzJdOwogICAgICAgICAgICAgICAgICAgIGZvcihpbnQgaT0zO2k8TjsrK2kpewogICAgICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IGJbaS0xXT5iW2ktMl0gPyBiW2ktMl06YltpLTFdOwogICAgICAgICAgICAgICAgICAgICAgICBpbnQgeSA9IGJbaS0zXT54ID8geCA6IGJbaS0zXTsKICAgICAgICAgICAgICAgICAgICAgICAgYltpXT0geSthW2ldOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IGJbTi0xXT5iW04tMl0gPyBiW04tMl06YltOLTFdOwogICAgICAgICAgICAgICAgICAgIGludCB5ID0gYltOLTNdPnggPyB4IDogYltOLTNdOwogICAgICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih5KTsKICAgICAgICAgICAgICAgIH0KCX0KCQp9IA==