#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<pair<int, int>, bool> M;
int n, sol;
vector<int> row[N], col[N];
int main() {
  cin >> n;
  for (int x, y, i = 0; i < n; ++i) {
    cin >> x >> y;
    M[make_pair(x, y)] = 1;
    row[x].push_back(y);
    col[y].push_back(x);
  }
  for (int i = 0; i < N; ++i) {
    sort(row[i].begin(), row[i].end());
    sort(col[i].begin(), col[i].end());
  }
  for (int i = 0; i < N; ++i) {
    int sza = row[i].size();
    for (int j = 0; j < sza; ++j) {
      int y = row[i][j], k1 = j;
      int k2 = lower_bound(col[y].begin(), col[y].end(), i) - col[y].begin();
      int szb = col[y].size();
      while (k1 < sza && k2 < szb) {
        if (row[i][k1] - y < col[y][k2] - i)
          k1++;
        else if (row[i][k1] - y > col[y][k2] - i)
          k2++;
        else {
          if (row[i][k1] != y && col[y][k2] != i &&
              M[make_pair(col[y][k2], row[i][k1])] == 1)
            sol++;
          k1++;
          k2++;
        }
      }
    }
  }
  cout << sol;
}
