#include<bits/stdc++.h>
#define MAX_N 1000005
using namespace std;

int snowman[3][MAX_N];

int create_snowman(int index, int m, int parent)
{
    if(m>0)
    {
        snowman[0][index]=parent;
        snowman[1][index]=snowman[1][parent]+m;
        snowman[2][index]=m;
    }
    else
    {
        snowman[0][index]=parent;
        snowman[1][index]=snowman[1][snowman[0][parent]];
        snowman[2][index]=snowman[2][snowman[0][parent]];
    }
    return snowman[1][index];
}

int main()
{
    int n;
    cin >> n;

    snowman[0][0]=0;
    snowman[1][0]=0;
    snowman[2][0]=0;

    int parent, m;
    long long result=0;
    for(int i=1; i<=n; i++)
    {
        cin>> parent >> m;
        result+=create_snowman(i, m, parent);
    }

    cout << result;

    return 0;
}
