fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, m, input;
  7. long long counter = 0;
  8.  
  9. cin >> n >> m;
  10.  
  11. unordered_map<int, int> freq;
  12.  
  13. for (int i = 0; i < n; i++)
  14. {
  15. cin >> input;
  16. freq[input]++;
  17. }
  18.  
  19. for (int i = 0; i < m; i++)
  20. {
  21. cin >> input;
  22. counter += freq[input];
  23. }
  24.  
  25. cout << counter;
  26. }
Success #stdin #stdout 0.01s 5288KB
stdin
8 7
1 1 3 3 3 5 8 8
1 3 3 4 5 5 5
stdout
11