#include #include #include #include #include using namespace std; using mint=atcoder::modint998244353; using dat=pair; dat op(dat a,dat b) { a.first+=b.first; a.second+=b.second; return a; } dat e(){return make_pair(mint::raw(0),0);} dat mp(int f,dat x) { if(f>=0)x.first=x.second*mint(f); return x; } int cmp(int f,int g){return f>=0?f:g;} int id(){return -1;} int N; int A[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; for(int i=0;i>A[i]; mint ans=0,ret=0; atcoder::lazy_segtreesegmax(N),segmin(N); vector >mx,mn; mx.push_back(make_pair(N,(int)1e9)); mn.push_back(make_pair(N,0)); for(int i=N;i--;) { segmax.set(i,make_pair(A[i],1)); segmin.set(i,make_pair(A[i],1)); {//max while(mx.back().secondA[i]) { int l=mn.back().first; int a=mn.back().second; mn.pop_back(); ans-=segmax.prod(l,mn.back().first).first*a; } segmin.apply(i,mn.back().first,A[i]); ans+=segmax.prod(i+1,mn.back().first).first*A[i]; mn.push_back(make_pair(i,A[i])); } ans+=mint(A[i])*A[i]; ret+=ans; } cout<