#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > graph, revgraph;
bool visit[200005];
stack<long long int> s;
long long int c;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int k = power(a, b / 2);
  if ((b % 2) == 0)
    return (k * k) % 1000000007;
  else
    return (((a * k) % 1000000007) * k) % 1000000007;
}
void firstpass(int i) {
  int j;
  visit[i] = true;
  for (j = 0; j < graph[i].size(); j++) {
    if (!visit[graph[i][j]]) firstpass(graph[i][j]);
  }
  s.push(i);
}
void secondpass(int i) {
  visit[i] = true;
  c++;
  for (int j = 0; j < revgraph[i].size(); j++) {
    if (!visit[revgraph[i][j]]) secondpass(revgraph[i][j]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  long long int n, i, k;
  cin >> n;
  graph.resize(n + 1);
  revgraph.resize(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> k;
    graph[i].push_back(k);
    revgraph[k].push_back(i);
  }
  memset(visit, false, sizeof(visit));
  for (i = 1; i <= n; i++) {
    if (!visit[i]) firstpass(i);
  }
  memset(visit, false, sizeof(visit));
  long long int ans = 1;
  while (!s.empty()) {
    i = s.top();
    if (!visit[i]) {
      c = 0;
      secondpass(i);
      if (c == 1)
        ans *= 2;
      else
        ans *= (power(2, c) - 2);
      ans %= 1000000007;
    }
    s.pop();
  }
  cout << ans << "\n";
}
