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.  
  19. for(int k=3;k<=n;k++)
  20. {
  21. for(int l=k+1;l<=n;l++)
  22. {
  23. freq[arr[k]+arr[l]]++;
  24. }
  25. }
  26. int count =0;
  27. for(int j=2;j<=n-2;j++)
  28. {
  29. for(int i=1;i<j;i++)
  30. {
  31. int g=-(arr[i]+arr[j]);
  32. count+=freq[g];
  33. }
  34.  
  35. for(int j1=j+2;j1<=n;j1++)
  36. {
  37. freq[arr[j+1]+arr[j1]]--;
  38. }
  39. }
  40.  
  41.  
  42.  
  43. cout<<count;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5288KB
stdin
7
1 2 3 4 -1 -2 -2
stdout
3