#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  /*
  どの頂点を選ぶか？

  その頂点を選ぶことによって、どれだけ自分がプラスになるか
  自分の手番が継続できるか

  優先度
  手番が継続できて、収支プラス
  ↓
  手番が継続できなくて、収支プラス（大きい方から）
  ↓
  手番が継続できなくて、収支マイナス（マシな方から）
  ↓
  手番が継続できて、収支マイナス

  */


  int N; cin >> N;
  vvi es(N);
  FOR(i, 1, N) {
    int p; cin >> p; p--;
    es[p].push_back(i);
  }
  v(bool) bs(N); // 手番が継続できるかどうか
  vi ss(N); // 収支

  int big = 2000002;
  auto vscore = [&](int v) {
    int s = ss[v];
    if (bs[v]) {
      if (ss[v] >= 0) s += big;
      else s -= big;
    }
    return s;
  };

  auto vcmp = [&](int a, int b) {
    return vscore(a) < vscore(b);
  };

  auto dfs = [&](auto dfs, int v) {

    if (!sz(es[v])) {
      bs[v] = false;  // 相手の手番に
      ss[v] = -1;
      return;
    }

    priority_queue<int, deque<int>, decltype(vcmp)> pq(vcmp);
    for (auto c : es[v]) {
      dfs(dfs, c);
      pq.push(c);
    }
    int turn = 1; // 相手の手番なら-1
    int score = 0;
    while (sz(pq)) {
      auto c = pq.top(); pq.pop();
      score += ss[c] * turn;
      if (!bs[c]) turn = turn * -1;
    }
    ss[v] = -1+score;
    bs[v] = turn < 0; // 1回戻るので、手番は逆になる
  };
  dfs(dfs, 0);
  //cout << ss;

  /*
  a+b=N a-b=ss[0]
  */
  int a = (N - ss[0]) / 2;
  cout << a << newl;
}
#endif

#include <bits/stdc++.h>
#define int long long
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbd(a) cout << #a << ": " << a << endl
#define dbd2(a,b) cout << #a << ": " << a << ", " << #b << ": " << b << endl 
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto _i:a) cout << _i << " "; cout << endl
#define adbp(a) for(auto _i:a) cout << _i.first << " " << _i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define N 3010
#define M 200010
using namespace std;

int n;
vector<int> a, pre;
vector<vector<int>> dp;
vector<vector<vector<int>>> modmap;

// i: current position, j: current subset
int solve(int i, int j)
{
    if(i == n) return 1;
    if(dp[i][j] != -1) return dp[i][j];

    int curmod = pre[i] % j;

    auto &mp = modmap[j][curmod];
    auto index = lower_bound(mp.begin(), mp.end(), i) - mp.begin();

    int ret = (index == mp.size()) ? (0) : 
                (solve(mp[index] + 1, j) + (mp[index] != n - 1) * solve(mp[index] + 1, j + 1)); 

    ret = (ret % mod);

    return dp[i][j] = ret;
}

signed main()
{
    fastIO;
    cin >> n;

    a.resize(n);
    for(int i=0; i<n; i++) cin >> a[i];

    pre.resize(n + 1);
    for(int i=0; i<n; i++) pre[i + 1] = pre[i] + a[i];

    modmap.assign(n + 1, vector<vector<int>>(n + 1, vector<int>()));
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<n; j++)
        {
            modmap[i][pre[j + 1] % i].push_back(j);
        }
    }

    dp.assign(n + 1, vector<int>(n + 1, -1));

    cout << solve(0, 1);
}