#include using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,tuple&a){is>>std::get<0>(a)>>std::get<1>(a)>>std::get<2>(a);return is;} templateistream &operator>>(istream &is,array&a){for(auto&i:a)is>>i;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define overload3(_1,_2,_3,name,...) name #define rep1(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__) #define reps(i,l,r) rep2(i,l,r) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcountll(x) #define fin(x) return cout<<(x)<<'\n',static_cast(0) #define yn(x) cout<<((x)?"Yes\n":"No\n") #define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end()) template inline int fkey(vector&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();} ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } #ifdef LOCAL #include #else #define debug(...) static_cast(0) #define debugg(...) static_cast(0) templateostream &operator<<(ostream &os,const pair&p){os<>testcase; for(int i=0;i #include template constexpr std::enable_if_t::digits<=32,int>msb(T n){return n==0?-1:31-__builtin_clz(n);} template constexpr std::enable_if_t<(std::numeric_limits::digits>32),int>msb(T n){return n==0?-1:63-__builtin_clzll(n);} template constexpr std::enable_if_t::digits<=32,int>lsb(T n){return n==0?-1:__builtin_ctz(n);} template constexpr std::enable_if_t<(std::numeric_limits::digits>32),int>lsb(T n){return n==0?-1:__builtin_ctzll(n);} template constexpr std::enable_if_t,T>floor_pow2(T n){return n==0?0:T(1)< constexpr std::enable_if_t,T>ceil_pow2(T n){return n<=1?1:T(1)<<(msb(n-1)+1);} template constexpr T safe_div(T a,T b){return a>=0?a/b:-((-a+b-1)/b);} template struct SparseTable{ using S=typename M::S; private: std::vectordat,prefix,suffix; std::vector>sp; public: SparseTable(){} SparseTable(std::vectora):dat(a){ int n=a.size(); n=(n+(1<d2(n>>L,M::e()); for(int i=0;i>L);i++){ for(int j=1;j<(1<>L)-1;i>=0;i--){ for(int j=(1<=1;j--)suffix[(i<=j-w;k--)sp[i][k]=M::op(d2[k],sp[i][k+1]); int r=std::min(d2.size(),j+w); for(int k=j+1;k>L,rid=r>>L; if(lid==rid){ S ret=M::e(); for(int i=l;i<=r;i++)ret=M::op(ret,dat[i]); return ret; } else{ lid++; rid--; S mid=M::e(); if(lid==rid)mid=sp[0][lid]; else if(lid struct MaxRangeSum{ static constexpr T minf=std::numeric_limits::min()/2; struct S{ T sum,ans,left,right; S():sum(0),ans(allow_empty?0:minf),left(allow_empty?0:minf),right(allow_empty?0:minf){} S(T v_):sum(v_),ans(allow_empty?std::max(v_,0):v_),left(allow_empty?std::max(v_,0):v_),right(allow_empty?std::max(v_,0):v_){} }; static inline S op(const S&x,const S&y){ S res; res.sum=x.sum+y.sum; res.ans=std::max(x.ans,y.ans); if(res.ansa){ vector::S>init(a.size()); rep(i,a.size())init[i]=a[i]; SparseTable>sp(init); ll res=-1e18; rep(i,1,a.size())chmax(res,sp.prod(0,i).ans*sp.prod(i,a.size()).ans); return res; } void SOLVE(){ int n; cin>>n; vectora(n); cin>>a; ll ans=solve(a); rep(i,n)a[i]=-a[i]; chmax(ans,solve(a)); cout<