CodeEff/ECCO huggingface dataset:
# Original solution
from math import floor
from fractions import Fraction
from decimal import Decimal


def com_interest(n: int) -> int:
    saving = Decimal(100)
    interest_per = 0.01
    years = 0

    while True:
        years += 1
        b = Decimal('1.01')
        saving = int(saving) * b
        if saving >= n:
            break
    return years


print((com_interest(int(eval(input())))))

# Optimized solution
from decimal import Decimal


def com_interest(n: int) -> int:
    saving = Decimal('100')
    interest_per = 0.01
    years = 0

    while True:
        years += 1
        saving = int(saving * Decimal('1.01'))
        if saving >= n:
            break
    return years


print((com_interest(int(eval(input())))))
# Original solution
from decimal import Decimal
x=int(eval(input()))
n=Decimal("100")
ans=0
while True:
    ans+=1
    n*=Decimal("1.01")
    n//=1
    if n>=x:
        print(ans)
        break

# Optimized solution
x=int(eval(input()))
n=100
ans=0
while True:
    ans+=1
    n+=n//100
    if n>=x:
        print(ans)
        break
# Original solution
X = int(eval(input()))
y = 100
flag = 1
con = 0
while flag:
  y *= 1.01
  y = int(y)
  con += 1
  if y >= X:
    flag = 0
print(con)
  

# Optimized solution
X = int(eval(input()))
money = 100
ans = 0
while money < X:
  ans += 1
  money = int(money*1.01)
print(ans)
# Original solution
x = int(eval(input()))
year = 0
m = 100

for i in range(100000):
    m = int(m*1.01)
    year += 1
    if m >= x:
        print(year)
        exit()

# Optimized solution
x = int(eval(input()))
year = 0
m = 100

for i in range(100000):
    m = m*101//100
    year += 1
    if m >= x:
        print(year)
        exit()
# Original solution
while 1:
    N,T,L,B = list(map(int,input().split()))
    if N == 0: break
    lose = [int(input()) for i in range(L)]
    back = [int(input()) for i in range(B)]

    dp = [[0.0]*(N+1) for i in range(T+2)]
    dp[0][0] = 1.0
    ans = 0.0
    p = 1.0/6.0
    for t in range(T):
        for i in range(N):
            tt = t-1 if i in lose else t
            for j in range(i+1,i+7):
                if j > N: j = N-j%N
                if j in back:
                    dp[t+1][0] += p*dp[tt][i]
                else:
                    dp[t+1][j] += p*dp[tt][i]
        dp[t+1][N] += dp[t][N]
    print("%.6f"%dp[T][N])

# Optimized solution
while 1:
    N,T,L,B = list(map(int,input().split()))
    if N == 0: break
    lose = set([int(input()) for i in range(L)])
    back = set([int(input()) for i in range(B)])
    dp = [[0.]*(N+1) for i in range(T+1)]
    dp[0][0] = 1.
    p = 1./6.
    for t in range(T):
        for i in range(N):
            tt = t-1 if i in lose else t
            for j in range(i+1,i+7):
                if j > N: j = N-j%N
                if j in back: j = 0
                dp[t+1][j] += p*dp[tt][i]
        dp[t+1][N] += dp[t][N]
    print("%.6f"%dp[T][N])
# Original solution
while 1:
	N, T, L, B = list(map(int,input().split(" ")))
	if N == T == L == B == 0: break
	check = 0
	dp = [[0 for _ in range(N+1)] for _ in range(T+1)]
	Lose = set([int(input()) for _ in range(L)])
	Back = set([int(input()) for _ in range(B)])
	dp[0][0] = 1
	for i in range(T):
		for j in range(N):
			rank = i-1 if j in Lose else i
			for d in range(1,7):
				next = j + d
				if next > N :
					next = N - (next - N)
				if next in Back:
					dp[i+1][0] += dp[rank][j] / 6.
				else :
					dp[i+1][next] += dp[rank][j] / 6.
	
	print("%6f" % sum([dp[i][N] for i in range(1,T+1)]))

# Optimized solution
while 1:
	N, T, L, B = list(map(int,input().split(" ")))
	if N == T == L == B == 0: break
	dp = [[0 for _ in range(N+1)] for _ in range(T+1)]
	Lose = set([int(input()) for _ in range(L)])
	Back = set([int(input()) for _ in range(B)])
	dp[0][0] = 1
	for i in range(T):
		for j in range(N):
			rank = i-1 if j in Lose else i
			for d in range(1,7):
				next = j + d
				if next > N :
					next = N - (next - N)
				if next in Back:
					dp[i+1][0] += dp[rank][j] / 6.
				else :
					dp[i+1][next] += dp[rank][j] / 6.
	
	print("%6f" % sum([dp[i][N] for i in range(1,T+1)]))
