#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;

    int arr[n] , brr[n];
    for(int i=0 ; i<n ; i++)
    {
        cin >> arr[i];
        cin >> brr[i];
    }

    int count=0;
    for(int i=0 ; i<n-1 ; i++)
    {
        int x=arr[i] , y=brr[i];
        for(int j=i+1 ; j<n ; j++)
        {
            if(arr[j]-x != 0)
            {
                int a = arr[j]-x;
                int b = brr[j]-y;

                if(abs(a) >= abs(b))
                count++;
            }
        }
    }

    cout << count << "\n";
    return 0;
}
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+2;
#define filename ""
    vector<int> v[N];
    int h[N];
    pair<int,int> o[N];
bool sss(pair<int,int> &x,pair<int,int> &y)
{
    if (x.fi-x.se==y.fi-y.se) re x<y;
    re x.fi-x.se>y.fi-y.se;
}
void dfs(int x)
{
    h[x]=1;
    vector<pair<int,int> > vv[2];
    for(auto y:v[x])
    {
        dfs(y);
        h[x]+=h[y];
        vv[h[y]%2].pb(o[y]);
    }
    o[x]={0,0};
    if (vv[1].size()%2)
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=max(j.fi,j.se);
            o[x].se+=min(j.fi,j.se);
        }
    }
    else
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=j.fi;
            o[x].se+=j.se;
        }
    }
    sort(all(vv[1]),sss);
    int i;
    fo(i,vv[1].size())
    {
        if (i%2)
        {
            o[x].fi+=vv[1][i].se;
            o[x].se+=vv[1][i].fi;
        }
        else
        {
            o[x].fi+=vv[1][i].fi;
            o[x].se+=vv[1][i].se;
        }
    }
    o[x].se++;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,i;
    cin>>n;
    fo(i,n-1)
    {
        int a;
        cin>>a;
        a--;
        v[a].pb(i+1);
    }
    dfs(0);
    cout<<o[0].se;
}
