package BOJ.DP;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* BOJ 2579
* https://www.acmicpc.net/problem/2579
*/
public class BOJ_2579 {
private static int[] arr;
private static int[] answer;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
arr = new int[n+1];
answer = new int[n+1];
for(int i=1; i<=n; i++){
arr[i] = Integer.parseInt(br.readLine());
}
// D(n) : n번째 계단 밟는 최대 점수
// n-1 밟는 경우 : D(n-3) + P(n-1) + P(n)
// n-2 밟는 경우 : D(n-2) + P(n)
// D(n) = max ( D(n-3) + P(n-1) + P(n), D(n-2) + P(n) )
solve(n);
System.out.println(answer[n]);
}
private static void solve(int n) {
answer[1] = arr[1];
answer[2] = arr[1] + arr[2];
for(int i=3; i<=n; i++){
answer[i] = Math.max(answer[i-3]+arr[i-1]+arr[i],answer[i-2]+arr[i]);
}
}
}