fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. long long int n,p[40009],i,two=0,z=0,sum;
  10. cin>>n;
  11. for(i=0;i<n;i++)
  12. {
  13. cin>>p[i];
  14. }
  15. for(i=0;i<n;i++)
  16. {
  17. if(p[i]==2)
  18. two++;
  19. if(p[i]==0)
  20. z++;
  21. }
  22. sum=(two*(two-1))/2 + (z*(z-1))/2;
  23.  
  24. cout<<sum<<endl;
  25.  
  26.  
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 4280KB
stdin
2
3
2 4 2
3
0 2 3
stdout
1
0