#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> x[100100], y[100100];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    x[a].push_back(b);
    y[b].push_back(a);
  }
  for (int i = 0; i <= 100000; i++) {
    sort(x[i].begin(), x[i].end());
    sort(y[i].begin(), y[i].end());
  }
  int sum = 0;
  for (int i = 0; i <= 100000; i++)
    for (int j = 0; j < x[i].size(); j++) {
      int tx = i, ty = x[i][j], px = j + 1;
      int py = upper_bound(y[ty].begin(), y[ty].end(), tx) - y[ty].begin();
      while (px < x[tx].size() && py < y[ty].size()) {
        if (x[tx][px] - ty < y[ty][py] - tx) {
          px++;
          continue;
        }
        if (x[tx][px] - ty > y[ty][py] - tx) {
          py++;
          continue;
        }
        sum +=
            binary_search(x[y[ty][py]].begin(), x[y[ty][py]].end(), x[tx][px]);
        px++;
        py++;
      }
    }
  printf("%d", sum);
  return 0;
}
