-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMadeUp.java
More file actions
49 lines (42 loc) · 1.41 KB
/
MadeUp.java
File metadata and controls
49 lines (42 loc) · 1.41 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Source: https://usaco.guide/general/io
import java.util.*;
import java.io.*;
import java.util.StringTokenizer;
public class MadeUp {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int[] A = Arrays.stream(br.readLine().split(" ")).mapToInt(s -> Integer.parseInt(s)-1).toArray();
int[] B = Arrays.stream(br.readLine().split(" ")).mapToInt(s -> Integer.parseInt(s)-1).toArray();
int[] C = Arrays.stream(br.readLine().split(" ")).mapToInt(s -> Integer.parseInt(s)-1).toArray();
HashMap<Integer, Integer> mapA = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> mapBC = new HashMap<Integer, Integer>();
for(int i=0; i<n; i++) {
if(mapA.containsKey(A[i])) {
mapA.put(A[i], mapA.get(A[i]) + 1);
}
else {
mapA.put(A[i], 1);
}
}
for(int j=0; j<n; j++) {
int c = C[j];
if(c < B.length && mapBC.containsKey(B[c])) {
mapBC.put(B[c], mapBC.get(B[c]) + 1);
}
else if (c < B.length) {
mapBC.put(B[c], 1);
}
}
int ans = 0;
for(Map.Entry<Integer, Integer> entry : mapA.entrySet()) {
int key = entry.getKey();
if(mapBC.containsKey(key)) {
ans += mapBC.get(key) * entry.getValue();
}
}
System.out.println(ans);
}
}