#include <iostream>
#include <unordered_map>
using namespace std;
#include <map>    
typedef unsigned long long ull;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    ull res=0;
    unordered_map<ull,ull>hash_map;
    for(int i=1;i<=n;i++){
        ull x,y;
        cin>>x>>y;
        hash_map[x]=hash_map.count(x)?hash_map[x]:0;
        res+=(ull)i*hash_map[x];
        hash_map[x]=y;
    }
    cout<<res<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")