#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
const int inf = 0x7f7f7f7f;
const int mod = (int)(1e9 + 7);
const long long INF = 1LL << 50;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int mask = 65535;
vector<int> W[maxn];
bool ok(int x, int y) {
  if (x >= maxn || y >= maxn) return 0;
  return binary_search(W[x].begin(), W[x].end(), y);
}
int main() {
  ios::sync_with_stdio(false);
  int n, i, j, k, u, x, y;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> x >> y;
    W[x].push_back(y);
  }
  for (i = 0; i < maxn; ++i) {
    sort(W[i].begin(), W[i].end());
  }
  int block = (int)sqrt(n + 0.0);
  vector<int>::iterator it, jt;
  int ans = 0, d;
  for (i = 0; i < maxn; ++i) {
    int sz = W[i].size();
    if (sz <= block) {
      for (j = 0; j < sz; ++j) {
        for (k = j + 1; k < sz; ++k) {
          d = W[i][k] - W[i][j];
          y = W[i][j];
          x = i;
          ans += ok(x + d, y) && ok(x + d, y + d);
        }
      }
    } else {
      for (j = i + 1; j < maxn; ++j) {
        int sz = W[j].size();
        d = j - i;
        for (k = 0; k < sz; ++k) {
          x = j;
          y = W[j][k];
          ans += ok(j, y + d) && ok(i, y) && ok(i, y + d);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Create a solution in CPP for the following problem:

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;
const int maxn = 100001;
const int inf = 0x7f7f7f7f;
const int mod = (int)(1e9 + 7);
const long long INF = 1LL << 50;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int mask = 65535;
vector<int> W[maxn];
bool ok(int x, int y) {
  if (x >= maxn || y >= maxn) return 0;
  return binary_search(W[x].begin(), W[x].end(), y);
}
int main() {
  ios::sync_with_stdio(false);
  int n, i, j, k, u, x, y;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> x >> y;
    W[x].push_back(y);
  }
  for (i = 0; i < maxn; ++i) {
    sort(W[i].begin(), W[i].end());
  }
  int block = (int)sqrt(n + 0.0);
  vector<int>::iterator it, jt;
  int ans = 0, d;
  for (i = 0; i < maxn; ++i) {
    int sz = W[i].size();
    if (sz <= block) {
      for (j = 0; j < sz; ++j) {
        for (k = j + 1; k < sz; ++k) {
          d = W[i][k] - W[i][j];
          y = W[i][j];
          x = i;
          ans += ok(x + d, y) && ok(x + d, y + d);
        }
      }
    } else {
      for (j = i + 1; j < maxn; ++j) {
        int sz = W[j].size();
        d = j - i;
        for (k = 0; k < sz; ++k) {
          x = j;
          y = W[j][k];
          ans += ok(j, y + d) && ok(i, y) && ok(i, y + d);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

```