using System; using System.Collections.Generic; namespace lecture { class MainClass { // 再帰関数 // 戻り値として候補の最大値を取得する。 // 寿司の美味しさ(A)と現在食べる場所(current)を引数にする public static int recursive(int[] A, int current) { int point = A[current]; int P1 = 0; int P2 = 0; // 2つ先を食べる if (current + 2 < A.Length) { P1 = recursive(A, current + 2); } // 3つ先を食べるか if (current + 3 < A.Length) { P2 = recursive(A, current + 3); } if (P1 > P2) { return point + P1; } else { return point + P2; } } public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = new int[N]; string[] row = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { A[i] = int.Parse(row[i]); } int P1 = 0; P1 = recursive(A, 0); int P2 = 0; // 2皿以上ある場合 if (A.Length > 1) { P2 = recursive(A, 1); } if (P1 > P2) { Console.WriteLine(P1); } else { Console.WriteLine(P2); } } } }