#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--) #define PI acos(-1.0) #define DEBUG(C) cerr << C << endl; #define VI vector #define VII vector #define VL vector #define VLL vector #define VD vector #define VDD vector #define PII pair #define PDD pair #define PLL pair #define VPII vector #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort(ALL(a)) #define REVERSE(a) reverse(ALL(a)) #define MP make_pair #define EB emplace_back #define FORE(a, b) for (auto &&a : b) #define FIND(s, n) (s.find(n) != s.end()) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; int dp[1010][2]; //dp[i][j] = i皿目まで来ていてi皿目をとったとき(j = 1),取らなかった時(j = 0)の最大値 int main(void) { int N; cin >> N; VI V(N + 1); REP(i, N) cin >> V[i + 1]; dp[0][0] = dp[0][1] = 0; FOR(i, 1, N + 1) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max({dp[i - 1][0], dp[i - 2][0], dp[i - 2][1]}) + V[i]; } int ans = max(dp[N][0], dp[N][1]); cout << ans << endl; // VI ans; // RREP(i, N) { // // } // REVERSE(ans); // FORE(el, ans) { // cout << ans << " "; // } // cout << endl; }