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

int main() {
    unsigned long long n, x, y, i = 1;
    cin >> n;
    unordered_map<unsigned long long, unsigned long long> hash;
    unsigned long long ret = 0;

    while (n--) {
        cin >> x >> y;
        ret += hash[x] * i;
        hash[x] = y;
        ++i;
    }

    cout << ret;

    return 0;
}