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. vector<int> arr(n + 1);
  9. int i=1;
  10. while(i<=n)
  11. {
  12. cin>>arr[i];
  13. i++;
  14. }
  15.  
  16.  
  17. unordered_map<int,int>freq;
  18. for(int l=4;l<=n;l++)
  19. {
  20. freq[arr[l]]++;
  21. }
  22. int count=0;
  23. for(int i=1;i<=n;i++)
  24. {
  25. for(int j=i+1;j<=n;j++)
  26. {
  27. for(int k=j+1;k<=n-1;k++)
  28. {
  29. int g=-(arr[i]+arr[j]+arr[k]);
  30. count=count+freq[g];
  31. freq[arr[k+1]]--;
  32. }
  33. for(int z=j+3;z<=n;z++)
  34. {
  35. freq[arr[z]]++;
  36. }
  37. }
  38. }
  39.  
  40.  
  41.  
  42. cout<<count;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 5288KB
stdin
7
1 2 3 4 -1 -2 -2
stdout
2