# Original solution
from collections import deque
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(eval(input()))
same = set()
xseq = []
yseq = []
uf = UnionFind(N)
ans = 0

for i in range(N):
    x,y = (int(x) for x in input().split())
    xseq.append((x,i))
    yseq.append((y,i))
xseq.sort()
yseq.sort()
xdiff = [(xseq[i][0]-xseq[i-1][0],(xseq[i][1],xseq[i-1][1])) for i in range(1,N)]
ydiff = [(yseq[i][0]-yseq[i-1][0],(yseq[i][1],yseq[i-1][1])) for i in range(1,N)]
diff = xdiff + ydiff
diff.sort()
d = deque(diff)

for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
    if uf.parents.count(-1*N) == 1:
        break
print(ans)

# Optimized solution
from collections import deque
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(eval(input()))
xseq = []
yseq = []
uf = UnionFind(N)
ans = 0

for i in range(N):
    x,y = (int(x) for x in input().split())
    xseq.append((x,i))
    yseq.append((y,i))
xseq.sort()
yseq.sort()
xdiff = [(xseq[i][0]-xseq[i-1][0],(xseq[i][1],xseq[i-1][1])) for i in range(1,N)]
ydiff = [(yseq[i][0]-yseq[i-1][0],(yseq[i][1],yseq[i-1][1])) for i in range(1,N)]
diff = xdiff + ydiff
diff.sort()
d = deque(diff)

for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
print(ans)
# Original solution
N=int(eval(input()))
city=[0]*N
for i in range(N):
    x,y=list(map(int,input().split()))
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]>root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)

# Optimized solution
import sys
input=sys.stdin.readline
N=int(eval(input()))
P=[tuple(map(int,input().split())) for i in range(N)]
X=[(i,P[i][0]) for i in range(N)]
Y=[(i,P[i][1]) for i in range(N)]
X.sort(key=lambda x:x[1])
Y.sort(key=lambda x:x[1])
Z=[(X[i][0],X[i+1][0],X[i+1][1]-X[i][1]) for i in range(N-1)]+[(Y[i][0],Y[i+1][0],Y[i+1][1]-Y[i][1]) for i in range(N-1)]
Z.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
ans=0
for i,j,k in Z:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        root[ri]+=root[rj]
        root[rj]=ri
        ans+=k
    else:
        root[rj]+=root[ri]
        root[ri]=rj
        ans+=k
print(ans)
# Original solution
import heapq

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.count = 0

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1

			self.count += 1
			return True
		return False

n = int(eval(input()))
x = []
y = []
for i in range(n):
	a, b = list(map(int, input().split()))
	x.append([i, a])
	y.append([i, b])

vx = sorted(x, key=lambda x: x[1])
vy = sorted(y, key=lambda x: x[1])

edges = []
uf = UnionFind(n)

for i in range(n - 1):
	if vx[i][1] == vx[i + 1][1]:
		uf.union(vx[i][0], vx[i + 1][0])
	else:
		heapq.heappush(edges, (vx[i + 1][1] - vx[i][1], vx[i][0], vx[i + 1][0]))

	if vy[i][1] == vy[i + 1][1]:
		uf.union(vy[i][0], vy[i + 1][0])
	else:
		heapq.heappush(edges, (vy[i + 1][1] - vy[i][1], vy[i][0], vy[i + 1][0]))


#edges = sorted(edges, key=lambda x: x[2], reverse=True)
#print(edges)

ans = 0

while edges != []:
	e = heapq.heappop(edges)
	if uf.union(e[1], e[2]):
		ans += e[0]
	if uf.count == n - 1:
		break

print(ans)

# Optimized solution
import heapq
import sys
sys.setrecursionlimit(10 ** 7)

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.count = 0

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1

			self.count += 1
			return True
		return False

n = int(eval(input()))
x = []
y = []
for i in range(n):
	a, b = list(map(int, input().split()))
	x.append([i, a])
	y.append([i, b])

vx = sorted(x, key=lambda x: x[1])
vy = sorted(y, key=lambda x: x[1])

edges = []
uf = UnionFind(n)

for i in range(n - 1):
	if vx[i][1] == vx[i + 1][1]:
		uf.union(vx[i][0], vx[i + 1][0])
	else:
		heapq.heappush(edges, (vx[i + 1][1] - vx[i][1], vx[i][0], vx[i + 1][0]))

	if vy[i][1] == vy[i + 1][1]:
		uf.union(vy[i][0], vy[i + 1][0])
	else:
		heapq.heappush(edges, (vy[i + 1][1] - vy[i][1], vy[i][0], vy[i + 1][0]))


