Harryxun/stf_run huggingface dataset:
H, W = map(int, input().split())
zero_pad = '.' * W
s = []
s.append(zero_pad)
for i in range(H):
    s.append('.' + input() + '.')
s.append(zero_pad)

for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == '#':
            if s[h - 1][w] == '.' and s[h + 1][w] == '.' and s[h][w - 1] == '.' and s[h][w + 1] == '.':
                print('No')
                exit()

print('Yes')


### FIXED CODE ###

H, W = map(int, input().split())
s = [input() for i in range(H)]

# 四隅
# 左上
if s[0][0] == '#':
    if s[0][1] == '.' and s[1][0] == '.':
        print('No')
        exit()
# 右上
if s[0][W - 1] == '#':
    if s[0][W - 2] == '.' and s[1][W - 1] == '.':
        print('No')
        exit()
# 左下
if s[H - 1][0] == '#':
    if s[H - 1][1] == '.' and s[H - 2][0] == '.':
        print('No')
        exit()
# 右下
if s[H - 1][W - 1] == '#':
    if s[H - 1][W - 2] == '.' and s[H - 2][W - 1] == '.':
        print('No')
        exit()

# 上辺
for i in range(1, W - 1):
    if s[0][i] == '#':
        if s[0][i - 1] == '.' and s[0][i + 1] == '.' and s[1][i] == '.':
            print('No')
            exit()

# 下辺
for i in range(1, W - 1):
    if s[H - 1][i] == '#':
        if s[H - 1][i - 1] == '.' and s[H - 1][i + 1] == '.' and s[H - 2][i] == '.':
            print('No')
            exit()

# 左辺
for i in range(1, H - 1):
    if s[i][0] == '#':
        if s[i - 1][0] == '.' and s[i + 1][0] == '.' and s[i][1] == '.':
            print('No')
            exit()

# 右辺
for i in range(1, H - 1):
    if s[i][W - 1] == '#':
        if s[i - 1][W - 1] == '.' and s[i + 1][W - 1] == '.' and s[i][W - 2] == '.':
            print('No')
            exit()

# 中央
for h in range(1, H - 1):
    for w in range(1, W - 1):
        if s[h][w] == '#':
            if s[h - 1][w] == '.' and s[h + 1][w] == '.' and s[h][w - 1] == '.' and s[h][w + 1] == '.':
                print('No')
                exit()

print('Yes')
val= int(input())
return val^2

### FIXED CODE ###

print(input()**2)
from collections import deque
import heapq

def dijkstra(s,g,m):
    color=[0]*n
    dis=[float('inf')]*n
    dis[s]=0
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        color[u]=2
        if dis[u]<t:
            continue
        for v in g[u]:
            if color[v]!=2:
                if dis[u]+m[u][v]<dis[v]:
                    dis[v]=dis[u]+m[u][v]
                    color[v]=1
                    heapq.heappush(pq,[dis[v],v])
    return dis

