#include <bits/stdc++.h>
struct compMinPQ {
  bool operator()(const int &a, const int &b) { return a > b; }
};
using namespace std;
vector<int> V[200010];
int arr[200010];
int back[200010];
bool instack[200010];
int t = 0, n;
vector<long long int> G;
void dfsC(int a, stack<int> &second) {
  int i;
  t++;
  arr[a] = back[a] = t;
  second.push(a);
  instack[a] = true;
  for (i = 0; i < V[a].size(); i++) {
    if (arr[V[a][i]] == -1) {
      dfsC(V[a][i], second);
      back[a] = min(back[a], back[V[a][i]]);
    } else if (instack[V[a][i]] == true)
      back[a] = min(back[a], arr[V[a][i]]);
  }
  int w = 0;
  if (back[a] == arr[a]) {
    long long int pp = 0;
    while (second.top() != a) {
      w = second.top();
      instack[w] = false;
      second.pop();
      pp++;
    }
    w = second.top();
    second.pop();
    pp++;
    G.push_back(pp);
    instack[w] = false;
  }
}
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b = b / 2;
  }
  return res;
}
void SCC() {
  stack<int> second;
  int i, j;
  for (i = 0; i < n; i++) {
    arr[i] = -1;
    back[i] = -1;
    instack[i] = false;
  }
  for (i = 0; i < n; i++)
    if (arr[i] == -1) dfsC(i, second);
}
int main() {
  cin >> n;
  long long int a;
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    V[i].push_back(a - 1);
  }
  SCC();
  long long int ans = 1;
  for (long long int i = 0; i < G.size(); i++) {
    if (G[i] > 1) {
      ans = (ans * (powmod(2, G[i]) - 2 + 1000000007)) % 1000000007;
    } else {
      ans = (ans * 2) % 1000000007;
    }
  }
  cout << ans << endl;
}
