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
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SerejaAndSquares solver = new SerejaAndSquares();
        solver.solve(1, in, out);
        out.close();
    }

    static class SerejaAndSquares {
        static final int N = 123457;

        private int hashCode(int x, int y) {
            return x * N + y;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> mp = new HashSet<>();
            ArrayList<Integer>[] points = new ArrayList[100001];
            for (int i = 0; i < 100001; i++) {
                points[i] = new ArrayList<>();
            }
            for (int i = 0; i < n; i++) {
                int x = in.nextInt(), y = in.nextInt();
                points[x].add(y);
                mp.add(hashCode(x, y));
            }
            int sqrt = 320;
            long answer = 0;
            for (int i = 0; i < 100001; i++) {
                Collections.sort(points[i]);
            }
            for (int i = 0; i < 100001; i++) {
                if (points[i].isEmpty()) continue;
                if (points[i].size() <= sqrt) {
                    for (int a = 0; a < points[i].size(); a++) {
                        for (int b = a + 1; b < points[i].size(); b++) {
                            int distance = points[i].get(b) - points[i].get(a);
                            int hash1 = hashCode(i - distance, points[i].get(a));
                            int hash2 = hashCode(i - distance, points[i].get(b));
                            if (mp.contains(hash1) && mp.contains(hash2)) answer++;
                            if (i + distance < 100001 && points[i + distance].size() > sqrt) {
                                hash1 = hashCode(i + distance, points[i].get(a));
                                hash2 = hashCode(i + distance, points[i].get(b));
                                if (mp.contains(hash1) && mp.contains(hash2)) answer++;
                            }
                        }
                    }
                } else {
                    for (int j = i + 1; j < 100001; j++) {
                        if (points[j].size() <= sqrt) continue;
                        int a = 0, b = 0;
                        while (a < points[i].size() && b < points[j].size()) {
                            int x = points[i].get(a);
                            int y = points[j].get(b);
                            if (x == y) {
                                a++;
                                int distance = j - i;
                                int hash1 = hashCode(i, x + distance);
                                if (!mp.contains(hash1)) continue;
                                int hash2 = hashCode(j, y + distance);
                                if (!mp.contains(hash2)) continue;
                                answer++;
                            } else if (x < y) a++;
                            else b++;
                        }
                    }
                }
            }
            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