n,k=map(int,raw_input().split())
cr=[map(int,raw_input().split()) for _ in xrange(n)]
g=[[]*n for _ in xrange(n)]
m=[[0]*n for _ in xrange(n)]
for i in xrange(k):
    a,b=map(int,raw_input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    m[a-1][b-1]=1
    m[b-1][a-1]=1

pq=[]
d=[[]*n for _ in xrange(n)]
for i in xrange(n):
    d[i]=dijkstra(i,g,m)

cost=[[float('inf')]*n for _ in xrange(n)]
newg=[[]*n for _ in xrange(n)]
for i in xrange(n):
    for j in xrange(n):
        if d[i][j]<=cr[i][1]:
            cost[i][j]=cr[i][0]
            newg[i].append(j)

pq=[]
dis=dijkstra(0,newg,cost)
print(dis[n-1])

### FIXED CODE ###

from collections import deque
import heapq

def dijkstra(s,g,m):
    color=[0]*n
    dis=[float('inf')]*n
    dis[s]=0
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        color[u]=2
        if dis[u]<t:
            continue
        for v in g[u]:
            if color[v]!=2:
                if dis[u]+m[u][v]<dis[v]:
                    dis[v]=dis[u]+m[u][v]
                    color[v]=1
                    heapq.heappush(pq,[dis[v],v])
    return dis

n,k=map(int,raw_input().split())
cr=[map(int,raw_input().split()) for _ in xrange(n)]
g=[[]*n for _ in xrange(n)]
for i in xrange(k):
    a,b=map(int,raw_input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

d=[[0]*n for _ in xrange(n)]
cost=[[float('inf')]*n for _ in xrange(n)]
newg=[[]*n for _ in xrange(n)]
for i in xrange(n):
    q=deque([i])
    visited=[0]*n
    visited[i]=1
    while len(q)!=0:
        p=q.popleft()
        for j in g[p]:
            if visited[j]==0:
                visited[j]=1
                d[i][j]=d[i][p]+1
                if d[i][j]<=cr[i][1]:
                    cost[i][j]=cr[i][0]
                    newg[i].append(j)
                    q.append(j)

pq=[]
dis=dijkstra(0,newg,cost)
print(dis[n-1])
N, K = map(int, input())
h = list(map(int, input().split()))

ans = 0
for i in range(N):
	if h[i] >= K:
		ans += 1
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
 
ans = 0
for i in range(N):
	if h[i] >= K:
		ans += 1
print(ans)
n = int(input())
h = [map(int, input().split())]
s = 1
for i in range(n):
  flag = 0
  for j in range(n-1-i):
    if h[j] <= h[n-1-i] + 1:
      flag += 0
    else:
      flag += 1
  if flag != 0:
    s *= 0
if s = 0:
  print("No")
else:
  print("Yes")


### FIXED CODE ###

a, b, c = map(int, input().split())
if b + c <= a:
  print(0)
else:
  print(b + c - a)
import heapq
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = []
ans = []
flag = []
first = [A[0] + B[0] + C[0], [0, 0, 0]]
heapq.heappush(q, first)
flag.append(first[1])
for h in range(k):
    max_ans = heapq.heappop(q)
    ans.append(abs(max_ans[0]))
    i, j, k = max_ans[1]
    if i == len(A)-1:
        i = i-1
    if j == len(B)-1:
        j = j-1
    if k == len(C)-1:
        k = k-1

    lst1 =  [-A[i+1]-B[j]-C[k], [i+1, j, k]]
    if lst1[1] not in flag:
        heapq.heappush(q, lst1)
        flag.append(lst1[1])

    lst2 = [-A[i]-B[j+1]-C[k], [i, j+1, k]]
    if lst2[1] not in flag: 
        heapq.heappush(q, lst2)
        flag.append(lst2[1])

    lst3 = [-A[i]-B[j]-C[k+1], [i, j, k+1]]
    if lst3[1] not in flag:
        heapq.heappush(q, lst3)
        flag.append(lst3[1])
    print(ans[h])

### FIXED CODE ###

import heapq
x, y, z, w = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = []
ans = []
flag = []
first = [A[0] + B[0] + C[0], [0, 0, 0]]
heapq.heappush(q, first)
flag.append(first[1])
for h in range(w):
    max_ans = heapq.heappop(q)
    ans.append(abs(max_ans[0]))
    i, j, k = max_ans[1]

    if i == x-1:
        lst1 =  [-A[i]-B[j]-C[k], [i, j, k]]
    else:
        lst1 =  [-A[i+1]-B[j]-C[k], [i+1, j, k]]
    if lst1[1] not in flag:
        heapq.heappush(q, lst1)
        flag.append(lst1[1])

    if j == y-1:
        lst2 = [-A[i]-B[j]-C[k], [i, j, k]]
    else:
        lst2 = [-A[i]-B[j+1]-C[k], [i, j+1, k]]
    if lst2[1] not in flag: 
        heapq.heappush(q, lst2)
        flag.append(lst2[1])

    if k == z-1:
        lst3 = [-A[i]-B[j]-C[k], [i, j, k]]
    else:
        lst3 = [-A[i]-B[j]-C[k+1], [i, j, k+1]]
    if lst3[1] not in flag:
        heapq.heappush(q, lst3)
        flag.append(lst3[1])
    
    print(ans[h])
i = 0

while True:
 n = int(input())
 if n == 0:break

  print("Case {}: {}".format(i, n))
  i += 1

### FIXED CODE ###

i = 0

while True:
 n = int(input())
 i += 1
 if n == 0:
  break
 print("Case {}: {}".format(i, n))
def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

N,M = map(int,input().split())
if M == 0:
  P = Fib(N+2)
  print(P%1000000007)
else:
  S = []
  for _ in range(M):
    S.append(int(input()))
  S.append(-1)
  S.append(N+1)
  S.sort()  
  P = 1

  for i in range(M+1):
    P *= Fib(S[i+1]-S[i]) 

  print(P%1000000007)


### FIXED CODE ###

a = [int(i) for i in input().split()]
a.sort()
print(a[0]+a[1])
n=int(input())
ans=(n//11)*2
ans+=2 if n-n//11>6 else 1
ans-=1 if n-n//11=0 else 0
print(ans)

### FIXED CODE ###

n=int(input())
ans=(n//11)*2
ans+=2 if n-11*(n//11)>6 else 1
ans-=1 if n-11*(n//11)==0 else 0
print(ans)
a = [input() for _ in range(int(input()))]
b = [input() for _ in range(int(input()))]
l = list(set(a))
c = max(0, max[a.count(i) - b.count(i) for i in l])
print(c)

### FIXED CODE ###

a = [input() for _ in range(int(input()))]
b = [input() for _ in range(int(input()))]
l = list(set(a))
c = max(0, max([a.count(i) - b.count(i) for i in l]))
print(c)
N=int(input())
X=input()
Xnum=int(X,2)
popcount=X.count('1')
if popcount != 1:
    Xnum1=Xnum%(popcount-1)
Xnum0=Xnum%(popcount+1)
for i in range(N):
    if popcount==1 and X[i]=='1':
        print(0)
    if X[i]=='1':
        Xi = (Xnum1 - (2**(N-i-1)%(popcount-1)))%(popcount-1)
    else:
        Xi = (Xnum0 + (2**(N-i-1)%(popcount+1)))%(popcount+1)
    ans = 1
    while Xi!=0:
        Xi = Xi % bin(Xi).count('1')
        ans += 1
    print(ans)

### FIXED CODE ###

N=int(input())
X=input()
popcount=X.count('1')
bi1=[]
bi0=[]
Xnum1 = 0
Xnum0 = 0
if popcount != 1:
    for i in range(N):
        if i==0: bi1.append(1)
        else: bi1.append(bi1[i-1]*2%(popcount-1))
        Xnum1 = (Xnum1 + int(X[N-i-1])*bi1[i])%(popcount-1)
for i in range(N):
    if i==0: bi0.append(1)
    else: bi0.append(bi0[i-1]*2%(popcount+1))
    Xnum0 = (Xnum0 + int(X[N-i-1])*bi0[i])%(popcount+1)
for i in range(N):
    if popcount==1 and X[i]=='1':
        print(0)
        continue
    if X[i]=='1':
        Xi = (Xnum1 - bi1[N-i-1])%(popcount-1)
    else:
        Xi = (Xnum0 + bi0[N-i-1])%(popcount+1)
    ans = 1
    while Xi!=0:
        Xi = Xi % bin(Xi).count('1')
        ans += 1
    print(ans)
s=list(map(int,input().split))
t=10*s[0]+s[1]
k=10*s[2]+s[3]
if 1<=t<=12:
  if 1<=k<=12:
    print("AMBIGUOUS")
  elif:
    print("MMYY")
elif 1<=k<=12:
  print("YYMM")
else:
  print("NA")

### FIXED CODE ###

s=list(input())
s=list(map(int,s))
t=10*s[0]+s[1]
k=10*s[2]+s[3]
if 1<=t<=12:
  if 1<=k<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif 1<=k<=12:
  print("YYMM")
else:
  print("NA")
import bisect
N, Q = map(int, input().split())
A = [int(a) for a in input().split()]

def chk(x, l, m, r):
    rr = m % 2
    xl = x - m//2 - rr
    xr = x + m//2
    
    ll = bisect.bisect_left(A, xl)
    rr = bisect.bisect_left(A, xr+1)-1
    print(x, l, m, r, ll, rr, N)
    if rr - ll + 1 < N - rr - 2:
        if m == (m+r)//2:
            print(1/0)
        return chk(x, m, (m+r)//2, r)
    elif rr - ll + 1 > N - 1 - rr:
        if l == (l+m)//2:
            print(1/0)
        return chk(x, l, (l+m)//2, m)
    else:
        return (m+1)//2
    
    
Y = [0] * N
for i in range(1, N):
    Y[i] = Y[i-1] + A[-i-1]

Z = [0] * N
for i in range(1, N):
    Z[i] = Z[i-1] + A[((1+N)%2)::2]

for q in range(Q):
    x = int(input())
    t = chk(x, 0, A[-1]//2, A[-1])
    print(Y[t]+Z[N-t])


    



### FIXED CODE ###

import sys
input = sys.stdin.readline
def calc(x):
    l, r = 0, (N+1)//2
    while r - l > 1:
        m = (l+r) // 2
        if A[m] + A[2*m] >= 2 * x:
            l = m
        else:
            r = m
    return l
    
N, Q = map(int, input().split())
A = [int(a) for a in input().split()][::-1]
B = [A[0]] + [0] * (N-1)
for i in range(1, N):
    B[i] = B[i-1] + A[i]
C = [A[0]] + [0] * (N-1)
for i in range(2, N, 2):
    C[i] = C[i-2] + A[i]
C[-1] += C[-2]
for _ in range(Q):
    x = int(input())
    c = calc(x)
    print(B[c] + (C[-1] - C[2*c] if c*2<=N else 0))
n = int(input())
cost = 0
points = []
for i in range(n):
    xy = input().split()
    x = int(xy[0])
    y = int(xy[1])
    points.append((x,y))

while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break

print(cost)

### FIXED CODE ###

n = int(input())
if n ==1:
    print( 1)
    exit()
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
dictpq = {}
for i in range(n):
    for j in range(i+1,n):
        p = points[i][0] - points[j][0]
        q = points[i][1] - points[j][1]
        if (p,q) in dictpq:
            dictpq[(p,q)] +=1
        else:
            dictpq[(p,q)] =1
print(n-max(dictpq.values()))
A,B=map(int(input()))
if A==2 or B==2:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

A,B=map(int, input().split())
if A==2 or B==2:
  print('No')
else:
  print('Yes')
A, B, C, D, E, F = map(int, input().split())
ans = [100 * A, 0]
c = 0

for i in range(1, F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        a = 100 * A * i + 100 * b * j
        if a < F:
            break
        for k in range((F - a) // C + 1):
            for l in range((F - a - C * k) // D + 1):
                b = C * k + D * l
                conc = 100 * b / (a + b)
                if b <= (A * i + B * j) * E and a + b < F:
                    if conc > c:
                        c = conc
                        ans = [a + b, b]
                else:
                    break
print(' '.join(map(str, ans)))

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
ans = [100 * A, 0]
c = 0

for i in range(1, F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        a = 100 * A * i + 100 * B * j
        if a > F:
            break
        for k in range((F - a) // C + 1):
            for l in range((F - a - C * k) // D + 1):
                b = k * C + l * D
                concentration = 100 * b / (a + b)
                if (A * i + B * j) * E >= b and a + b <= F:
                    if concentration > c:
                        c = concentration
                        ans = [a + b, b]
                else:
                    break

print(' '.join(map(str, ans)))
N = input()
print((N-2)*180)

### FIXED CODE ###

N = (int)(input())
print((N-2)*180)
# -*- coding:utf-8 -*-
# /usr/bin/python3

from bisect import insort
from collections import deque

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = sorted([tuple(map(int, input().strip().split(' '))) for _ in range(n)], key=lambda x:x[0])

  k = 1
  top = deque()
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      for i in range(len(top)):
        if i < a-k:
          s += top[-1]
          del top[-1]
      k = a

    insort(top, b)


  s += top[-1]
  for i in range(m - k):
    s += top[-(i+1)]

  print(s)
  
  pass

if __name__=='__main__':
  main()


### FIXED CODE ###

# -*- coding:utf-8 -*-
# /usr/bin/python3

from heapq import heappush, heappop

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = [tuple(map(int, input().strip().split(' '))) for _ in range(n)]
  liAB.sort(key=lambda x:x[0])

  k = 1
  top = []
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      s += (-sum([heappop(top) for _ in range(a-k) if len(top) != 0]))
      k = a
    heappush(top, -b)

  s += (-sum([heappop(top) for _ in range(m-k+1) if len(top) != 0]))
  print(s)

if __name__=='__main__':
  main()
s=input()
if s=="SSS":
  print(0)
else if s=="RRS" or s== "SRR":
  print(2)
else if s== "RRR":
  print(3)
else:
  print(1)

### FIXED CODE ###

s=input()
if s=="SSS":
  print(0)
elif s=="RRS" or s== "SRR":
  print(2)
elif s== "RRR":
  print(3)
else:
  print(1)
n,m,k,*ab = map(int, open(0).read().split())
aa = ab[:n]
bb = ab[m-1:]
ans = 0
i = j = 0
while True:
    if n <= i and m <= j:
        break
    elif n > i and m > j:
        a = aa[i]
        b = bb[j]
        if a < b:
            if a > k:
                break
            i += 1
            ans += 1
            k -= a
        else:
            if b > k:
                break
            j += 1
            ans += 1
            k -= b
    elif n > i:
        a = aa[i]
        if a > k:
            break
        i += 1
        ans += 1
        k -= a
    else:
        b = bb[j]
        if b > k:
            break
        j += 1
        ans += 1
        k -= b
print(ans)


### FIXED CODE ###

N,M,K,*AB = map(int, open(0).read().split())
A = AB[:N]
B = AB[N:]
a = [0]
b = [0]
for i in range(N): a.append(a[i] + A[i])
for i in range(M): b.append(b[i] + B[i])
ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
x,y,z = map(int,input().split())
l = []

l[0] = z
l[1] = x
l[2] = y

print(l)


### FIXED CODE ###

x,y,z = map(int,input().split())
l = []

l.append(z)
l.append(x)
l.append(y)

print(*l)
n=int(input())
l=map(int,input().split())
m=map(int,input().split())
def f(x):
	return l[x]-m[x]
print(sum([f(i) for i in range(n) if f(i)>0]))

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
m=list(map(int,input().split()))
def f(x):
	return l[x]-m[x]
print(sum([f(i) for i in range(n) if f(i)>0]))
n = int(input())
tree = [list() for _ in  range(n+1)]
for i in range(2,n+1):
  a = int(input())
  tree[a].append(i)
win = [0]*(n+1)
  
def dfs(v,win):
  if tree[v] == []:
    win[v] = 0 
    return win[v]
  l = list()
  for x in tree[v]:
    dfs(x,win)
    l.append(win[x])
  l.sort(reverse=True)
  win[v] = max(i+1+l[i] for i in range(len(l)))
  return win[v]

print(dfs(1,win))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
tree = [list() for _ in  range(n+1)]
for i in range(2,n+1):
  a = int(input())
  tree[a].append(i)
win = [0]*(n+1)
  
def dfs(v,win):
  if tree[v] == []:
    win[v] = 0 
    return win[v]
  l = list()
  for x in tree[v]:
    dfs(x,win)
    l.append(win[x])
  l.sort(reverse=True)
  win[v] = max(i+1+l[i] for i in range(len(l)))
  return win[v]

print(dfs(1,win))
import math
 
a, b = input().split()
a = int(a)
b_int = int(b)
b_fric = b -b_int
r1 = a*b_int
r2 = a*b_fric//100
result = r1+r2
print(result)


### FIXED CODE ###

def main():
    A, B = input().split()
    A = int(A)
    B_big, B_small = B.split(".")
    B_big = int(B_big)
    B_small = int(B_small)
    print(A*B_big + A*B_small//100)
 
 
if __name__ == "__main__":
    main()
import numpy as np

N = int(input())
a = [list(map(int,input().split())) for i in range(N)]

for j in range(101):
    for k in range(101):
        can = True
        needH = a[0][2] + np.abs(a[0][0] - j) + np.abs(a[0][1] - k)
        for i in range(N):
            if a[i][2] > 0:
                if  a[i][2] != needH - np.abs(a[i][0] - j) - np.abs(a[i][1] - k):
                    can = False
                    break
        if can == False:
            continue
        for i in range(N):
            if a[i][2] == 0:
                if  first > np.abs(a[i][0] - j) - np.abs(a[i][1] - k):
                    can = False
                    break
        if can:
            print("{} {} {}\n".format(j, k, first))
         



### FIXED CODE ###

import numpy as np

N = int(input())
a = [list(map(int,input().split())) for i in range(N)]

for j in range(101):
    for k in range(101):
        needH = -1
        for i in range(N):
            if a[i][2] > 0:
                temp = a[i][2] + np.abs(a[i][0] - j) + np.abs(a[i][1] - k)
                if needH == -1:
                    needH = temp
                else:
                    if needH != temp:
                        needH = -2
                        break
        if needH == -2:
            continue
            
        for i in range(N):
            if a[i][2] == 0:
                dist = np.abs(a[i][0] - j) + np.abs(a[i][1] - k)
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue
            
        print("{} {} {}\n".format(j, k, needH))
def f(v, i):
    s,n,m = 4 * 2 ** v - 3, 2 * 2 ** v - 1, s / 2 + 1
    return 0 if i < 1 or i > s else [0, f(v - 1, i - 1), n / 2 + 1, f(v - 1, i - s / 2 - 1) + n / 2 + 1, n, 1][(i > 1) + (i >= m) + (i > m) + (i >= s) + (v == 0) * 3]

print f(*map(int, raw_input().split()))

### FIXED CODE ###

#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = map(int, raw_input().split())

sz = [1] * (N + 1)
num = [1] * (N + 1)

for i in range(N):
    sz[i + 1] = sz[i] * 2 + 3
    num[i + 1] = num[i] * 2 + 1

def func(lv, id):
    mid = (sz[lv] + 1) / 2
    if lv == 0:
        return 1
    if id == 1:
        return 0
    if id == mid:
        return (num[lv] - 1) / 2 + 1
    if id == sz[lv]:
        return num[lv]
    if 1 < id < mid:
        return func(lv - 1, id - 1)
    if mid < id < sz[lv]:
        return func(lv - 1, id - sz[lv - 1] - 2) + num[lv - 1] + 1

print func(N, X)
class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in xrange(size)]
 
    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)
        self.table[s1] = s2

n = input()
uf=UnionFind3(10001)
 

cities = [map(int,raw_input().split(" "))+[i] for i in range(n)]
 
cities_x = sorted(cities, key=lambda a:a[0])
cities_y = sorted(cities, key=lambda a:a[1])
 
road = [[cities_x[i+1][0]-cities_x[i][0],cities_x[i][2],cities_x[i+1][2]] for i in range(n-1)]
road +=[[cities_y[i+1][1]-cities_y[i][1],cities_y[i][2],cities_y[i+1][2]] for i in range(n-1)]
 
sum = 0
for (cost,i,j) in sorted(road):
    if(uf.find(i)!=uf.find(j)):
        uf.union(i,j)
        sum += cost
 
print sum

### FIXED CODE ###

class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in xrange(size)]
 
    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[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
uf=UnionFind3(100001)
 
n = input()
cities = [map(int,raw_input().split(" "))+[i] for i in range(n)]
 
cities_x = sorted(cities, key=lambda a:a[0])
cities_y = sorted(cities, key=lambda a:a[1])
 
road = [[cities_x[i+1][0]-cities_x[i][0],cities_x[i][2],cities_x[i+1][2]] for i in range(n-1)]
road +=[[cities_y[i+1][1]-cities_y[i][1],cities_y[i][2],cities_y[i+1][2]] for i in range(n-1)]
 
sum = 0
for (cost,i,j) in sorted(road):
    if(uf.find(i)!=uf.find(j)):
        uf.union(i,j)
        sum += cost
 
print sum