Попробуй это:
```cpp
#include <iostream>
#include <vector>
#include <set>
int main() {
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
int m;
std::cin >> m;
std::vector<int> b(m);
for (int i = 0; i < m; ++i) {
std::cin >> b[i];
}
std::set<int> s_a, s_b;
for (int num : a) {
s_a.insert(num);
}
for (int num : b) {
s_b.insert(num);
}
int count = 0;
for (int num : s_a) {
if (s_b.find(num) != s_b.end() && s_b.count(num) > 1) {
++count;
}
}
std::cout << count << std::endl;
return 0;
}
```