#include using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i) #define rep(i, n) FOR(i, 0, n) #define rep1(i, n) FOR(i, 1, int(n) + 1) #define rrep(i, n) RFOR(i, 0, n) #define rrep1(i, n) RFOR(i, 1, int(n) + 1) #define all(c) begin(c), end(c) template void __dump__(const T &first){ std::cerr << first << std::endl; } template void __dump__(const First& first, const Rest&... rest) { std::cerr << first << ", "; __dump__(rest...); } #define dump(...) { std::cerr << __LINE__ << ":\t" #__VA_ARGS__ " = "; __dump__(__VA_ARGS__); } #define int ll int n; vector a; signed main(){ while(cin >> n){ a.resize(n); rep(i, n){ cin >> a[i]; } int ans = 1e18; rep(_, 2){ rep(i, n){ // dump(i); int x = i; int time = a[x]; rep(j, n - 1){ int nx = (x + 1) % n; time = max(time + abs(x - nx), a[nx]); x = nx; // dump(time); } ans = min(ans, time); } reverse(all(a)); } cout << ans << endl; } }