func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 400004;   const long long Mod = 1000000007;   int Stop, Bcnt, Dindex, Ecnt;   int Low[N], Dfn[N], Step[N], Belong[N];   bool instack[N];   struct Edge {     int t;     int next;   } edge[N];   int head[N];   void addEdge(int s, int t) {     edge[Ecnt].t = t;     edge[Ecnt].next = head[s];     head[s] = Ecnt++;   }   void tarjan(int i) {     int j;     Dfn[i] = Low[i] = ++Dindex;     instack[i] = true;     Step[++Stop] = i;     for (int e = head[i]; e != -1; e = edge[e].next) {       j = edge[e].t;       if (!Dfn[j]) {         tarjan(j);         if (Low[j] < Low[i]) Low[i] = Low[j];       } else if (instack[j] && Dfn[j] < Low[i])         Low[i] = Dfn[j];     }     if (Dfn[i] == Low[i]) {       Bcnt++;       do {         j = Step[Stop--];         instack[j] = false;         Belong[j] = Bcnt;       } while (j != i);     }   }   void init() {     Ecnt = 0;     memset(head, -1, sizeof(head));   }   void solve(int n) {     int i;     Stop = Bcnt = Dindex = 0;     memset(Dfn, 0, sizeof(Dfn));     memset(Low, -1, sizeof(Low));     memset(instack, 0, sizeof(instack));     for (i = 1; i <= n; i++) {       if (!Dfn[i]) {         tarjan(i);       }     }   }   long long num[N];   long long Pow(int x, int y) {     long long a = (long long)x;     long long b = y;     long long ans = 1;     if (b == 0) return 1ll;     while (b > 0) {       if (b & 1) {         ans = (ans * (long long)a) % Mod;       }       a *= a;       a %= Mod;       b >>= 1;     }     return ans;   }   int main() {     int n, x;     while (~scanf( %d , &n)) {       init();       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         addEdge(i, x);       }       solve(n);       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         num[Belong[i]]++;       }       long long ans = 1;       for (int i = 1; i <= n; i++) {         if (num[i]) {           if (num[i] == 1) {             ans = (ans * 2) % Mod;           } else {             long long tm = ((Pow(2, num[i]) - 2) % Mod + Mod) % Mod;             ans = ans * tm % Mod;           }         }       }       printf( %I64d n , ans);     }     return 0;   }   