There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).

We will repeat the following operation as long as possible:

* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.



We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
x_1 y_1
:
x_N y_N


Output

Print the maximum number of times we can do the operation.

Examples

Input

3
1 1
5 1
5 5


Output

1


Input

2
10 10
20 20


Output

0


Input

9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5


Output

16
import java.util.*;

public class Main {
	public static class UnionFind {
		int[] param;
		int[] rank;
		int N;
		int xlen;
		
		public UnionFind(int n) {
			N=n;
			param = new int[N];
			rank = new int[N];
			for(int i=0; i<N; i++)
				param[i] = i;
		}
		
		public void init() {
			for(int i=0; i<N; i++)
				param[i] = i;
			Arrays.fill(rank, 0);
		}
		
		public UnionFind(int x, int y) {
			this(x*y);
			xlen=y;
		}
		
		public boolean same(int a, int b) {
			return getRoot(a)==getRoot(b);
		}
		
		public boolean same(int x1, int y1, int x2, int y2) {
			return same(x1*xlen+y1, x2*xlen+y2);
		}
		
		public int getRoot(int a) {
			if(param[a]==a) return a;
			else return (param[a] = getRoot(param[a]));
		}
		
		public void unite(int a, int b) {
			a = getRoot(a);
			b = getRoot(b);
			if(a==b)
				return;
			
			if(rank[a] < rank[b]) {
				param[a] = b;
			} else {
				param[b] = a;
				if(rank[a]==rank[b])
					rank[a]++;
			}
		}
		
		public void unite(int x1, int y1, int x2, int y2) {
			unite(x1*xlen+y1, x2*xlen+y2);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		HashMap<Integer, ArrayList<Integer>> xset = new HashMap<>();
		HashMap<Integer, ArrayList<Integer>> yset = new HashMap<>();
		HashSet<Integer> xall = new HashSet<>();
		
		for(int i=0; i<N; i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			
			ArrayList<Integer> ys = xset.get(x);
			if(ys == null) {
				ys = new ArrayList<>();
			}
			ys.add(y);
			xset.put(x, ys);
			
			ArrayList<Integer> xs = yset.get(y);
			if(xs == null) {
				xs = new ArrayList<>();
			}
			xs.add(x);
			yset.put(y, xs);
			
			xall.add(x);
		}
		
		UnionFind uf = new UnionFind(100000);
		Iterator<Integer> it = yset.keySet().iterator();
		while(it.hasNext()) {
			int y = it.next();
			ArrayList<Integer> xlist = yset.get(y);
			for(int i : xlist) {
				uf.unite(xlist.get(0), i);
			}
		}
		
		HashMap<Integer, ArrayList<Integer>> xgroup = new HashMap<>();
		
		for(int x=0; x<100000; x++) {
			if(xall.contains(x)) {
				int root = uf.getRoot(x);
				ArrayList<Integer> xs = xgroup.get(root);
				if(xs == null) {
					xs = new ArrayList<>();
				}
				xs.add(x);
				xgroup.put(root, xs);
			}
		}
		
		long finalSize = 0;
		it = xgroup.keySet().iterator();
		while(it.hasNext()) {
			ArrayList<Integer> xlist = xgroup.get(it.next());
			HashSet<Integer> ys = new HashSet<>();
			for(int x : xlist) {
				ys.addAll(xset.get(x));
			}
			finalSize += (long)xlist.size()*ys.size();
		}
		
		System.out.println(finalSize - N);
		sc.close();
	}
}
