#include #define int long long #define vi vector #define debug(x) cout << #x << " = " << x << "\n"; #define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n"; #define fi first #define sc second using namespace std; void solve() { int n; cin >> n; vector> a(n); for(int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } if(n == 1) { cout << a[0].first << endl; return; } if(n <= 2) { cout << max(a[0].first, a[1].first) << endl; return; } sort(a.begin(), a.end(), greater>()); if(abs(a[0].second - a[1].second) <= 1) { cout << a[0].first + a[2].first << endl; return; } else { cout << a[0].first + a[1].first << endl; return; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while (t--) { solve(); } }