#include //#include using namespace std; using ll = long long; ll MOD = 998244353; class BIT{ public: vectortree; int n; BIT(int n){ this->n = n; tree.assign(n+1,0); } void add(int a,ll w){ a++; for(int x=a;x<=n;x += x&-x)(tree[x] += w)%=MOD; } ll sum(int a){ if(a==0)return 0; ll ret = 0; for(int x = a; x>0; x -= x&-x)(ret+=tree[x])%=MOD; return ret; } }; int main() { int n; cin >> n; vector a(n); map atoidx,idxtoa; vector l(n),x(n),r(n),y(n); for(auto &i:a)cin >> i; { set zaatu; for(auto &i:a)zaatu.insert(i); int idx = 0; for(auto &i:zaatu){ atoidx[i]=idx; idxtoa[idx]=i; idx++; } BIT bitlr(n),bitxy(n); for(int i = 0;i=0;i--){ ll idx = atoidx[a[i]]; bitlr.add(idx,1); bitxy.add(idx,a[i]); r[i]=bitlr.sum(idx); y[i]=bitxy.sum(idx); } //for(auto &i:r)cout<