fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <bits/stdc++.h>
  4. int main() {
  5. // your code goes here
  6. int n;
  7. cin>>n;
  8. int arr[n];
  9. int i=0;
  10. while(i<n)
  11. {
  12. cin>>arr[i];
  13. i++;
  14. }
  15.  
  16.  
  17. unordered_map<int,int>freq;
  18. for(int l=3;l<n;l++)
  19. {
  20. freq[arr[l]]++;
  21. }
  22. int count=0;
  23. for(int i=0;i<n;i++)
  24. {
  25. for(int j=i+1;j<n;j++)
  26. {
  27. for(int k=j+1;k<n;k++)
  28. {
  29. int g=arr[i]+arr[j]+arr[k];
  30. count=count+freq[-g];
  31. int remove=arr[k+1];
  32. freq[remove]=0;
  33. }
  34. }
  35. }
  36.  
  37.  
  38.  
  39. cout<<count;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
7
1 2 3 4 -1 -2 -2
stdout
2