#include #include #include #include #include using namespace std; int N; int X[100002], Y[100002], pos[100002]; unordered_map Mx, My; unordered_set S; long long result; inline long long getv(int x, int y) { return 1000000001LL * x + y; } inline bool compare1(const int& i1, const int& i2) { return X[i1] < X[i2]; } inline bool compare2(const int& i1, const int& i2) { return Y[i1] < Y[i2]; } int main() { cin.sync_with_stdio(false); cin >> N; for (int i = 1; i <= N; ++i) { cin >> X[i] >> Y[i]; pos[i] = i; S.insert(getv(X[i], Y[i])); ++Mx[X[i]]; ++My[Y[i]]; } if (N <= 10000) { sort(pos + 1, pos + N + 1, compare1); for (int i = 1; i <= N; ++i) { int now = i; while (X[pos[now]] == X[pos[i]]) ++now; --now; for (int j = i; j <= now; ++j) if (Mx[X[pos[j]]] <= My[Y[pos[j]]]) { int dist = 0; for (int k = i; k <= now; ++k) if (j != k) { dist = Y[pos[k]] - Y[pos[j]]; if (dist < 0) dist *= -1; if (S.find(getv(X[pos[j]] - dist, Y[pos[j]])) != S.end()) ++result; if (S.find(getv(X[pos[j]] + dist, Y[pos[j]])) != S.end()) ++result; } } i = now; } sort(pos + 1, pos + N + 1, compare2); for (int i = 1; i <= N; ++i) { int now = i; while (Y[pos[now]] == Y[pos[i]]) ++now; --now; for (int j = i; j <= now; ++j) if (My[Y[pos[j]]] < Mx[X[pos[j]]]) { int dist = 0; for (int k = i; k <= now; ++k) if (j != k) { dist = X[pos[k]] - X[pos[j]]; if (dist < 0) dist *= -1; if (S.find(getv(X[pos[j]], Y[pos[j]] - dist)) != S.end()) ++result; if (S.find(getv(X[pos[j]], Y[pos[j]] + dist)) != S.end()) ++result; } } i = now; } } else { sort(pos + 1, pos + N + 1, compare1); for (int i = 1; i <= N; ++i) { int now = i; while (X[pos[now]] == X[pos[i]]) ++now; --now; for (int j = i; j <= now; ++j) if (Mx[X[pos[j]]] <= My[Y[pos[j]]]) { int dist = 0; for (int k = i; k <= now; ++k) if (j != k) { dist = Y[pos[k]] - Y[pos[j]]; if (dist < 0) dist *= -1; ++result; ++result; } } i = now; } sort(pos + 1, pos + N + 1, compare2); for (int i = 1; i <= N; ++i) { int now = i; while (Y[pos[now]] == Y[pos[i]]) ++now; --now; for (int j = i; j <= now; ++j) if (My[Y[pos[j]]] < Mx[X[pos[j]]]) { int dist = 0; for (int k = i; k <= now; ++k) if (j != k) { dist = X[pos[k]] - X[pos[j]]; if (dist < 0) dist *= -1; ++result; ++result; } } i = now; } } cout << result << '\n'; }