//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,n)         for(int i= 0; i < int(n); i++)
#define      rep1(i,n)        for(int i= 1; i <= n; i++)
#define      rev(i,n)         for(int i= (int)(n-1);i>=0;i--)
#define      rev1(i,n)        for(int i= (int) n;i>= 1;i--)
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;


int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>n>>k;
    if(k==0)
    {

        cout<<n<<endl;
        return 0;
    }

    map<ll,ll>frq;
    for(i=1;i<=(n+1);i++)
    {
        frq[i]=(i-1);
    }
    ll tem=0;
    for(i=(2*n);i>(n+1);i--)
    {
        tem++;
        frq[i]=tem;
    }

    k=abs(k);
    ll ans=0;
    map<ll,bool>vis;
    for(i=1;i<=(2*n);i++)
    {
        if(!vis[i]&&frq[i]>=1)
        {
            a = i+k;
            if(!vis[a]&&frq[a]>=1)
            {
                ans+=(frq[i]*frq[a]);
                vis[i]=true;
                //vis[a]=true;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = s; i < (int)(n); ++i)
#define Clear(a) a = decltype(a)()
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define bit(i,j) ((i>>j)&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef string::const_iterator state; //構文解析
const ll big=1000000007;
//const ll big=998244353;
const double PI=acos(-1);
const double EPS=1e-8;//適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-1;}
    constexpr operator ll(){return -ll(1e18)-1;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+1;}
    constexpr operator ll(){return ll(1e18)+1;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#define _GLIBCXX_DEBUG
#else
#define dbg(x) ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T,typename U> T max(const T x,const U y){if(x>y)return x;else return y;}
template<typename T,typename U> T min(const T x,const U y){if(x<y)return x;else return y;}
template<typename T> T max(const vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<typename T,typename U>
T expm(T x,U y,const ll mod=big){
    T res=1;
    while(y){
        if(y&1)(res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}
template<typename T,typename U>
T exp(T x,U y){
    T res=1;
    while(y){
        if(y&1)res*=x;
        x*=x;
        y>>=1;
    }
    return res;
}

int n;
vector<int> p;
vector<vector<int>> g;//g[i][0]がiの親.
vector<vector<bool>> notmy;
vector<int> ans;

//「自分」「相手」の辺を決定する.
bool dfs(int i){
    if(i!=0 && g[i].size()==1)return true;
    bool res=false;
    rep2(j,int(i!=0),g[i].size()){
        res^=(notmy[i][j]=dfs(g[i][j]));
    }
    return !res;
}

//その頂点「に」移動させることを選択した人がどれだけ獲得するか？
int calc(int i){
    if(g[i].size()==1 && i!=0){
        return ans[i]=-1;
    }

    vector<int> mine;
    vector<int> ene;
    rep2(j,int(i!=0),g[i].size()){
        if(notmy[i][j])ene.emplace_back(calc(g[i][j]));
        else mine.emplace_back(calc(g[i][j]));
    }

    sort(rall(mine));
    sort(rall(ene));

    int res=-1;
    //「ene」の個数が偶数個なら, mineは全て自分でとることになる.
    if(ene.size()%2==0){
        for(auto &e:mine)res+=e;
        rep(j,ene.size()){
            if(j%2==0)res+=ene[j];
            else res-=ene[j];
        }
    }
    else{
        for(auto &e:mine)res+=abs(e);
        rep(j,ene.size()){
            if(j%2==0)res+=ene[j];
            else res-=ene[j];
        }
    }
    return ans[i]=res;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout.precision(10);
    /*--------------------------------*/
    
    cin >> n;
    p.resize(n);
    g.resize(n);
    rep(i,n-1){
        cin >> p[i+1];
        p[i+1]--;
        g[i+1].emplace_back(p[i+1]);
        g[p[i+1]].emplace_back(i+1);
    }
    notmy.resize(n);
    rep(i,n){
        notmy[i].resize(g[i].size());
    }
    ans.resize(n,0);
    dfs(0);
    dbg(notmy);
    calc(0);
    dbg(ans);
    cout << (n-ans.front())/2 << newl;
}