fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long solve(){
  4. int n;
  5. cin>>n;
  6.  
  7. int max1 = -1;
  8. int max2 = -1;
  9. int cnt1 = 0, cnt2 = 0;
  10.  
  11. for (int i = 0; i < n; ++i) {
  12. int x;
  13. cin >> x;
  14. if(x==0) continue;
  15.  
  16. if (x > max1) {
  17. max2 = max1;
  18. cnt2 = cnt1;
  19. max1 = x;
  20. cnt1 = 1;
  21. } else if (x == max1) {
  22. ++cnt1;
  23. } else if (x > max2) {
  24. max2 = x;
  25. cnt2 = 1;
  26. } else if (x == max2) {
  27. ++cnt2;
  28. }
  29. }
  30. if(max1==-1 || cnt1%2==0) return 0;
  31. if(cnt1>1) return ((long long)cnt1)*max1;
  32. if(max2==-1 || cnt2%2) return 1;
  33. return max2;
  34. }
  35. int main() {
  36. ios::sync_with_stdio(false);
  37. cin.tie(nullptr);
  38. int t;
  39. cin>>t;
  40. while(t--){
  41. cout<<solve()<<"\n";
  42. }
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 5308KB
stdin
3
5
0 1 0 1 0
3
0 7 0
5
1 0 1 0 1

stdout
0
1
3