#edges = sorted(edges, key=lambda x: x[2], reverse=True)
#print(edges)

ans = 0

while edges != []:
	e = heapq.heappop(edges)
	if uf.union(e[1], e[2]):
		ans += e[0]
	if uf.count == n - 1:
		break

print(ans)
# Original solution
import heapq
def prim_heap():
    used = [True] * n #True:不使用
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist,e)
    used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,e)
        res += minedge[0]
    return res

#########################
n = int(eval(input()))

#隣接リストの作成 edge[i]:[コスト,行先]
edge = [[] for i in range(n)]
x_sort = [] #[Xi,Yi,点番号]
y_sort = [] #[Yi,Xi,点番号]
for i in range(n):
    X,Y = list(map(int,input().split()))
    x_sort.append([X,Y,i])
    y_sort.append([Y,X,i])
x_sort.sort()
y_sort.sort()
for i in range(1,n):
    edge[x_sort[i][2]].append([min(abs(x_sort[i][0]-x_sort[i-1][0]),abs(x_sort[i][1]-x_sort[i-1][1])),x_sort[i-1][2]])
    edge[x_sort[i-1][2]].append([min(abs(x_sort[i][0]-x_sort[i-1][0]),abs(x_sort[i][1]-x_sort[i-1][1])),x_sort[i][2]])
    edge[y_sort[i][2]].append([min(abs(y_sort[i][0]-y_sort[i-1][0]),abs(y_sort[i][1]-y_sort[i-1][1])),y_sort[i-1][2]])
    edge[y_sort[i][2]].append([min(abs(y_sort[i][0]-y_sort[i-1][0]),abs(y_sort[i][1]-y_sort[i-1][1])),y_sort[i-1][2]])
print((prim_heap()))

# Optimized solution
import heapq
def prim_heap():
    used = [True] * n #True:不使用
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist,e)
    used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,e)
        res += minedge[0]
    return res

#########################
n = int(eval(input()))

#隣接リストの作成 edge[i]:[コスト,行先]
edge = [[] for i in range(n)]
p=[]
edge=[[] for i in range(n)]
for i in range(n):
    p.append(tuple(map(int,input().split()))+tuple([i]))
x_sorted=sorted(p,key=lambda x:x[0])
y_sorted=sorted(p,key=lambda x:x[1])
for i in range(n-1):
    edge[x_sorted[i][2]].append((x_sorted[i+1][0]-x_sorted[i][0],x_sorted[i+1][2]))
    edge[x_sorted[i+1][2]].append((x_sorted[i+1][0]-x_sorted[i][0],x_sorted[i][2]))
    edge[y_sorted[i][2]].append((y_sorted[i+1][1]-y_sorted[i][1],y_sorted[i+1][2]))
    edge[y_sorted[i+1][2]].append((y_sorted[i+1][1]-y_sorted[i][1],y_sorted[i][2]))

print((prim_heap()))
# Original solution
#!/usr/bin/env python3

import heapq

def main():
    n = int(eval(input()))
    nodes = []
    for i in range(n):
        xi, yi = list(map(int, input().split()))
        nodes.append((i, xi, yi))

    adj = [[] for i in range(n)]
    nodes.sort(key=(lambda x: x[1]))
    for j in range(n):
        i = nodes[j][0]
        if j - 1 >= 0:
            i1 = nodes[j - 1][0]
            adj[i].append(i1)
        if j + 1 < n:
            i1 = nodes[j + 1][0]
            adj[i].append(i1)
    nodes.sort(key=(lambda x: x[2]))
    for j in range(n):
        i = nodes[j][0]
        if j - 1 >= 0:
            i1 = nodes[j - 1][0]
            adj[i].append(i1)
        if j + 1 < n:
            i1 = nodes[j + 1][0]
            adj[i].append(i1)
    nodes.sort(key=(lambda x: x[0]))

    res = 0
    q = [(0, 0)]
    visited = [False for i in range(n)]
    while q:
        d, i = heapq.heappop(q)
        if visited[i]:
            continue
        visited[i] = True
        res += d
        for j in adj[i]:
            if visited[j]:
                continue
            heapq.heappush(q, (dist(i, j, nodes), j))
    print(res)

def dist(i, j, nodes):
    _, xi, yi = nodes[i]
    _, xj, yj = nodes[j]
    res = min(abs(xi - xj), abs(yi - yj))
    return res

