fork download
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <algorithm>
  6. using namespace std;
  7. int n;
  8. long long res, r;
  9. set < pair<int, int> > S;
  10. map <int, int> X, Y;
  11. int main() {
  12. scanf("%d",&n);
  13. pair <int, int> P;
  14. for (int i = 0; i < n; i++) {
  15. scanf("%d%d",&P.first,&P.second);
  16. if (S.count(P)) res = -1;
  17. else S.insert(P);
  18. X[P.first]++;
  19. Y[P.second]++;
  20. }
  21. if (res == -1) printf("-1");
  22. else {
  23. res = 0;
  24. for (map<int,int>::iterator I = X.begin(); I != X.end(); I++) {
  25. r = (*I).second;
  26. res += r*(r-1)/2;
  27. }
  28. for (map<int,int>::iterator I = Y.begin(); I != Y.end(); I++) {
  29. r = (*I).second;
  30. res += r*(r-1)/2;
  31. }
  32. printf("%lld",res);
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 3304KB
stdin
Standard input is empty
stdout
Standard output is empty