#include <bits/stdc++.h>
using namespace std;
int a[200004];
int n;
vector<int> g[200004];
int low[200004];
int num[200004];
int cur;
int vis[200004];
vector<int> s;
long long int ans = 1;
long long int fastexp(int p) {
  long long int res;
  if (p == 0)
    return 1;
  else if (p % 2 == 0) {
    res = fastexp(p / 2);
    return (res * res) % 1000000007;
    ;
  } else {
    res = fastexp(p / 2);
    return ((res * res) * 2) % 1000000007;
    ;
  }
}
void dfs(int u) {
  low[u] = ++cur;
  num[u] = cur;
  vis[u] = 1;
  s.push_back(u);
  int i;
  int v;
  v = a[u];
  if (!num[v]) dfs(v);
  if (vis[v]) low[u] = min(low[u], low[v]);
  if (low[u] == num[u]) {
    int cnt = 1;
    v = s.back();
    vis[v] = 0;
    while (v != u) {
      cnt++;
      s.pop_back();
      v = s.back();
      vis[v] = 0;
    }
    if (cnt > 1) {
      ans = ans * (fastexp(cnt) - 2);
      ans = ans % 1000000007;
      ;
    } else
      ans = (ans * 2) % 1000000007;
    ;
  }
}
int main() {
  scanf("%d", &n);
  int i, u;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    if (!num[i]) dfs(i);
  }
  printf("%I64d", ans);
  return 0;
}
