fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. cin.tie(nullptr);
  6. int n;
  7. cin >> n;
  8. unordered_map<long long, long long> cnt;
  9. for (int i = 0; i < n; i++) {
  10. long long a, b;
  11. cin >> a >> b;
  12. cnt[a - b]++;
  13. }
  14. long long ans = 0;
  15. if (cnt.count(0)) {
  16. long long c = cnt[0];
  17. ans += c * (c - 1) / 2;
  18. }
  19. for (auto &p : cnt) {
  20. long long d = p.first;
  21. if (d > 0 && cnt.count(-d)) {
  22. ans += p.second * cnt[-d];
  23. }
  24. }
  25. cout << ans;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5292KB
stdin
3
1 2
4 3
2 1
stdout
2