include bits stdc using namespace std define MAXN 10000000 int int cos

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
using namespace std;
#define MAXN 10000000
int n;
int cost[MAXN], dp[MAXN][2];
class fastio {
public:
fastio() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
} __fastio;
int f(int i, int p) {
if(i > n) return 0;
if(dp[i][p] != -1) return dp[i][p];
if(p == 1) return dp[i][p] = f(i+1,0) + cost[i];
if(p == 0) return dp[i][p] = min(f(i+1,0) + cost[i], f(i+1,1));
}
void solve() {
cin >> n;
for(int i=1; i<=n; i++) {
int in; cin >> in;
cost[i] = cost[i+n] = in;
}
memset(dp, -1, sizeof(dp));
cout << max(f(1,0),f(1,1)) << endl;
}
int main() {
__fastio;
solve();
return 0;
}