#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int re()
{
    char f=getchar();
    int x=0,k=1;
    while(f>'9'||f<'0')
    {
        if(f=='-') k=-1;
        f=getchar();
    }
    while(f>='0'&&f<='9')
    {
        x=x*10+f-'0';
        f=getchar();
    }
    return x*k;
}

signed main()
{
    int n=re(),ans=0;
    n*=2;
    for(int i=1;i<=sqrt(n);i++)
        if(n%i==0)
        {
            if(i&1)
            ans++;
            if((n/i)&1 && i*i<n)
                ans++;
        }
            
    cout<<ans*2;
}
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;

vector<int> g[100005];
int d[100005];
int dfs(int u){
  for(int v:g[u]) d[u] += dfs(v);
  return ++d[u];
}
int f(int u){
  int res=1,i=1;
  vector<int> t[2];
  for(int v:g[u]) t[d[v]&1].push_back(f(v));
  sort(t[1].begin(),t[1].end());
  for(int s:t[0]) res += min(s,0);
  for(int s:t[1]) res += i*s, i*=-1;
  for(int s:t[0]) res += i*max(s,0);
  return res;
}
int main() {
  int n;
  cin >> n;
  rep(i,n-1){
    int p;
    cin >> p;
    --p;
    g[p].push_back(i+1);
  }
  dfs(0);
  cout << (n+f(0))/2 << endl;
}
