//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include //#include //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int mod = 998244353; const int bm = 200201; ll BIT00[bm], BIT01[bm], BIT10[bm], BIT11[bm]; void add00(int A) { while (A <= bm) { BIT00[A]++; A += A & -A; } } int query00(int A) { int ret = 0; while (A > 0) { ret += BIT00[A]; A -= A & -A; } return ret; } void add01(int A, ll B) { while (A <= bm) { BIT01[A] += B; A += A & -A; } } ll query01(int A) { ll ret = 0; while (A > 0) { ret += BIT01[A]; A -= A & -A; } return ret; } void add10(int A) { while (A > 0) { BIT10[A]++; A -= A & -A; } } int query10(int A) { int ret = 0; while (A <= bm) { ret += BIT10[A]; A += A & -A; } return ret; } void add11(int A, ll B) { while (A > 0) { BIT11[A] += B; A -= A & -A; } } ll query11(int A) { ll ret = 0; while (A <= bm) { ret += BIT11[A]; A += A & -A; } return ret; } void zaatu(int N, ll A[]) { ll tmp[200000]; rep(i, N) tmp[i] = A[i]; sort(tmp, tmp + N); rep(i, N) A[i] = lower_bound(tmp, tmp + N, A[i]) - tmp + 1; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll A[200000], B[200000]; rep(i, N) { cin >> A[i]; B[i] = A[i]; } zaatu(N, A); ll amae[200000], bmae[200000], aato[200000], bato[200000]; rep(i, N) { amae[i] = query10(A[i] + 2); bmae[i] = query11(A[i] + 2); add10(A[i] + 1); add11(A[i] + 1, B[i]); } for (int i = N - 1; i >= 0; i--) { aato[i] = query00(A[i] + 1); bato[i] = query01(A[i] + 1); add00(A[i] + 2); add01(A[i] + 2, B[i]); } ll kotae = 0; rep(i, N) { kotae += B[i] * amae[i] % mod * aato[i] % mod; kotae += bmae[i] % mod * aato[i] % mod; kotae += bato[i] % mod * amae[i] % mod; } co(kotae% mod); Would you please return 0; }