fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. cin >> n;
  7. unordered_set<int> a(n), b(n);
  8. for (int i = 0; i < n; i++) {
  9. int x;
  10. cin >> x;
  11. if (a.find(x) == a.end()) a.insert(x);
  12. }
  13. for (int i = 0; i < n; i++) {
  14. int x;
  15. cin >> x;
  16. if (b.find(x) == b.end()) b.insert(x);
  17. }
  18. if (a.size() + b.size() >= 4) cout << "YES" << endl;
  19. else cout << "NO" << endl;
  20. }
  21.  
  22. int main() {
  23. int t;
  24. cin >> t;
  25. while (t--) solve();
  26. }
Success #stdin #stdout 0.01s 5272KB
stdin
5
4
1 2 1 2
1 2 1 2
6
1 2 3 3 2 1
1 1 1 1 1 1
3
1 1 1
1 1 1
6
1 52 52 3 1 3
59 4 3 59 3 4
4
100 1 100 1
2 2 2 2
stdout
YES
YES
NO
YES
NO