#define f(k)d[2*i+k][j+3]+max(d[2*i+3-k][j+1],0ll) ll n,d[3d5][27];{rd(n,*d(n));rrep(i,n)rep(j,24)d[i][j+2]=max(f(1),f(2))+*d[i]*(j-7);wt(d[0][9]);}