#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>

using namespace std;

const int MOD = 10000003;
const unsigned long long base = 1e10;

unordered_map<int, vector<int> > line;
unordered_map<int, vector<int> > col;
vector<pair<int, int> > v;
bool s[MOD];
int rasp;

void citire()
{
    int n;
    cin >> n;
    unsigned long long x, y;
    for(int i = 1; i <= n; ++i)
    {
        cin >> x >> y;
        line[x].push_back(y);
        col[y].push_back(x);
        v.push_back(make_pair(x, y));
        s[(x * base + y) % MOD] = true;
    }
}

inline bool exists(unsigned long long x, unsigned long long y)
{
    return s[(x * base + y) % MOD];
}

void rezolvare()
{
    int difX, difY;
    for(auto &p:v)
    {
        if(line[p.first].size() < col[p.second].size())
        {
            for(auto y:line[p.first])
                if(y != p.second)
                {
                    difY = abs(p.second - y);
                    if(exists(p.first + difY, p.second))
                        rasp++;
                    if(p.first >= difY && exists(p.first - difY, p.second))
                        rasp++;
                }
        }
        else
        {
            for(auto x:col[p.second])
                if(x != p.first)
                {
                    difX = abs(p.first - x);
                    if(exists(p.first, p.second + difX))
                        rasp++;
                    if(p.second >= difX && exists(p.first, p.second - difX))
                        rasp++;
                }
        }
    }
    cout << rasp;
}

int main()
{
    citire();
    rezolvare();
    return 0;
}