#include <iostream>
#include <utility>
using namespace std;

int main()
{
    pair<int, int>* arr;
    int N, curr_sum = 0, ans = 0;

    cin >> N;
    arr = new pair<int, int>[N];

    for (int i = 0; i < N; i++)
        cin >> arr[i].first >> arr[i].second;

    for (int i = 0; i < N - 1; i++)
    {
        if (i > 0 && i < N && arr[i].second == 0)
        {
            curr_sum -= arr[i - 1].second;
        }

        curr_sum += arr[i].second;
        ans += curr_sum;
    }

    cout << ans << endl;

    return 0;
}
