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.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;


public class Main {

	static class Task {
		
		int NN = 100005;
		int MOD = 1000000007;
		int INF = 2009000000;
		long INFINITY = 2000000000000000000L;

		int [][]a;
		List<Integer> [] rows;
		List<Integer> [] cols;
		
		class UnionFind {
			int parent;
			int rank;
			Set<Integer> cols;
			public UnionFind(int parent, int rank, Set<Integer> q) {
				this.parent = parent;
				this.rank = rank;
				this.cols = q;
			}
		}
		
		UnionFind [] uf;
		
		void update(int u, int v){
			Set<Integer> q1 = uf[u].cols;
			Set<Integer> q2 = uf[v].cols;
			for(int e:q2) {
				q1.add(e);
			}			
		}
		
		void union(int u, int v) {
			u = find(u);
			v = find(v);
			if(uf[u].rank == uf[v].rank) {
				++uf[v].rank;
				uf[u].parent = v;
				update(v, u);
			} else {
				if(uf[u].rank > uf[v].rank) {
					uf[v].parent = u;
					update(u, v);
				} else {
					uf[u].parent = v;
					update(v, u);
				}
			}
		}
		
		int find(int x) {
			return uf[x].parent == x 
					? x 
					: (uf[x].parent = find(uf[x].parent));
		}
		
		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			a = new int[n][2];
			rows = new ArrayList[NN];
			cols = new ArrayList[NN];
			uf = new UnionFind[NN];
			for(int i=0;i<NN;++i) {
				rows[i] = new ArrayList<>();
				cols[i] = new ArrayList<>();
			}
			for(int i=0;i<n;++i) {
				a[i][0] = in.nextInt();
				a[i][1] = in.nextInt();
				cols[a[i][0]].add(a[i][1]);
				rows[a[i][1]].add(a[i][0]);
			}
			for(int i=1;i<NN;++i) {
				uf[i] = new UnionFind(
						i, 0, cols[i].stream().collect(Collectors.toSet()));
			}
			for(int col=1;col<NN;++col) {
				if(rows[col].size() < 2)continue;
				int r1= rows[col].get(0);
				for(int i=1;i<rows[col].size();++i) {
					int r2 = rows[col].get(i);
					union(r1, r2);
				}
			}
			long ans = 0;
			for(int row=1;row<NN;++row) {
				if(cols[row].isEmpty())
					continue;
				int tot = uf[find(row)].cols.size();
				ans += 1L * (tot - cols[row].size());
			}
			out.println(ans);
		}
	}
	
	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) { 
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}
	
	public static void main(String[] args) {
        prepareIO(false);
	}
	
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        
        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }
        
        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }
        
        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());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        
    }

}