#include <bits/stdc++.h>
using namespace std;
struct HashMap {
  vector<pair<int, int> > g[1000007];
  void ins(int x, int y) {
    int id = ((long long)x * 1000000007 + y) % 1000007;
    g[id].push_back(make_pair(x, y));
  }
  bool get(int x, int y) {
    int id = ((long long)x * 1000000007 + y) % 1000007;
    for (int i = 0; i < g[id].size(); i++)
      if (g[id][i].first == x && g[id][i].second == y) return true;
    return false;
  }
};
int n;
HashMap mp;
vector<int> row[100011];
vector<int> rateB;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[y].push_back(x);
    mp.ins(x, y);
  }
  int di = (int)sqrt(n);
  long long int ans = 0;
  for (int a = 0; a <= 100000; a++) {
    if (row[a].size() != 0) {
      sort(row[a].begin(), row[a].end());
      if (row[a].size() <= di) {
        for (int i = 0; i < row[a].size(); i++) {
          for (int j = i + 1; j < row[a].size(); j++) {
            int x1 = row[a][i];
            int x2 = row[a][j];
            int dis = x2 - x1;
            if (mp.get(x1, a + dis) && mp.get(x2, a + dis)) ans++;
            if (a - dis >= 0 && row[a - dis].size() > di &&
                (mp.get(x1, a - dis) && mp.get(x2, a - dis)))
              ans++;
          }
        }
      } else
        rateB.push_back(a);
    }
  }
  for (int i = 0; i < rateB.size(); i++) {
    for (int j = i + 1; j < rateB.size(); j++) {
      int a = rateB[i];
      int b = rateB[j];
      int u = 0, p = 0;
      int dis = b - a;
      while (u < row[a].size() && p < row[b].size()) {
        if (row[a][u] < row[b][p])
          u++;
        else if (row[a][u] > row[b][p])
          p++;
        else {
          int x1 = row[a][u];
          if (mp.get(x1 + dis, a) && mp.get(x1 + dis, b)) ans++;
          u++;
          p++;
        }
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.

Input

The first line contains integer n (1 ≤ n ≤ 105). Each of the next n lines contains two integers xi, yi (0 ≤ xi, yi ≤ 105), the integers represent the coordinates of the i-th point. It is guaranteed that all the given points are distinct.

Output

In a single line print the required number of squares.

Examples

Input

5
0 0
0 2
2 0
2 2
1 1


Output

1


Input

9
0 0
1 1
2 2
0 1
1 0
0 2
2 0
1 2
2 1


Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct HashMap {
  vector<pair<int, int> > g[1000007];
  void ins(int x, int y) {
    int id = ((long long)x * 1000000007 + y) % 1000007;
    g[id].push_back(make_pair(x, y));
  }
  bool get(int x, int y) {
    int id = ((long long)x * 1000000007 + y) % 1000007;
    for (int i = 0; i < g[id].size(); i++)
      if (g[id][i].first == x && g[id][i].second == y) return true;
    return false;
  }
};
int n;
HashMap mp;
vector<int> row[100011];
vector<int> rateB;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[y].push_back(x);
    mp.ins(x, y);
  }
  int di = (int)sqrt(n);
  long long int ans = 0;
  for (int a = 0; a <= 100000; a++) {
    if (row[a].size() != 0) {
      sort(row[a].begin(), row[a].end());
      if (row[a].size() <= di) {
        for (int i = 0; i < row[a].size(); i++) {
          for (int j = i + 1; j < row[a].size(); j++) {
            int x1 = row[a][i];
            int x2 = row[a][j];
            int dis = x2 - x1;
            if (mp.get(x1, a + dis) && mp.get(x2, a + dis)) ans++;
            if (a - dis >= 0 && row[a - dis].size() > di &&
                (mp.get(x1, a - dis) && mp.get(x2, a - dis)))
              ans++;
          }
        }
      } else
        rateB.push_back(a);
    }
  }
  for (int i = 0; i < rateB.size(); i++) {
    for (int j = i + 1; j < rateB.size(); j++) {
      int a = rateB[i];
      int b = rateB[j];
      int u = 0, p = 0;
      int dis = b - a;
      while (u < row[a].size() && p < row[b].size()) {
        if (row[a][u] < row[b][p])
          u++;
        else if (row[a][u] > row[b][p])
          p++;
        else {
          int x1 = row[a][u];
          if (mp.get(x1 + dis, a) && mp.get(x1 + dis, b)) ans++;
          u++;
          p++;
        }
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}

```