n = int(input()) ans, dic = 0, dict() for i in range(1,n+1): x, y = map(int,input().split()) ans += i*dic.setdefault(x,0) dic[x] = y print(ans%2**64)