#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = map(int, read().split()) assert N == len(A) def calc_dp(A): """時刻 t に左端を出発して全部拾っていった場合に、そのセルのものを拾う時刻。max(t + i, x)""" dp = [-1] * N for i, x in enumerate(A): dp[i] = max(dp[i - 1] + 1, x) return dp dp1 = calc_dp(A) dp2 = calc_dp(A[::-1])[::-1] def gen_cand(): global dp1, dp2 for _ in range(2): dp1, dp2 = dp2[::-1], dp1[::-1] yield dp1[-1] for i, (x, y) in enumerate(zip(dp1, dp2[1:])): yield max(y, x + 2 * (N - i) - 3) answer = min(gen_cand()) print(answer)