#include using namespace std; using ll = int64_t; #define fi first #define se second int main(){ ll n,mod=998244353; cin>>n; ll a[n]; for(int i=0;i>a[i]; } ll ans=0,x,y; int countx,county; for(int j=1;ja[j]){ x+=a[i]; countx++; } } for(int k=j+1;ka[k]){ y+=a[k]; county++; } } x%=mod; y%=mod; ans+=x*county+y*countx+countx*county*a[j]; ans%=mod; } cout<