#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 100000 + 10;
const int maxv = 222222;
int V;
vector<int> G[maxv];
vector<int> rG[maxv];
vector<int> vs;
bool used[maxv];
int cmp[maxv];
void add_edge(int from, int to) {
  G[from].push_back(to);
  rG[to].push_back(from);
}
void dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); ++i) {
    if (!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}
void rdfs(int v, int k) {
  used[v] = true;
  cmp[v] = k;
  for (int i = 0; i < rG[v].size(); ++i) {
    if (!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}
int scc() {
  memset(used, 0, sizeof used);
  vs.clear();
  for (int v = 0; v < V; ++v) {
    if (!used[v]) dfs(v);
  }
  memset(used, 0, sizeof used);
  int k = 0;
  for (int i = vs.size() - 1; i >= 0; i--) {
    if (!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}
long long mypow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans;
}
int num[maxv];
int main() {
  scanf("%d", &V);
  for (int i = 0; i < V; ++i) {
    int x;
    scanf("%d", &x);
    add_edge(i, x - 1);
  }
  int mx = scc();
  memset(num, 0, sizeof num);
  for (int i = 0; i < V; ++i) {
    num[cmp[i]]++;
  }
  long long ans = 1, sum = 0;
  for (int i = 0; i < mx; ++i) {
    if (num[i] > 1) {
      ans *= mypow(2, num[i]) - 2;
      ans %= mod;
      sum += num[i];
    }
  }
  ans *= mypow(2, V - sum);
  printf("%I64d\n", (ans % mod + mod) % mod);
}
