#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    int N;
    cin >> N;
    vector<vector<int>> child(N+1);
    vector<int> par(N+1, 0);
    for (int i = 2; i <= N; i++) {
        int p;
        cin >> p;
        child[p].push_back(i);
        par[i] = p;
    }
    vector<int> size(N+1, 1);
    vector<int> cplus(N+1, -1);
    for (int now = N; now >= 1; now--) {
        for (int c : child[now]) size[now] += size[c];
        vector<int> odd = {-10000000}, even = {-10000000};
        bool turn = true;
        for (int c : child[now]) {
            if (size[c]%2 == 1) odd.push_back(cplus[c]);
            else even.push_back(cplus[c]);
        }
        sort(odd.begin(), odd.end(), greater<int>());
        sort(even.begin(), even.end(), greater<int>());
        int k = odd.size();
        int l = even.size();
        int op = 0, ep = 0;
        k--;l--;
        //cout << k << " " << l << endl;
        while (op < k || ep < l) {
            if (even[ep] >= 0 || op == k) {
                if (turn) cplus[now] += even[ep];
                else cplus[now] -= even[ep];
                ep++;
            }else {
                if (turn) cplus[now] += odd[op];
                else cplus[now] -= odd[op];
                op++;
                turn = !turn;
            }
        }
    }
    cout << (N-cplus[1])/2 << endl;
    return 0;
}
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
bool ok(int x,int y,int n,int m){
	 re(x>=0&&x<n&&y>=0&&y<m);
}
bool isprime(int x){
	if(x<2)
	re false;
	for(int i=2;i*i<=x;i++)
	if(x%i==0)
	re false;
	re true;
}
int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
int n;
ll a[3001];
ll lst[3001][3001];
ll prv[3001];
ll dp[3001][3001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	cin>>a[i];
	rep(i,n)
	prv[i+1]=prv[i]+a[i];
	lst[1][0]=1;
	forn(i,1,n+1){
		forn(j,1,i+1){
			dp[i][j]=lst[j][prv[i]%j];
		}
		forn(j,1,i+1){
			lst[j+1][prv[i]%(j+1)]+=dp[i][j];
			lst[j+1][prv[i]%(j+1)]%=mod;
		} 
	}
//	forn(i,1,n+1)
//	cout<<prv[i]<<" ";
//	cout<<"\n";
//	forn(i,1,n+1){
//		forn(j,1,i+1)
//		cout<<dp[i][j]<<" ";
//		cout<<"\n";
//	}
	ll ans=0;
	forn(i,1,n+1){
		ans+=dp[n][i];
		ans%=mod;
	}
	cout<<ans;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
long long所要的时间比int长!!
没有long long必要不写long long!!
写公式前先想一想!!
二分前看一看边界对不对，有没有特殊值!!
提交前要测特殊数据（边界上的）!!
*/
