#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- template struct ConvexHull { deque> Q; V calc(pair p, V x) { return p.first*x+p.second; } int dodo(pair A,pair B, pair C) { // max or min return ((__int128)(A.second-C.second)*(B.first-A.first)<=(__int128)(A.second-B.second)*(C.first-A.first)); } void add(V a, V b) { // add ax+b Q.push_back({a,b}); int v; while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1])) Q[v-2]=Q[v-1], Q.pop_back(); } V query(V x) { int L=-1,R=Q.size()-1; while(R-L>1) { int M=(L+R)/2; (((calc(Q[M],x)>=calc(Q[M+1],x)))?L:R)=M; } return calc(Q[R],x); } }; int N; int A[3030]; ll S[3030]; ll cost[3030][3030]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) { cin>>A[i+1]; S[i+1]=S[i]+A[i+1]; } FOR(x,N+2) FOR(y,N+2) cost[x][y]=1LL<<60; cost[0][0]=0; for(i=1;i<=N+1;i++) { ConvexHull ch; for(x=i;x<=N+1;x++) { ch.add(-2*S[x-1],cost[i-1][x-1]+S[x-1]*S[x-1]); cost[i][x]=ch.query(S[x-1])+S[x-1]*S[x-1]; } } for(i=1;i<=N;i++) cout<