#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 (l > 0 || r < n-1) { ll lval = l-1 >= 0 ? arr[l-1] : DINF; ll rval = r+1 < n ? arr[r+1] : DINF; if (lval < rval) { 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]; } int mx = 0; rep(i,1,n) { if (arr[i] > arr[mx]) { mx = i; } } vector tmp(n); rep(i,0,n) { tmp[i] = arr[(i+mx)%n]; } arr = tmp; ll best = DINF; rep(i,0,n) { best = min(best, opt(i)); } cout << best << endl; return 0; }