#include #include #include #include #include #include #include using namespace std; using mint = atcoder::modint998244353; mint op(mint a, mint b) { return a + b; } mint e() { return mint(0); } mint mapping(mint f, mint x) { return f * x; } mint composition(mint f, mint g) { return f * g; } mint id() { return mint(1); } vector sorted_idx(const vector &A) { auto n = A.size(); vector> tmp(n); for (size_t i = 0; i < n; i++) tmp[i] = {A[i], i}; sort(begin(tmp), end(tmp)); vector ret(n); for (size_t i = 0; i < n; i++) ret[i] = tmp[i].second; return ret; } vector cumulative_sum(const vector &A) { auto n = A.size(); atcoder::lazy_segtree lst(vector(n, 1)); vector ret(n); auto &&tmp = sorted_idx(A); for(auto &i : tmp) { ret[i] = lst.prod(0, i + 1) / lst.get(i); lst.apply(0, i+1, mint(2)); } return ret; } int main() { size_t n; cin >> n; vector A(n); for(size_t i = 0; i < n; i++) cin >> A[i]; auto &&x = cumulative_sum(A); reverse(begin(A), end(A)); auto &&y = cumulative_sum(A); reverse(begin(x), end(x)); mint ans; for(size_t i = 0; i < n; i++) { ans += x[i] * y[i] * A[i]; } cout << ans.val() << endl; }