import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Map<Long, Long> f = new HashMap<>();
long total = 0;
for (int i = 1; i <= n; i++) {
// ❌ 错误:sc.nextLong() 无法解析 > 2^63-1 的数
// ✅ 正确:先读字符串,再 parseUnsignedLong
String xStr = sc.next();
String yStr = sc.next();
long x = Long.parseUnsignedLong(xStr);
long y = Long.parseUnsignedLong(yStr);
long ans_i = f.getOrDefault(x, 0L);
total += (long) i * ans_i; // 自动 mod 2^64
f.put(x, y);
}
// 输出必须用无符号形式
System.out.println(Long.toUnsignedString(total));
sc.close();
}
}