← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n int
	fmt.Fscan(in, &n)

	// Maps to assign unique IDs to distinct X and Y coordinates.
	// X and Y coordinates are treated as separate sets of nodes in a bipartite graph.
	xToID := make(map[int]int)
	yToID := make(map[int]int)
	var adj [][]int

	// Helper function to map coordinate to ID
	getID := func(m map[int]int, val int) int {
		if id, ok := m[val]; ok {
			return id
		}
		id := len(adj)
		m[val] = id
		adj = append(adj, []int{})
		return id
	}

	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		u := getID(xToID, x)
		v := getID(yToID, y)
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	mod := int64(1000000007)
	numNodes := len(adj)
	
	// Precompute powers of 2
	pow2 := make([]int64, numNodes+1)
	pow2[0] = 1
	for i := 1; i <= numNodes; i++ {
		pow2[i] = (pow2[i-1] * 2) % mod
	}

	visited := make([]bool, numNodes)
	ans := int64(1)
	stack := make([]int, 0, numNodes)

	// Iterate over all connected components
	for i := 0; i < numNodes; i++ {
		if !visited[i] {
			compV := 0 // Number of vertices in the component
			compE := 0 // Number of edges in the component
			
			// Iterative DFS
			visited[i] = true
			stack = append(stack, i)
			
			for len(stack) > 0 {
				u := stack[len(stack)-1]
				stack = stack[:len(stack)-1]
				
				compV++
				compE += len(adj[u])

				for _, v := range adj[u] {
					if !visited[v] {
						visited[v] = true
						stack = append(stack, v)
					}
				}
			}
			
			// Each edge is counted twice in undirected graph
			compE /= 2
			
			// Calculate ways for this component
			ways := pow2[compV]
			// If component is a tree (Edges = Vertices - 1), we cannot form the full set
			if compE == compV-1 {
				ways = (ways - 1 + mod) % mod
			}
			// If component contains a cycle (Edges >= Vertices), we can form any subset (2^V)
			
			ans = (ans * ways) % mod
		}
	}

	fmt.Fprintln(out, ans)
}
```