#include using namespace std; #define rep(i,a,b) for (auto i=(a); i<(b); ++i) #define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it) typedef pair ii; typedef vector vi; typedef vector vii; typedef vector vvi; typedef long long ll; const int INF = 2147483647; const ll DINF = 9000000000000000000; int n; vector arr; // Optimal solution starting at the given index ll opt(int at) { ll res = arr[at], now = arr[at]; int l = at, r = at; while (r-l+1 < n) { if (arr[l-1] < arr[r+1]) { res = max(arr[l-1]-now, res); now += arr[l-1]; l--; } else { res = max(arr[r+1]-now, res); now += arr[r+1]; r++; } } return res; } int main() { cin >> n; arr = vector(n); rep(i,0,n) { cin >> arr[i]; } rep(i,0,n) { arr.push_back(arr[i]); } rep(i,0,n) { arr.push_back(arr[i]); } ll best = DINF; rep(i,0,n) { best = min(best, opt(n+i)); } cout << best << endl; return 0; }