#include <bits/stdc++.h>

using namespace std;

unordered_map<int, unordered_multiset<int>> OnVert, OnHor;
int X[500000], Y[500000];

int main() {

    int n;
    cin >> n;

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

    long long total = 0;

    for (int i = 1; i <= n; ++i) {
        int x = X[i], y = Y[i];
        auto &VertSet = OnVert[x], &HorSet = OnHor[y];

        if(VertSet.size() > HorSet.size()) {
            swap(x, y);
            swap(VertSet, HorSet);
        }

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

    cout << total - 2 * n;

    return 0;
}