#include <bits/stdc++.h>
constexpr int DEBUG = 0;
using namespace std;
using int64 = long long;
#define REPEAT(i, l, r) for (int i = (int)(l); i < (int)(r); i++)

constexpr int64 P = 998244353;

class FF {
 private:
  int64 x_;
  void Normalize() {
    if (0 <= x_ && x_ < P) { return; } x_ %= P; if (x_ < 0) { x_ += P; }
  }
 public:
  FF(int64 x) : x_(x) { Normalize(); }
  FF() : x_(0) {}
  int64 Value() const { return x_; }
  FF operator+(FF o) const { FF r(*this); r += o; return r; }
  FF operator-(FF o) const { FF r(*this); r -= o; return r; }
  FF operator* (FF o) const { FF r(*this); r *= o; return r; }
  FF operator/ (FF o) const { return (*this) * o.Power(P - 2); }
  void operator+= (FF o) { x_ += o.x_; if (x_ >= P) x_ -= P; }
  void operator-= (FF o) { x_ -= o.x_; if (x_ < 0) x_ += P; }
  void operator*= (FF o) { x_ = (x_ * o.x_) % P; }
  FF Power(int64 p) const {
    if (p < 0) { return Power(-p); } FF x(*this), r(1);
    while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
  }
};
ostream& operator<<(ostream& s, const FF& x) { s << x.Value(); return s; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vector<int> fs(n);
  REPEAT(i, 0, n) {
    cin >> fs[i];
    fs[i]--;
  }

  vector<int> ts(n, -1);
  int t = 0;
  vector<int> cs;
  REPEAT(s, 0, n) {
    if (ts[s] >= 0) continue;
    ts[s] = t;
    t++;
    int v = fs[s];
    while (true) {
      if (ts[v] >= 0) {
        if (ts[v] >= ts[s]) {
          cs.push_back(t - ts[v]);
        }
        break;
      } else {
        ts[v] = t;
        t++;
        v = fs[v];
      }
    }
  }
  FF ans = FF(2).Power(cs.size()) - 1;
  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=998244353;

const int N=2e5+10;
vector<ll> a[N];
vector<bool> vis(N);

ll dfs(ll v){
    vis[v]=true;
    ll s=1;
    for(ll u: a[v]){
        if(!vis[u])
            s+=dfs(u);
    }
    return s;
}

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll r;
        cin>>r; r--;
        a[r].pb(i);
        a[i].pb(r);
    }
    ll ans=1;
    for(ll i=0;i<n;i++){
        if(!vis[i]){
            ll num=dfs(i);
            ans=ans*2%mod;
        }
    }
    ans=(ans-1+mod)%mod;
    cout<<ans;


    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}