#include #include #include using namespace std; int main() { int N; cin >> N; vector V(N); for (int i = 0; i < N; i++) { cin >> V[i]; } int m = 0; if (N == 1) { m = V[0]; } else { int c = 0; for (int i = 0; i < N-1; i++) { m += max(V[c], V[c+1]); if (V[c] > V[c+1]) c += 2; else c += 2+1; } } cout << m << endl; return 0; }