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.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>). Each of the next *n* lines contains two integers *x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub> (0 ≤ *x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>), the integers represent the coordinates of the *i*-th point. It is guaranteed that all the given points are distinct.
def f0(points):
    pset = set((a, b) for a, b in points)
    n = len(points)
    ans = 0
    for i in range(n - 1):
        x1, y1 = points[i]
        for j in range(i + 1, n):
            x2, y2 = points[j]
            if y1 != y2:
                continue
            d = abs(x1 - x2)
            if (x1, y1 + d) in pset and (x2, y2 + d) in pset:
                ans += 1
    return ans


def f1(points):
    from collections import defaultdict
    points = sorted(points)
    pset = set((a, b) for a, b in points)

    x2p = defaultdict(list)
    y2p = defaultdict(list)
    for x, y in points:
        x2p[x].append(y)
        y2p[y].append(x)
    x2s = {x: 0 for x in x2p}
    y2s = {y: 0 for y in y2p}

    ans = 0
    for x, y in points:
        x2s[x] += 1
        y2s[y] += 1
        x_rem = len(x2p[x]) - x2s[x]
        y_rem = len(y2p[y]) - y2s[y]
        if x_rem < y_rem:  # 垂直方向
            arr = x2p[x]
            start = x2s[x]
            for t in range(start, len(arr)):
                c, d = x, arr[t]
                size = abs(d - y)
                p1 = (x + size, y)
                p2 = (c + size, d)
                ans += int(p1 in pset and p2 in pset)
        else:  # 水平方向
            arr = y2p[y]
            start = y2s[y]
            for t in range(start, len(arr)):
                c, d = arr[t], y
                size = abs(c - x)
                p1 = (x, y + size)
                p2 = (c, d + size)
                ans += int(p1 in pset and p2 in pset)
    return ans


def judge(points):
    lcls = locals().copy()
    vals = [
        f0(points),
        f1(points),
    ]
    v0 = vals[0]
    for vx in vals[1:]:
        if vx != v0:
            print("DIFF FOUND")
            for k, v in lcls.items():
                print(f"{k}={v}")
            print()
            for i, v in enumerate(vals):
                print(f"r{i}={v}")
            exit(1)


def test():
    import numpy.random as r
    lo, hi = 0, 10
    N = 50
    for i in range(10000):
        n = r.randint(1, N)
        points = [r.randint(lo, hi, 2).tolist() for _ in range(n)]
        points = list({(a, b) for a, b in points})
        judge(points)
        if i % 1000 == 0:
            print(i)
    print("ac")


# test()

n = int(input())
points = [list(map(int, input().split())) for i in range(n)]
print(f1(points))
