fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. freopen("SUM.INP" , "r" , stdin);
  9. freopen("SUM.OUT" , "w" , stdout);
  10. ll n;
  11. cin >> n;
  12. vector<ll> a(n);
  13. for(int i = 0; i < n; i++) cin >> a[i];
  14. unordered_map<ll, ll> freq;
  15. ll dem = 0;
  16. for(int i = 0; i < n; i++) {
  17. dem += freq[-a[i]];
  18. if(a[i] == 0) dem++;
  19.  
  20. freq[a[i]]++;
  21. }
  22.  
  23. cout << dem;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 5324KB
stdin
5
-3 1 0 -1 3
stdout
3