#include #include #include #include #include using namespace std; const int MOD1 = 1000001; int F1[MOD1]; 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; long long aux = getv(X[i], Y[i]); ++F1[aux % MOD1]; ++Mx[X[i]]; ++My[Y[i]]; } 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]]; long long aux = getv(X[pos[j]] - dist, Y[pos[j]]); if (aux >= 0) if (F1[aux % MOD1] != 0) ++result; aux = getv(X[pos[j]] + dist, Y[pos[j]]); if (aux >= 0) if (F1[aux % MOD1] != 0) ++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; long long aux = getv(X[pos[j]], Y[pos[j]] - dist); if (aux >= 0) if (F1[aux % MOD1] != 0) ++result; aux = getv(X[pos[j]], Y[pos[j]] + dist); if (aux >= 0) if (F1[aux % MOD1] != 0) ++result; } } i = now; } cout << result << '\n'; }