Advertisement
MathQ_

Untitled

Jun 23rd, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #pragma GCC optimize 03
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. const int m = 2e4 + 1;
  8.  
  9. int main() {
  10.     int n;
  11.     cin >> n;
  12.     vector<int> a(n);
  13.     for (auto &el : a) cin >> el;
  14.     vector<int> cnt(m);
  15.     for (auto el : a) cnt[el]++;
  16.  
  17.     long long ans = 0;
  18.     for (int i = 0; i < n; ++i) {
  19.         cnt[a[i]]--;
  20.         for (int j = 0; j < i; ++j) {
  21.             ans += cnt[a[i] + a[j]];
  22.         }
  23.     }
  24.     cout << ans << '\n';
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement