#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,           \
       tree_order_statistics_node_update>

#define ll long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define el '\n'
#define sz(a) (int)(a).size()
#define pi acos(-1)
// #define int ll

#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 0
#define debug_itr(...) 0
#define debug_bits(...) 0
#endif

const ll mod = 998244353, N = 3e5 + 5;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n), pre(n + 1);
  for (int &i : a)
    cin >> i;
  vector<int> cnt(n);
  ordered_set s;
  for (int i = n - 1; i >= 0; --i) {
    cnt[i] = sz(s) - s.order_of_key({a[i], i});
    s.insert({a[i], i});
  }
  debug(cnt);

  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1] * 2 + 1;
    pre[i] %= mod;
  }
  sort(all(a));
  debug(a);

  ll ans = 0;
  for (int &i : cnt) {
    ans = (ans % mod + pre[i] % mod) % mod;
  }
  cout << ans << el;
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
#ifdef LOCAL
  debug((float)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}