if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3

import heapq

def main():
    n = int(eval(input()))
    nodes = []
    for i in range(n):
        xi, yi = list(map(int, input().split()))
        nodes.append((i, xi, yi))

    adj = [[] for i in range(n)]
    nodesx = sorted(nodes, key=(lambda x: x[1]))
    for j in range(n - 1):
        i1 = nodesx[j][0]
        i2 = nodesx[j + 1][0]
        adj[i1].append(i2)
        adj[i2].append(i1)
    nodesy = sorted(nodes, key=(lambda x: x[2]))
    for j in range(n - 1):
        i1 = nodesy[j][0]
        i2 = nodesy[j + 1][0]
        adj[i1].append(i2)
        adj[i2].append(i1)

    res = 0
    q = [(0, 0)]
    visited = [False for i in range(n)]
    while q:
        d, i = heapq.heappop(q)
        if visited[i]:
            continue
        visited[i] = True
        res += d
        for j in adj[i]:
            if visited[j]:
                continue
            heapq.heappush(q, (dist(i, j, nodes), j))
    print(res)

def dist(i, j, nodes):
    _, xi, yi = nodes[i]
    _, xj, yj = nodes[j]
    res = min(abs(xi - xj), abs(yi - yj))
    return res

if __name__ == "__main__":
    main()
# Original solution
import sys
import heapq
input = sys.stdin.readline

class Node:
    def __init__(self, id):
        self.id = id
        self.check = False
        self.link = []
        self.cost = []
    
    def __lt__(self, other):
        return self.id < other.id

def main():
    N = int(eval(input()))
    
    nodes = [Node(i) for i in range(N)]

    xy = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        xy.append((i, x, y))
    
    for t in range(2):
        if t == 0:
            xy = sorted(xy, key=lambda x: x[1])# x昇順
        else:
            xy = sorted(xy, key=lambda x: x[2])# y昇順
        p_n, p_x, p_y = xy[0]
        for i in range(1, N):
            n, x, y = xy[i]
            if t == 0:
                cost = abs(x - p_x)# x
            else:
                cost = abs(y - p_y)# y
            nodes[p_n].link.append(nodes[n])
            nodes[p_n].cost.append(cost)
            nodes[n].link.append(nodes[p_n])
            nodes[n].cost.append(cost)
            p_n, p_x, p_y = n, x, y
    q = []
    ans = 0
    heapq.heappush(q, (0, nodes[0]))# edge_cost, node
    while len(q) > 0:
        edge_cost, node = heapq.heappop(q)
        if node.check:
            continue
        node.check = True
        ans += edge_cost
        for i, next_node in enumerate(node.link):
            if not next_node.check:
                heapq.heappush(q, (node.cost[i], next_node))
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline

def same_tree(node_a, node_b):
    if node_a.root() == node_b.root():
        return True

def unite(node_a, node_b):
    root_a = node_a.root()
    root_b = node_b.root()
    if root_a == root_b:
        return
    if root_b.depth > root_a.depth:
        root_a, root_b = root_b, root_a
    root_b.is_root = False
    root_b.parent = root_a
    root_a.depth = max(root_a.depth, root_b.depth+1)

class Node:
    def __init__(self):
        self.is_root = True
        self.parent = None
        self.depth = 1
    
    def root(self):
        node = self
        while not node.is_root:
            node = node.parent
        return node

def main():
    N = int(eval(input()))
    
    nodes = [Node() for i in range(N)]

    # 各町の座標をタプル(i, x, y)に入れて配列に格納
    xy = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        xy.append((i, x, y))
    
    # 使う可能性のある辺のみを取り出す
    edges = []
    xy = sorted(xy, key=lambda x: x[1])# x座標昇順
    # print("x:", xy)
    for i in range(1, N):
        edges.append((xy[i][1] - xy[i-1][1], xy[i-1][0], xy[i][0]))
    xy = sorted(xy, key=lambda x: x[2])# y座標昇順
    # print("y:", xy)
    for i in range(1, N):
        edges.append((xy[i][2] - xy[i-1][2], xy[i-1][0], xy[i][0]))
    
    ans = 0
    edges = sorted(edges)
    # print(edges)
    for (cost, a, b) in edges:
        if not same_tree(nodes[a], nodes[b]):
            unite(nodes[a], nodes[b])
            ans += cost
    print(ans)




if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
import sys
input=sys.stdin.readline
X=[[-10**10,0]]
Y=[[-10**10,0]]

