fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int t, n, a[200020];
  4. unordered_map<int,int> freq;
  5. int main() { ios::sync_with_stdio(false);cin.tie(0);
  6. cin >> t;
  7. while (t--) {
  8. cin >> n;
  9. for (int j = 0; j < 3; j++) freq[j] = 0;
  10. for (int i = 0; i < n; i++) cin >> a[i], a[i] %= 3, freq[a[i]]++;
  11. if (freq[1]>0 and freq[2]>0 and freq[0] <= 0) {cout << "NO\n"; continue;}
  12. if (freq[1]+freq[2]<=0 and freq[0] > 0) {cout << "NO\n"; continue;}
  13. if (freq[1]+freq[2]+1 < freq[0]) {cout << "NO\n"; continue;}
  14. cout << "YES\n";
  15. }
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 4700KB
stdin
Standard input is empty
stdout
Standard output is empty