from os import initgroups from sys import stdin from collections import * from heapq import * from random import * input = lambda: stdin.readline().strip() # read1 = stdin.read().split() # idx = 1 mod1 = 2**64 f = defaultdict(int) ans = 0 for i in range(1,int(input())+1): x,y = map(int,input().split()) ans += i*f[x] f[x] = y ans %= mod1 print(ans)