fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9.  
  10. StringTokenizer stk = new StringTokenizer(br.readLine());
  11. int n = Integer.parseInt(stk.nextToken());
  12. int m = Integer.parseInt(stk.nextToken());
  13.  
  14. HashMap<String, Integer> map = new HashMap<>();
  15.  
  16. stk = new StringTokenizer(br.readLine());
  17. for(int i = 0; i < n; i++){
  18. String str = stk.nextToken();
  19.  
  20. if(map.containsKey(str)){
  21. map.put(str, map.get(str) + 1);
  22. }else{
  23. map.put(str, 1);
  24. }
  25. }
  26.  
  27. stk = new StringTokenizer(br.readLine());
  28. for(int i = 0; i < m; i++){
  29. String str = stk.nextToken();
  30. if(map.containsKey(str)){
  31. map.put(str, map.get(str) + 1);
  32. }else{
  33. map.put(str, 1);
  34. }
  35. }
  36.  
  37. // n+m - ((n+m) - map.length)*2
  38. // n+m - 2(n+m) + 2*map.length
  39. // 2*map.length - (n+m)
  40.  
  41. System.out.println(2*map.size() - (n+m));
  42.  
  43. }
  44. }
Success #stdin #stdout 0.09s 47456KB
stdin
3 5
1 2 4
2 3 4 5 6
stdout
4