#include //#include //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector; using mat = vector; ll N,M,H,W,Q,K,A,B; string S; using P = pair; const ll INF = (1LL<<60); template bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template class modint{ public: ll x; constexpr modint(){x = 0;} constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){} constexpr modint set_raw(ll _x){ //_x in [0, mod) x = _x; return *this; } constexpr modint operator-(){ return x == 0 ? 0 : mod - x; } constexpr modint& operator+=(const modint& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr modint operator+(const modint& a) const{ return modint(*this) += a; } constexpr modint& operator-=(const modint& a){ if((x -= a.x) < 0) x += mod; return *this; } constexpr modint operator-(const modint& a) const{ return modint(*this) -= a; } constexpr modint& operator*=(const modint& a){ (x *= a.x)%=mod; return *this; } constexpr modint operator*(const modint& a) const{ return modint(*this) *= a; } constexpr modint pow(unsigned long long pw) const{ modint res(1), comp(*this); while(pw){ if(pw&1) res *= comp; comp *= comp; pw >>= 1; } return res; } //以下、modが素数のときのみ constexpr modint inv() const{ if(x == 2) return (mod + 1) >> 1; return modint(*this).pow(mod - 2); } constexpr modint& operator/=(const modint &a){ (x *= a.inv().x)%=mod; return *this; } constexpr modint operator/(const modint &a) const{ return modint(*this) /= a; } }; #define mod1 998244353 using mint = modint; ostream& operator<<(ostream& os, const mint& a){ os << a.x; return os; } using vm = vector; template class BIT { //T has operator "+=" and can be initialized with 0. unsigned int n; vector bitree; public: BIT(unsigned long _n) : bitree(_n + 1, 0) { n = _n; } void add(int id, T x) { ++id; while (id <= n) { bitree[id] += x; id += id & -id; } } T sum(int id) { ++id; T temp(0); while (id > 0) { temp += bitree[id]; id -= id & -id; } return temp; } void print(int sz = -1){ if(sz == -1) sz = n; rep(i, sz) cout<>N; vec a(N); priority_queue

pque; rep(i, N) { cin>>a[i]; pque.emplace(a[i], i); } BIT ni(N), si(N), nj(N), sj(N); mint ans(0); while(!pque.empty()){ P p = pque.top(); pque.pop(); //cout<