fork download
  1. #include<stdio.h>
  2.  
  3. int main ()
  4. {
  5. int t;
  6. long long int n,i,count,a,c;
  7. scanf("%d",&t);
  8. while(t>0)
  9. {
  10. scanf("%lld",&n);
  11. i=0;count=0;c=0;
  12. while(i<n)
  13. {
  14. scanf("%lld",&a);
  15. if(a==2)
  16. count++;
  17. else if(a<2)
  18. c++;
  19. i++;
  20. }
  21. n-=c;
  22. n=(n*(n-1)-count*(count-1))/2;
  23. printf("%lld\n",n);
  24. t--;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 3344KB
stdin
8
4
0 0 0 0
5
2 2 3 3 3
5
2 2 2 3 3
5
1 1 1 3 3
8
1 2 2 2 2 2 3 4
8
0 0 1 1 2 2 3 3
4
0 0 3 3
4
3 3 0 0
stdout
0
9
7
1
11
5
1
1