#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(!ismin) a*=(-1), b*=(-1); if(deq.empty()){ deq.push_back({a, b}); return; } if(deq.back().first>=a){ if(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}); }else{ while(deq.size()>1){ T a1=deq.front().first, b1=deq.front().second; T a2=deq[1].first, b2=deq[1].second; if((b1-b2)*(a1-a)>(b-b1)*(a2-a1)) break; deq.pop_front(); } deq.push_front({a, b}); } } T get(T x, bool isinc){ if(isinc){ 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+b11){ T a1=deq.back().first, b1=deq.back().second; T a2=deq[deq.size()-2].first, b2=deq[deq.size()-2].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; const ll INF=1e18; ll mn=INF; for(int i=r; i>=m; i--){ cht.add(-2*(i+1), (ll)(i+1)*(i+1)+s[i+1]); } for(int i=l; i<=m; i++){ mn=min(mn, (ll)cht.get(i, true)+(ll)i*i-s[i]); ans[i]=min(ans[i], mn); } cht.clear(); mn=INF; for(int i=m; i>=l; i--){ cht.add(-2*i, (ll)i*i-s[i]); } for(int i=r; i>=m; i--){ mn=min(mn, (ll)cht.get(i+1, false)+(ll)(i+1)*(i+1)+s[i+1]); 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