#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, cnt = 1; while (cnt < n) { ll lval = l == 0 ? arr[n-1] : arr[l-1]; ll rval = r == n-1 ? arr[0] : arr[r+1]; if (lval < rval) { res = max(lval-now, res); now += lval; l--; if (l == -1) l = n-1; } else { res = max(rval-now, res); now += rval; r++; if (r == n) r = 0; } cnt++; } return res; } int main() { cin >> n; arr = vector(n); rep(i,0,n) { cin >> arr[i]; } ll best = DINF; rep(i,0,n) { best = min(best, opt(i)); } cout << best << endl; return 0; }