1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer in = new StringTokenizer(br.readLine());
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
HashMap<Long, Long> hmap = new HashMap<>();
long total = 0;
int n = Integer.parseInt(in.nextToken());
for (int i = 1; i <= n; i++) {
in = new StringTokenizer(br.readLine());
long x = Long.parseUnsignedLong(in.nextToken());
long y = Long.parseUnsignedLong(in.nextToken());
long ans = hmap.getOrDefault(x, 0L);
total += (long) i * ans;
hmap.put(x, y);
}
out.println(Long.toUnsignedString(total));
out.flush();
out.close();
br.close();
}
|