#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
//constexpr ll MOD = 1e9 + 7;
constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll loopcnt = 0;
vector<vector<ll>> G;
vector<ll> visited;
void dfs(ll sv, ll V)
{
  if (visited.at(V) != -1)
  {
    if (visited.at(V) == sv)
    {
      //cerr << sv << " " << V << endl;
      loopcnt++;
    }

    return;
  }
  visited.at(V) = sv;

  for (auto nv : G.at(V))
  {
    dfs(sv, nv);
  }
}

int main()
{
  ll N;
  cin >> N;
  G.resize(N);
  for (ll u = 0; u < N; u++)
  {
    ll v;
    cin >> v;
    v--;
    G.at(u).push_back(v);
  }

  visited.resize(N);
  fill(visited.begin(), visited.end(), -1);
  for (ll v = 0; v < N; v++)
  {
    if (visited.at(v) == -1)
      dfs(v, v);
  }

  ll ans = 1;
  for (ll i = 0; i < loopcnt; i++)
  {
    ans *= 2, ans %= MOD;
  }
  ans = mod(ans - 1, MOD);
  cout << ans << endl;
  //cerr << loopcnt << endl;
}
// We can calculate the number of inversions in the original array in a number of ways, such as with a Fenwick tree or with merge sort.
// Now, notice that each of the resulting sequences essentially remove the first element of the previous sequence and insert it at the end of it. 
// This changes the number of inversions in the new sequence by n−1−2ai for each i from 0 to N−2.


// Time complexity: O(NlogN for calculating inversions  )
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int maxn = (int)3e5+5;
int n,a[maxn],b[maxn],c[maxn];
 
ll find_inversions(int l, int r) {
    if (l == r)
        return 0;
    int m = l+ ((r-l)>>1), x = l, y = m+1;
    ll ans = find_inversions(l, m) + find_inversions(m+1, r);
    for (int i = l; i <= r; i++) {
        if (x > m)
            c[i] = b[y++];
        else if (y>r)
            c[i] = b[x++];
        else if (b[x]>b[y]) {
            c[i] = b[y++];
            ans += m-x+1;
        }
        else
            c[i] = b[x++];
    }
    for (int i = l; i <= r; i++)
        b[i] = c[i];
    return ans;
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    ll cur = find_inversions(0,n-1);
    cout << cur << "\n";
    for (int i = 0; i+1 < n; i++) {
        cur += n-1 - 2*a[i];
        cout << cur << "\n";
    }
    return 0;
}