import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
//SOLUTION BEGIN
int MXN = 71, cp = 0, mxMask = 0;
int[] prime, sz, fMask;
ArrayList
<Integer
>[] adj
= new ArrayList[MXN
]; long[][][] ANS,DP;
int n = ni();
for(int i = 1; i<= n; i++)adj[i] = new ArrayList<>();
for(int i = 2; i<= n; i++)adj[ni()].add(i);
//Working with primes.
//Finding all primes below n/2, since primes above n/2 will not matter as we cannot ever have two childs both with subtree size > n/2
prime = new int[11];
for(int i = 2; i<= n/2; i++){
boolean pr = true;
for(int j = 0; j<cp; j++)pr &= (i%prime[j]!=0);
if(pr)prime[cp++] = i;
}
//Creating a bitmask on primes. It can be seen that there can be atmost 11 primes.
mxMask = 1<<cp;sz = new int[MXN];
//Our DP table, table[i][j][mask] denote number of possible ways of distributing j coins in subtree of i (including i)
//such that all subtrees in this subtree are divisible by primes represented in mask
ANS = new long[MXN][MXN][mxMask];
fMask = new int[MXN];
//Stores the mask of each value. If ith bit in fMask[x] is 1, it means that x is divisible by ith prime in prime array.
//Using this, we can easily check if two number share any prime factor stored in prime array.
// fMask[x1] & fMask[x2] represent common factors between x1 and x2.
for(int i = 1; i<= n; i++)
for(int j = 0; j< cp; j++)
if(i%prime[j]==0)fMask[i] |= 1<<j;
dfs(1);
//Final answer is represented by sum{table[1][i][j]} for all 0<=i<=n, 0<=j<mxMask, representding every combination of coin and mask at node 1.
long ans = 0;
for(int coin = 0; coin<= sz[1]; coin++)
for(int mask = 0; mask< mxMask; mask++)
ans = (ans+ANS[1][coin][mask])%mod;
pn(ans);
}
sz[u] = 1;
if(adj[u].isEmpty()){
//If node U is leaf, It will either contain 1 coin or 0 coin. Both ways will always be valid. mask would also be 0.
ANS[u][0][0] = ANS[u][1][0] = 1;
}else{
for(int v:adj[u]){
dfs(v);//Calculations is made from leaf to root
sz[u]+=sz[v];//Subtree size updation
}
//The
DP = new long[sz[u]+1][sz[u]+1][mxMask];//This table is used for intermediate calculations at a node.
//dp[i][j][mask] represent number of ways to put exactly j coins in subtrees of first i children of X.
DP[0][0][0] = 1;//It is possible to choose 0 coins in first 0 subtrees such that their mask is 0.
int maxCoins = 0;//
int ind = 0;
for(int child:adj[u]){
for(int coins = 0; coins<=maxCoins; coins++){ //Iterating over max coins we can have uptil now.
for(int mask = 0; mask< mxMask; mask++){//Checking every mask
if(DP[ind][coins][mask] == 0)continue;//Skipping irrelevant cases
for(int add = 0; add<= sz[child]; add++){//Iterating over number of coins to put in this subtree
//If subtree of child is not co-prime to mask1, it will also voilate condition of GCD, thus, has to be skipped.
if((fMask[add]&mask)!=0)continue;
//Iterating over submask of complement of mask1.
int comp = (mxMask-1)^mask;
for(int mask2 = comp; ; mask2 = (mask2-1)&comp){
//The main DP transition,
DP[ind+1][coins+add][mask|mask2] = (DP[ind+1][coins+add][mask|mask2]+DP[ind][coins][mask]*ANS[child][add][mask2])%mod;
if(mask2==0)break;
}
}
}
}
//Updating Coin count uptil now
maxCoins+=sz[child];
ind++;
}
//For updating ANS table for node u.
for(int coins = 0; coins<= maxCoins; coins++){
for(int cMask = 0; cMask<mxMask; cMask++){
//If coin is not put at Node u
ANS[u][coins][cMask|fMask[coins]] = (ANS[u][coins][cMask|fMask[coins]]+DP[ind][coins][cMask])%mod;
//If coin is put at node u.
ANS[u][coins+1][cMask|fMask[coins+1]] = (ANS[u][coins+1][cMask|fMask[coins+1]]+DP[ind][coins][cMask])%mod;
}
}
}
}
//SOLUTION ENDS
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p
(Object o
){out.
print(o
);} void pn
(Object o
){out.
println(o
);} void pni
(Object o
){out.
println(o
);out.
flush();} String nln
(){return in.
nextLine();} int ni
(){return Integer.
parseInt(in.
next());} long nl
(){return Long.
parseLong(in.
next());} double nd
(){return Double.
parseDouble(in.
next());}
class FastReader{
public FastReader(){
}
}
while (st == null || !st.hasMoreElements()){
try{
e.printStackTrace();
}
}
return st.nextToken();
}
try{
str = br.readLine();
e.printStackTrace();
}
return str;
}
}
long mod = (int)1e9+7, IINF = (long)1e18;
final int MAX = (int)1e4+1, INF = (int)1e9, root = 3;
double PI = 3.141592653589793238462643383279502884197169399375105820974944;
static boolean multipleTC = false, memory = true;
if(memory
)new Thread(null,
new Runnable() {public void run
(){try{new Main
().
run();}catch(Exception e
){e.
printStackTrace();}}},
"1",
1 << 28).
start(); else new Main().run();
}
in = new FastReader();
for(int i = 1, T= (multipleTC)?ni():1; i<= T; i++)solve(i);
out.flush();
out.close();
}
}