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

int main() {
    unsigned long long n;
    cin >> n;
    unordered_map<unsigned long long, unsigned long long> un_nums;//其中元素默认都为0,符合第一次f(x)时都为0的结果
    unsigned long long result = 0;
    for(unsigned long long i = 0; i < n; i++) {
        unsigned long long x,y;
        cin >> x >> y;
        result += un_nums[x] * (i + 1);//先计算当前f(x)的结果*次数,result累加此值
        un_nums[x] = y;//更新f(x)的结果为y,下次f(x)就会用这次的y值,而不是默认值0
    }
    cout << result << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")