#include <bits/stdc++.h>
using namespace std;
vector<long long int> graph[200001];
long long int vis[200001] = {0};
long long int len = 0;
bool ch = 0;
void dfs(int curr) {
  if (vis[curr] == 3) return;
  len++;
  vis[curr] = 3;
  dfs(graph[curr][0]);
}
void cycle(long long int curr) {
  if (vis[curr] == 1) {
    dfs(curr);
  }
  if (vis[curr] == 3 || vis[curr] == 2) {
    return;
  }
  vis[curr] = 1;
  cycle(graph[curr][0]);
  vis[curr] = 2;
  return;
}
long long int modi(long long int a, long long int n) {
  if (n == 0)
    return 1;
  else {
    if (n % 2 == 0) {
      long long int temp = modi(a, n / 2);
      return (temp * temp) % 1000000007;
    } else {
      return (a * modi(a, n - 1)) % 1000000007;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    long long int temp;
    cin >> temp;
    graph[i].push_back(temp);
  }
  vector<long long int> cy;
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      len = 0;
      ch = 0;
      cycle(i);
      if (len != 0) cy.push_back(len);
    }
  }
  long long int ans = 1;
  long long int count = 0;
  for (long long int i = 0; i < cy.size(); i++) {
    ans =
        (ans * (modi(2LL, cy[i]) - 2LL + 1000000007) % 1000000007) % 1000000007;
    count += cy[i];
    if (cy[i] == 1) cout << "YES" << endl;
  }
  ans = (ans * modi(2LL, n - count)) % 1000000007;
  cout << ans << endl;
  return 0;
}
