#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
unordered_map<unsigned long long, unsigned long long> f;//定义f
unsigned long long n;
cin >> n;
unsigned long long res = 0;//存放结果
for(unsigned long long i = 1; i <= n; i++){
unsigned long long x, y;
cin >> x >> y;
if(f.count(x)){//已经存在x则获取当前值给ans,更新res并更新f(x)
unsigned long long ans = f[x];
res += i *ans;
f[x] = y;
}
else{//不存在x,ans值为0,不用更新res直接添加f(x)
f[x] = y;
}
}
printf("%llu",res);
return 0;
}
// 64 位输出请用 printf("%lld")