#include #include using namespace std; using namespace atcoder; using ll=long long; using mint=modint998244353; mint op(mint x,mint y){ return x+y; } mint e(){ return 0; } mint mapping(mint x,mint y){ return x*y; } mint composition(mint x,mint y){ return x*y; } mint id(){ return 1; } int main() { int n; cin>>n; vector a(n); for(int i=0;i>a[i]; deque deq[2]; mint ans=a[0]*a[0],sum=a[0]*a[0]; lazy_segtree lst0(n),lst1(n); deq[0].push_back(0); deq[1].push_back(0); lst0.set(0,a[0]); lst1.set(0,a[0]); for(int i=1;ia[i]){ int x=deq[0].back(); deq[0].pop_back(); if(deq[0].empty())p=0; else p=deq[0].back()+1; sum-=(a[x]-a[i])*lst1.prod(p,x+1); lst0.apply(p,x+1,(mint)a[i]/a[x]); } deq[0].push_back(i); while(!deq[1].empty()&&a[deq[1].back()]