//二分板子题
//二分时间T
//每一步都进行检查,看是否合格
//时间复杂度O(nlogn);
#include<cstdio>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long LL;
const int N=2e5+10;
int n;
LL a[N],b[N];
bool check(int x)
{
rep(i,1,n)
b[i]=a[i]-x;
LL s=x;
rep(i,2,n)
if(b[i]>0&&b[i-1]>0)
{
LL t=min({b[i-1],b[i],s});
s-=t,b[i-1]-=t,b[i]-=t;
if(s==0)break;
}
s+=x;
rep(i,1,n)
if(b[i]>0)s-=b[i];
return s>=0;
}
int main()
{
scanf("%d",&n);
rep(i,1,n)
scanf("%lld",&a[i]);
LL l=0,r=(int)2e9,ans=0;
while(l<=r)
{
LL mid=(l+r)>>1;
if(check(mid))ans=mid,r=mid-1;
else l=mid+1;
}
printf("%lld\n",ans);
return 0;
}