package yukicoder; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; public class N45 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int del, i, a, b; ArrayList sushies = new ArrayList(); LinkedList queue = new LinkedList(); LinkedList visited = new LinkedList(); if(n == 1){ System.out.println(sc.nextInt()); return; } for(i = 0;i < n;++i){ del = sc.nextInt(); sushies.add(del); visited.add(0); } visited.set(0, sushies.get(0)); queue.add(0); queue.add(1); i = 0; while(true){ i = queue.poll(); if(visited.get(i) > sushies.get(i)){ del = visited.get(i); }else{ del = sushies.get(i); } a = i + 2; b = i + 3; if(a < n && visited.get(a) < del + sushies.get(a)){ visited.set(a, del + sushies.get(a)); queue.offer(a); } if(b < n && visited.get(b) < del + sushies.get(b)){ visited.set(b, del + sushies.get(b)); queue.offer(b); } if(queue.size() < 1){ System.out.println(Collections.max(visited)); return; } } } }