#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; template struct ConvexHullTrickMonotone{ using P=pair; deque

deq; ConvexHullTrickMonotone(){} void add(T a, T b){ if(!deq.empty() && deq.back().first==a && deq.back().second<=b) return; while(deq.size()>1){ T a1=deq.back().first, b1=deq.back().second; T a2=deq[deq.size()-2].first, b2=deq[deq.size()-2].second; if((b1-b2)*(a1-a)<(b-b1)*(a2-a1)) break; deq.pop_back(); } deq.push_back({a, b}); } T get(T x){ while(deq.size()>1){ T a1=deq.front().first, b1=deq.front().second; T a2=deq[1].first, b2=deq[1].second; if(a1*x+b1r) return; if(l==r){ ans[l]=min(ans[l], 1+a[l]); return; } int m=(l+r)/2; ConvexHullTrickMonotone cht; vector vm1(m-l+1), vm2(r-m+1); for(int i=m; i<=r; i++){ cht.add(-2*(i+1), (ll)(i+1)*(i+1)+s[i+1]); } for(int i=l; i<=m; i++){ vm1[i-l]=cht.get(i)+(ll)i*i-s[i]; } ll mn=1e18; for(int i=l; i<=m; i++){ mn=min(mn, vm1[i-l]); ans[i]=min(ans[i], mn); } cht.clear(); for(int i=l; i<=m; i++){ cht.add(-2*i, (ll)i*i-s[i]); } for(int i=m; i<=r; i++){ vm2[i-m]=cht.get(i+1)+(ll)(i+1)*(i+1)+s[i+1]; } mn=1e18; for(int i=r; i>=m; i--){ mn=min(mn, vm2[i-m]); ans[i]=min(ans[i], mn); } solve(l, m-1); solve(m+1, r); } int main() { cin>>n; s[0]=0; for(int i=0; i>a[i]; s[i+1]=s[i]+a[i]; } const ll INF=1e18; fill(ans, ans+n, INF); solve(0, n-1); for(int i=0; i