for i in range(N):
    x,y=list(map(int,input().split()))
    X.append([x,i+1])
    Y.append([y,i+1])
X.append([10**10,N+1])
Y.append([10**10,N+1])
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append([X[i][0]-X[i-1][0],X[i-1][1]])
    L[X[i][1]].append([X[i+1][0]-X[i][0],X[i+1][1]])
for i in range(1,N+1):
    L[Y[i][1]].append([Y[i][0]-Y[i-1][0],Y[i-1][1]])
    L[Y[i][1]].append([Y[i+1][0]-Y[i][0],Y[i+1][1]])
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)

# Optimized solution
N=int(eval(input()))
import sys
input=sys.stdin.readline
X=[(-10**10,0)]
Y=[(-10**10,0)]

for i in range(N):
    x,y=list(map(int,input().split()))
    X.append((x,i+1))
    Y.append((y,i+1))
X.append((10**10,N+1))
Y.append((10**10,N+1))
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append((X[i][0]-X[i-1][0],X[i-1][1]))
    L[X[i][1]].append((X[i+1][0]-X[i][0],X[i+1][1]))
for i in range(1,N+1):
    L[Y[i][1]].append((Y[i][0]-Y[i-1][0],Y[i-1][1]))
    L[Y[i][1]].append((Y[i+1][0]-Y[i][0],Y[i+1][1]))
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)
# Original solution

import heapq

def prime_method():
    start = graph[0]
    not_went = [True] * n  # n個の点に行ったかという話
    edges = []
    for e in start:
        heapq.heappush(edges,e)
    not_went[0] = False
    cost = 0
    while len(edges) != 0:
        minedge = heapq.heappop(edges)
        if not not_went[minedge[1]]:
            continue
        v = minedge[1]
        gv = graph[v]
        not_went[v] = False
        for temp in gv:
            if not_went[temp[1]]:  # その頂点に行ってなければ
                heapq.heappush(edges, temp)
        cost += minedge[0]
    return cost
    # a[1] = [[2,3],[5,11]] → 点1からコスト2で頂点3に行ける辺、点1からコスト5で頂点11に行ける辺がある


n = int(eval(input()))
# cities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]
cities = []
for i in range(n):
    cities.append(tuple(map(int,input().split()))+tuple([i]))

graph = [[] for i in  range(n)]


citiesX=sorted(cities,key=lambda x:x[0])
citiesY=sorted(cities,key=lambda x:x[1])

for i in range(n-1):
    graph[citiesX[i][2]].append([(citiesX[i+1][0] - citiesX[i][0]),citiesX[i+1][2]])
    graph[citiesX[i+1][2]].append([(citiesX[i+1][0] - citiesX[i][0]),citiesX[i][2]])
    graph[citiesY[i][2]].append([(citiesY[i+1][1] - citiesY[i][1]),citiesY[i+1][2]])
    graph[citiesY[i+1][2]].append([(citiesY[i+1][1] - citiesY[i][1]),citiesY[i][2]])
print((prime_method()))

# Optimized solution

import heapq

def prime_method():
    not_went = [True] * n  # n個の点に行ったかという話
    edges = []
    start = graph[0]
    for e in start:
        heapq.heappush(edges,e)
    not_went[0] = False
    cost = 0
    while len(edges) != 0:
        minedge = heapq.heappop(edges)
        if not not_went[minedge[1]]:
            continue
        v = minedge[1]
        gv = graph[v]
        not_went[v] = False
        for temp in gv:
            if not_went[temp[1]]:  # その頂点に行ってなければ
                heapq.heappush(edges, temp)
        cost += minedge[0]
    return cost
    # a[1] = [[2,3],[5,11]] → 点1からコスト2で頂点3に行ける辺、点1からコスト5で頂点11に行ける辺がある


n = int(eval(input()))
graph = [[] for i in  range(n)]
cities = []
for i in range(n):
    cities.append(tuple(map(int,input().split()))+tuple([i]))


citiesX=sorted(cities,key=lambda x:x[0])
citiesY=sorted(cities,key=lambda x:x[1])

for i in range(n-1):
    graph[citiesX[i][2]].append(((citiesX[i+1][0] - citiesX[i][0]),citiesX[i+1][2]))
    graph[citiesX[i+1][2]].append(((citiesX[i+1][0] - citiesX[i][0]),citiesX[i][2]))
    graph[citiesY[i][2]].append(((citiesY[i+1][1] - citiesY[i][1]),citiesY[i+1][2]))
    graph[citiesY[i+1][2]].append(((citiesY[i+1][1] - citiesY[i][1]),citiesY[i][2]))
print((prime_method()))