#include <bits/stdc++.h>

using namespace std;

unordered_map<int, unordered_set<int>> OnX, OnY;
int X[500000], Y[500000];

int main() {

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i) {
        cin >> X[i] >> Y[i];
        OnX[X[i]].insert(Y[i]);
        OnY[Y[i]].insert(X[i]);
    }

    long long total = 0;

    for (int i = 1; i <= n; ++i) {
        int x = X[i], y = Y[i];
        auto &XSet = OnX[y], &YSet = OnY[x];

        if(XSet.size() > YSet.size()) {
            swap(x, y);
            swap(XSet, YSet);
        }

        for(auto val : XSet)
            total += YSet.count(x - val + y);
    }

    cout << total;

    return 0;
}