fork download
  1. #include<bits/stdc++.h>
  2. #define LL long long
  3.  
  4. using namespace std;
  5.  
  6. unordered_map<LL, LL>mymap;
  7. LL arr[10002];
  8.  
  9. int main()
  10. {
  11. int n;
  12. scanf("%d", &n);
  13. for(int i=0; i<n; i++){
  14. scanf("%lld", arr+i);
  15. mymap[2*arr[i]]++;
  16. }
  17.  
  18. LL cnt = 0;
  19. for(int i=0; i<n; i++){
  20. for(int j=i+1; j<n; j++){
  21. LL val = mymap[arr[i] + arr[j]];
  22. if(val>0) cnt = cnt + val;
  23. mymap[arr[i] + arr[j]] = 0;
  24. }
  25. }
  26.  
  27. printf("%lld", cnt);
  28. }
  29.  
Success #stdin #stdout 0s 16144KB
stdin
2
2 2
stdout
2