#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int p, m;
    long long count = 0;
    int arr[n];

    for (int i = 0; i < n; i++)
    {
        cin >> p >> m;
        if (p == 1 && m == 0)
        {
            arr[p] = 0;
            continue;
        }

        if (m == 0 && (p - 2) >= 0)
        {
            //    cout << "tuk" << endl;
            arr[i] = arr[p - 2];
            count += arr[i];
            continue;
        }
        if ((p - 1) >= 0)
        {
            //cout << "p - 1" << endl;
           // cout << m << endl;
            arr[i] = arr[p - 1] + m;
           // cout << arr[i] << endl;
        }

        else
        {
            //cout << "else" << endl;
           // cout << m << endl;
            arr[i] = m;
        }
      //  cout << count << endl;
        count += arr[i];
       // cout << count << endl;
    }

    cout << count << endl;

    return 0;
}
