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.util.*;
import java.io.*;

public class d
{
	public static void main(String[] arg) throws IOException
	{
		new d();
	}	
	public d() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		HashSet<Integer>[] xList = new HashSet[100_001];
		HashSet<Integer>[] yList = new HashSet[100_001];
		int[] xCount = new int[100_001];
		int[] yCount = new int[100_001];
		for(int i = 0; i < n; i++)
		{
			x[i] = in.nextInt();
			y[i] = in.nextInt();
			xCount[x[i]]++;
			yCount[y[i]]++;
		}
		int[][] xl = new int[100_001][];
		int[][] yl = new int[100_001][];

		for(int i = 0; i <= 100_000; i++)
		{
			xl[i] = new int[xCount[i]];
			yl[i] = new int[yCount[i]];
			xCount[i] = 0;
			yCount[i] = 0;
		}
		for(int i = 0; i < n; i++)
		{
			if(xList[x[i]] == null) xList[x[i]] = new HashSet<Integer>();
			if(yList[y[i]] == null) yList[y[i]] = new HashSet<Integer>();
			xList[x[i]].add(y[i]);
			yList[y[i]].add(x[i]);
			xl[x[i]][xCount[x[i]]++] = y[i];
			yl[y[i]][yCount[y[i]]++] = x[i];
		}
		for(int i = 0; i <= 100_000; i++)
		{
			Arrays.sort(xl[i]);
			Arrays.sort(yl[i]);
		}
		long ans = 0;
		for(int i = 0; i < n; i++)
		{
			if(xl[x[i]].length <= yl[y[i]].length)
			{
				for(int v : xl[x[i]])
				{
					if(v >= y[i]) break;
					int dist = y[i]-v;
					if(x[i]-dist >= 0 && xList[x[i]-dist] != null && xList[x[i]-dist].contains(y[i]) && xList[x[i]-dist].contains(v))
					{
						ans++;
					}
				}
			}
			else
			{
				for(int v : yl[y[i]])
				{
					if(v >= x[i]) break;
					int dist = x[i]-v;
					if(y[i]-dist >= 0 && yList[y[i]-dist] != null && yList[y[i]-dist].contains(x[i]) && yList[y[i]-dist].contains(v))
					{
						ans++;
					}
				}
			}
		}

		out.println(ans);
		in.close(); out.close();
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}
