#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return SQR(POW(B, P / 2));
}
template <typename T>
inline T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T BMOD(T p, T e, T m) {
  T ret = 1;
  while (e) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
    e >>= 1;
  }
  return (T)ret;
}
vector<long long> adj[200007], r_adj[200007], stk;
long long vis[200007], nd, cy_sz = 0;
void dfs_1(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  int sz = adj[u].size(), x;
  for (int i = 0; i < sz; i++) {
    x = adj[u][i];
    if (!vis[x]) dfs_1(x);
  }
  stk.push_back(u);
  ;
  return;
}
void dfs_2(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  cy_sz++;
  int sz = r_adj[u].size(), x;
  for (int i = 0; i < sz; i++) {
    x = r_adj[u][i];
    if (!vis[x]) dfs_2(x);
  }
  return;
}
int scc() {
  long long ans = 1;
  memset(vis, 0, sizeof vis);
  for (int i = 1; i < nd + 1; i++) {
    if (!vis[i]) dfs_1(i);
  }
  memset(vis, 0, sizeof vis);
  reverse(stk.begin(), stk.end());
  int sz = stk.size(), u;
  for (int i = 0; i < sz; i++) {
    u = stk[i];
    if (!vis[u]) {
      cy_sz = 0;
      dfs_2(u);
      if (cy_sz == 1)
        ans = (ans * 2) % 1000000007LL;
      else
        ans = (ans * (BMOD(2LL, (long long)cy_sz, 1000000007LL) - 2)) %
              1000000007LL;
    }
  }
  return ans;
}
int main() {
  long long l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
  long long flg, sz, cnt, gt, ans, mx, mn;
  long long m, k, n;
  long long low, hi, md, inp[200007], sm, ff;
  scanf("%lld", &n);
  nd = n, n++;
  for (int i = 1; i < n; i++) {
    scanf("%lld", &a);
    adj[i].push_back(a);
    ;
    r_adj[a].push_back(i);
    ;
  }
  ans = scc();
  cout << ans << endl;
  return 0;
}
