Harryxun/stf_run huggingface dataset:
n,*abc=map(int,input().split())
ip=[0]*n
for i in range(n):
	tmp=input()
	if tmp=="AB":
		ip[i]=[0,1]
	elif tmp=="BC":
		ip[i]=[1,2]
	else:
		ip[i]=[0,2]
ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
	ans="No"
elif s==1:
	for i in range(n):
		i1=ip[i][0]
		i2=ip[i][1]
		ABC=(i1,i2)
		if ABC==(0,0):
			ans="No"
		'''
		if abc[i1]+abc[i2]==0:
			ans="No"
		'''
		elif abc[i1]+abc[i2]==1:
			if abc[i1]==0:
				abc[i1]+=1
				abc[i2]-=1
				res[i]=i1
			else:
				abc[i1]-=1
				abc[i2]+=1
				res[i]=i2
else:
	i1=ip[0][0]
	i2=ip[0][1]
	if abc[i1]+abc[i2]==0:
		ans="No"
	else:
		for i in range(n):
			i1=ip[i][0]
			i2=ip[i][1]
			if abc[i1]*abc[i2]==0:
				if abc[i1]==0:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
			elif i+1<n and ip[i+1]!=ip[i]:
				c=list(set(ip[i])&set(ip[i+1]))[0]
				if i1==c:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
			else:
				abc[i1]+=1
				abc[i2]-=1
				res[i]=i1
print(ans)
dic={0:"A",1:"B",2:"C"}
if ans=="Yes":
	for i in range(n):
		print(dic[res[i]])
		'''
		if res[i]==0:
			print("A")
		elif res[i]==1:
			print("B")
		else:
			print("C")
		'''

### FIXED CODE ###

n,*abc=map(int,input().split())
ip=[0]*n
for i in range(n):
	tmp=input()
	if tmp=="AB":
		ip[i]=[0,1]
	elif tmp=="BC":
		ip[i]=[1,2]
	else:
		ip[i]=[0,2]
ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
	ans="No"
elif s==1:
	for i in range(n):
		i1=ip[i][0]
		i2=ip[i][1]
		if abc[i1]+abc[i2]==0:
			ans="No"
		elif abc[i1]+abc[i2]==1:
			if abc[i1]==0:
				abc[i1]+=1
				abc[i2]-=1
				res[i]=i1
			else:
				abc[i1]-=1
				abc[i2]+=1
				res[i]=i2
else:
	i1=ip[0][0]
	i2=ip[0][1]
	if abc[i1]+abc[i2]==0:
		ans="No"
	else:
		for i in range(n):
			i1=ip[i][0]
			i2=ip[i][1]
			if abc[i1]*abc[i2]==0:
				if abc[i1]==0:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
			elif i+1<n and ip[i+1]!=ip[i]:
				c=list(set(ip[i])&set(ip[i+1]))[0]
				if i1==c:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
			else:
				if abc[i1]>=abc[i2]:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
print(ans)
if ans=="Yes":
	for i in range(n):
		if res[i]==0:
			print("A")
		elif res[i]==1:
			print("B")
		else:
			print("C")
import math
x1, y1, x2, y2 = map(int, raw_input().split())
x, y = x2 - x1, y2 - y1
print math.sqrt(x**2 + y**2)

### FIXED CODE ###

import math
x1, y1, x2, y2 = map(float, raw_input().split())
x, y = x2 - x1, y2 - y1
print math.sqrt(x**2 + y**2)
W , H , x , y = map(int,input().split())
if x == 0 or x == W:
	x_on_line = True
else:
	x_on_line = False
if y == 0 or y == H:
	y_on_line = True
else:
	y_on_line = False


if x_on_line or y_on_line:
	pattern = 0
	S = W * H / 2
else:
	if (W / 2) == float(x):
		x_half_point = True
	else:
		x_half_point = False
	if (H / 2) == float(y):
		y_half_point = True
	else:
		y_half_point = False
	if x_half_point and y_half_point:
		pattern = 1
		S = W * H / 2
	elif x_half_point or y_half_point:
		pattern = 0
		S = W * H / 2	
	else:
		min_x = (x,W - x)
		min_y = (y,H - y)
		S = max((min_x * H,min_y * W))
		pattern = 0
print(S,pattern)
	
	

### FIXED CODE ###

W , H , x , y = map(int,input().split())
if x == 0 or x == W:
	x_on_line = True
else:
	x_on_line = False
if y == 0 or y == H:
	y_on_line = True
else:
	y_on_line = False


if x_on_line or y_on_line:
	pattern = 0
	S = W * H / 2
else:
	if (W / 2) == float(x):
		x_half_point = True
	else:
		x_half_point = False
	if (H / 2) == float(y):
		y_half_point = True
	else:
		y_half_point = False
	if x_half_point and y_half_point:
		pattern = 1
		S = W * H / 2
	elif x_half_point or y_half_point:
		pattern = 0
		S = W * H / 2	
	else:
		S = W * H / 2
		pattern = 0
print(S,pattern)
input = str(raw_input())

print("2018"+input[4:])

### FIXED CODE ###

print("2018"+input()[4:])
n,m = map(int,input().split())
dp = [10**9]*(2**n)
for i in range(m):
  a,_ = map(int,input().split())
  c = list(map(int,input().split()))
  t = 0
  for x in c:
    t |= 1<<(x-1)
  for b in range(2**n):
    dp[b|t] = min(dp[b],dp[b+a])
if dp[-1] > 10**8:
  print(-1)
else:
  print(dp[-1])

### FIXED CODE ###

n,m = map(int,input().split())
dp = [10**9]*(2**n)
dp[0] = 0
for _ in range(m):
  a,_ = map(int,input().split())
  c = list(map(int,input().split()))
  t = 0
  for x in c:
    t |= 1<<(x-1)
  for b in range(2**n):
    dp[b|t] = min(dp[b|t],dp[b]+a)
if dp[-1] > 10**8:
  print(-1)
else:
  print(dp[-1])
def mx(ls,i):
    rls = ls[:]
    if i == 0: return 0
    else     : return (i+1)*rls.pop()+ mx(rls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m+1) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

### FIXED CODE ###

def mxmn(ls,m):
	global n
	s1,s2 = 0, 0
	for i in range(m):
		s1 += (n-i)*ls[-i-1]
		s2 += (n-i)*ls[i]
	return s1,s2

def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		mx,mn = mxmn(ls,m)
		if mx < s or mn > s: return 0
		elif mx == s or mn == s: return 1
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break
def abc():
    a, b, c = map(int, input().rstrip().split())
    n = list(range(a, b + 1))
    s = sorted(set(n[:c]) | set(n[-c:]))
    for _s in s:
        print(_s)


abc()


### FIXED CODE ###

def abc():
    a, b, c = map(int, input().split())
    n = range(a, b + 1)
    for s in sorted(set(n[:c]) | set(n[-c:])):
        print(s)


abc()
x,y= map(int,input().split())
crane= 2
turtle= 4
ans="No"
for i in range(x+1):
    b=x-i
    if cranei + turtleb == y:
        ans = "Yes"
print(ans)

### FIXED CODE ###

x,y= map(int,input().split())
crane= 2
turtle= 4
ans="No"
for i in range(x+1):
    b=x-i
    if crane*i + turtle*b == y:
        ans = "Yes"
print(ans)

# the for loop is to check for any combinations of numbers of cranes and turtles in which the statement is correct.
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=[2,3]
  cnt=2
  last=0
  for i in range(4,30001):
    if i%6 in [0,2,3,4]:
      l.append(i)
      cnt+=1
      if cnt==n:
        last=i
        break
  m=sum(l)
  if m%6==1:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==2:
        l.append(last+i)
        break
  elif m%6==2:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==3:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==4:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  elif m%6==5:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  print(*l)
  if len(s)!=n:
    while True:
      z=0

### FIXED CODE ###

n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=set()
  cnt=0
  e=0
  for i in range(2,30001):
    if i%2==0 or i%3==0:
      l.add(i)
      cnt+=1
      if cnt==n:
        m=sum(l)
        if m%6==2:
          l.discard(8)
          l.add((i//6+1)*6)
        elif m%6==3:
          l.discard(9)
          l.add((i//6+1)*6)
        elif m%6==5:
          l.discard(8)
          l.add((i+3)//6*6+3)
        break
  print(' '.join(map(str,l)))
ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans
    if level == 0:
        ans += 1
    else:
        if index == len_dic[level] // 2:
            ans += 1
            ans += p_dic[level - 1]
        elif index == len_dic[level] - 1:
            ans += p_dic[level]
        elif index == 0:
            pass
        elif index > len_dic[level] // 2:
            ans += p_dic[level - 1] + 1
            index_next = index - len_dic[level - 1] - 2
            count_ans(level - 1, index_next, len_dic, p_dic)
        else:
            index_next = index - 1
            count_ans(level - 1, index_next, len_dic, p_dic)


def get_len_dic(level):
    len_dic = [1]
    for i in range(level):
        len_dic.append(len_dic[-1] * 2 + 3)
    return len_dic

def get_p_dic(level):
    p_dic = [1]
    for i in range(level - 1):
        p_dic.append(p_dic[-1] * 2 + 1)
    return p_dic

def main():
    global ans
    level, eat_num = map(int, input().split())
    len_dic = get_len_dic(level)
    p_dic = get_p_dic(level)
    count_ans(level, eat_num - 1, len_dic, p_dic)
    print(ans)





if __name__ == '__main__':
    main()

### FIXED CODE ###


ans = 0
def count_ans(level, index, len_dic, p_dic):
    global ans
    if level == 0:
        ans += 1
    else:
        if index == 0:
            pass
        elif index == len_dic[level] // 2:
            ans += 1
            ans += p_dic[level - 1]
        elif index == len_dic[level] - 1:
            ans += p_dic[level]
        elif index > len_dic[level] // 2:
            ans += p_dic[level - 1] + 1
            index_next = index - len_dic[level - 1] - 2
            count_ans(level - 1, index_next, len_dic, p_dic)
        else:
            index_next = index - 1
            count_ans(level - 1, index_next, len_dic, p_dic)


def get_len_dic(level):
    len_dic = [1]
    for i in range(level):
        len_dic.append(len_dic[-1] * 2 + 3)
    return len_dic

def get_p_dic(level):
    p_dic = [1]
    for i in range(level):
        p_dic.append(p_dic[-1] * 2 + 1)
    return p_dic

def main():
    global ans
    level, eat_num = map(int, input().split())
    len_dic = get_len_dic(level)
    p_dic = get_p_dic(level)
    count_ans(level, eat_num - 1, len_dic, p_dic)
    print(ans)


if __name__ == '__main__':
    main()
N, M = map(int, input().split())
S = [0]*M
C = [0]*M
SC = {}
SC = {1: set([]), 2: set([]), 3: set([])}
for m in range(M):
    S[m], C[m] = map(int, input().split())
    SC[S[m]].add(C[m])

ANS = [0]*N
out = 0
for i in range(1, 4):
    if len(SC[i]) >= 2:
        out = 1
if out == 1:
    print(-1)

else:
    out = 0
    if N == 1:
        if len(SC[1]) == 0:
            ANS[0] = 0
        else:
            ANS[0] = list(SC[1])[0]

    else:
        for i in range(N):
            if i == 0:
                if list(SC[i+1])[0] == 0:
                    out = 1
                elif len(SC[i+1]) == 0:
                    ANS[0] = 1
                else:
                    ANS[0] = list(SC[i+1])[0]
            else:
                if len(SC[i+1]) == 0:
                    ANS[i] = 0
                else:
                    ANS[i] = list(SC[i+1])[0]
    if out == 1:
        print(-1)
    else:
        ans = 0
        for i in range(N):
            ans += ANS[i]*10**(N-i-1)
        print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
S = [0]*M
C = [0]*M
SC = {}
SC = {1: set([]), 2: set([]), 3: set([])}
for m in range(M):
    S[m], C[m] = map(int, input().split())
    SC[S[m]].add(C[m])

ANS = [0]*N
out = 0
for i in range(1, 4):
    if len(SC[i]) >= 2:
        out = 1
if out == 1:
    print(-1)

else:
    out = 0
    if N == 1:
        if len(SC[1]) == 0:
            ANS[0] = 0
        else:
            ANS[0] = list(SC[1])[0]

    else:
        for i in range(N):
            if i == 0:
                if len(SC[i+1]) == 0:
                    ANS[0] = 1
                elif list(SC[i+1])[0] == 0:
                    out = 1
                else:
                    ANS[0] = list(SC[i+1])[0]
            else:
                if len(SC[i+1]) == 0:
                    ANS[i] = 0
                else:
                    ANS[i] = list(SC[i+1])[0]
    if out == 1:
        print(-1)
    else:
        ans = 0
        for i in range(N):
            ans += ANS[i]*10**(N-i-1)
        print(ans)
N=input()
s=input()

N=int(N)
wn=[]
bn=[]
a=0
b=0

#各行間よりも前と後ろに何個白（黒）があるかをカウント
for i in range(N):
    j=N-(i+1)
    if(s[j]=="."):
        a+=1
    if(s[i]=="#"):
        b+=1
    bn.insert(0,a)
    wn.append(b)
bn.append(0)
wn.insert(0,0)
#print(bn)
#print(wn)

#各行間のscore算出
min=1000000
for i in range(N+1):
    score=bn[i]+wn[i]
    if(score<min):
        min=score

print(min)

### FIXED CODE ###

a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)

if(a<c and b>c or c<a and b<c):
    print("Yes")
else:
    print("No")
while 1:
    t = int(input())
    if t == 0:break
    n = int(input())
    x = 0
    for i in range(n):
        x += (lambda lst:lst[-1] - lst[0])(list(map(int,input().split())))
    print('OK' if t<=x else (t-x))
while 1:
    t = int(input())
    if t == 0:break
    #n = int(input())
    #x = 0
    #for i in range(n):
    t -= sum(map(lambda lst:lst[-1] - lst[0],[ list(map(int,input().split())) for i in range(int(input())) ]))
    print('OK' if t<=0 else t)

### FIXED CODE ###

while 1:
    t = int(input())
    if t == 0:break
    t -= sum(map(lambda lst:lst[-1] - lst[0],[ list(map(int,input().split())) for i in range(int(input())) ]))
    print('OK' if t<=0 else t)
total=0
s=0
i=0
try:
 while True:
  a,b = map(int,input().split(','))
  total += a*b
  s+=b
  i+=1
except:
 result=s/i+0.5 
 print(total)
 print(round(result))

### FIXED CODE ###

while True:
 try:
   a,b,c=map(float,input().split(','))
   bmi=b/c**2
   if bmi>=25:
     print(int(a))
 except:
  break
list=input()
list_n=[int(s) for s in list]
print(int(max(list_n))-int(min(list_n)))

### FIXED CODE ###

list=input().split(" ")
list_n=[int(s) for s in list]
print(int(max(list_n))-int(min(list_n)))
object Main {
  def main(args: Array[String]): Unit = {
    println("Hello World")
  }
}

### FIXED CODE ###

a = [x for x in range(9)]

for i in a:
    for j in a:
        print("{}x{}={}".format(i + 1, j + 1, (i + 1) * (j + 1)))
n, x = map(int, input().split())
m = [int(input()) for _ in range(n)]

a = 0
for i in n:
  a += (i+1) * m[(i)]

print(n + (x - a) // min(m))


### FIXED CODE ###

n, x = map(int, input().split())
m = [int(input()) for _ in range(n)]

x -= sum(m)

print(n + x // min(m))
x,a,b=list(map(int,input().split()))
if(math.fabs(x-a)>math.fabs(x-b)):
    print("B")
else:
    print("A")

### FIXED CODE ###

import math

x,a,b=list(map(int,input().split()))
if(math.fabs(x-a)>math.fabs(x-b)):
    print("B")
else:
    print("A")
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    if D <=X:
        D+=int(input())
        ans+=1
    else:
        int(input())
        continue
if D >X:
    ans-=1
print(ans)
    


### FIXED CODE ###

N,X = map(int,input().split())
D = 0
ans = 1
L = list(x for x in input().split())
for i in range(N):
    
    if D <=X:
        D+=int(L[i])
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
    exit()

if M == 0:
    print(0)
    exit()

if M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

k = str(K)
seq = list(map(str, range(2 ** M)))
seq.remove(K)
answer = seq + [k] + seq[::-1] + [k]

print(' '.join(answer))


### FIXED CODE ###

M, K = map(int, input().split())
m = 1 << M

if K >= m:
    print(-1)
    exit()

if M == 0:
    print(0, 0)
    exit()

if M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

k = str(K)
seq = list(map(str, range(m)))
seq.remove(k)
answer = seq + [k] + seq[::-1] + [k]

print(' '.join(answer))
S = list(input())
n = len(S)

for i in reversed(range(0,n)):
  for j in range(0,n-i+1):
    s = S[j:j+i].strip("A").strip("C").strip("G").strip("T")
    if s == "":
      break

print(i)
    

### FIXED CODE ###

S = input()
n = len(S)

flag = 0
for i in reversed(range(0,n+1)):
  for j in range(0,n-i+1):
    s = S[j:j+i].replace("A", "").replace("C", "").replace("G","").replace("T","")
    #print("+", s, "+", len(s))
    if len(s) == 0:
      flag=1
      break
  if flag==1:
    break

print(i)
x=int(input())
i=0
kekka1=[[0] for _ in range(10)]
while x>0:
    kekka1[i]=x%2
    x=x//2
    i+=1

for k in range(10):
    j=9-k
    if kekka1[j]==1:
        print(str(j)+"番の分銅を右の皿に載せる。")

### FIXED CODE ###

a=input()
s=list("abcdefghijklmnopqrstuvwxyz")
if a in s:
    print("a")
else:
    print("A")
X,Y = map(int,input().split())
if x%y > 0 or y%x > 0:
	print(-1)
	exit()
if 2*x % y == 0:
	print(2*x)
	exit()
else:
	print(-1)


### FIXED CODE ###

x,y = map(int,input().split())
if x % y == 0:
	print(-1)
	exit()
ans = 0
for i in range(y):
	ans += x
	if ans % y > 0:
		break
if ans == x*y:
	print(-1)
	exit()
print(ans)
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

### FIXED CODE ###

import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)
a, b = map(int, input().split())

print(int(a*b))

### FIXED CODE ###

from decimal import Decimal

a, b = input().split()
a = Decimal(a)
b = Decimal(b)
print(int(a*b))
# coding: utf-8
# Here your code !
x = input().split()
a = x[0]
b = x[1]
m = a*b
s = a*2+b*2
print m, s

### FIXED CODE ###

# coding: utf-8
# Here your code !
a,b = input().split()
m = int(a) * 2 + int(b) * 2
s = int(a) * int(b)
print(s,m)
n=int(input())
s=input()
ans=0
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))

### FIXED CODE ###

n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='#':
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)
a, b = map(int, input())
c = a - 2 * b
if c > 0:
  print(c)
else:
  print(0)

### FIXED CODE ###

a, b = map(int, input().split())
c = a - 2 * b
if c > 0:
  print(c)
else:
  print(0)
import sys

sys.setrecursionlimit(10000)

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
x = [(i, xy[i][0]) for i in range(n)]
y = [(i, xy[i][1]) for i in range(n)]

x.sort(key = lambda x:x[1])
y.sort(key = lambda x:x[1])

x_dif = [((x[i][0], x[i+1][0]), abs(x[i+1][1]-x[i][1])) for i in range(n-1)]
y_dif = [((y[i][0], y[i+1][0]), abs(y[i+1][1]-y[i][1])) for i in range(n-1)]

xy_dif = x_dif + y_dif
xy_dif.sort(key = lambda x:x[1])

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

def root(x):
  if p[x]==x:
    return x
  p[x] = root(p[x])
  return p[x]

ans = 0
for i in range(2*(n-1)):
  ab, cost = xy_dif[i]
  a, b = ab
  #print(a, b, p[a], p[b], p)
  if root(a)!=root(b):
    p[root(a)] = root(b)
    ans += cost

print(ans)


### FIXED CODE ###

import sys

sys.setrecursionlimit(2147483647)

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
x = [(i, xy[i][0]) for i in range(n)]
y = [(i, xy[i][1]) for i in range(n)]

x.sort(key = lambda x:x[1])
y.sort(key = lambda x:x[1])

x_dif = [((x[i][0], x[i+1][0]), abs(x[i+1][1]-x[i][1])) for i in range(n-1)]
y_dif = [((y[i][0], y[i+1][0]), abs(y[i+1][1]-y[i][1])) for i in range(n-1)]

xy_dif = x_dif + y_dif
xy_dif.sort(key = lambda x:x[1])

p = [-1]*n

def root(x):
  if p[x]<0:
    return x
  p[x] = root(p[x])
  return p[x]

ans = 0
for ab, cost in xy_dif:
  a, b = ab
  #print(a, b, p[a], p[b], p)
  if root(a)!=root(b):
    p[root(a)] = root(b)
    ans += cost

print(ans)
# AOJ ITP1_9_A

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

# ※大文字と小文字を区別しないので注意！！！！
# 全部大文字にしちゃえ。
def main():
    W = input().upper()  # 大文字にする
    line = ""
    count = 0
    while True:
        line = input().split()
        if line == "END_OF_TEXT": break
        for i in range(len(line)):
            word = line[i].upper()
            if W == word: count += 1
    print(count)

if __name__ == "__main__":
    main()


### FIXED CODE ###

# AOJ ITP1_9_A

# ※大文字と小文字を区別しないので注意！！！！
# 全部大文字にしちゃえ。
def main():
    W = input().upper()  # 大文字にする
    line = ""
    count = 0
    while True:
        line = input().split(" ")
        if line[0] == "END_OF_TEXT": break
        for i in range(len(line)):
            word = line[i].upper()
            if W == word: count += 1
    print(count)

if __name__ == "__main__":
    main()

# Accepted.
import math


R = input()
s = 2.0*math.pi*R

print(s)

### FIXED CODE ###

import math

r = int(input())
s = 2.0 * r * math.pi

print(s)
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = np.zeros((H, W))
ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))


### FIXED CODE ###

import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[(tmp_h-1, tmp_w-1)] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(int(h_max + w_max))
else:
    print(int(h_max + w_max - 1))
from itertools import permutations

n = int(input())
pq=[list(map(int,list(input()))) for i in range(h)] 

cnt=0
for v in permutations(range(1,N+1), N):
    cnt +=1
    if(pq[0]==v):
        a = cnt
    if(pq[1]==v):
        b = cnt

print(abs(a-b))

### FIXED CODE ###

import itertools
n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

num = []
for i in range(1,n+1):
    num.append(i)
ans = []
for i in itertools.permutations(num,n):
    ans.append(i)

print(abs(ans.index(p)-ans.index(q)))
N,Q = map(int,input().split())
S = list(input())

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    a[i] = 1
    b[i+1] = 1
    
def cumsum(xs):
  result = [xs[0]]
  for x in xs[1:]:
    result.append(result[-1] + x)
  return result

A = cumsum(a)
B = cumsum(b)

for i in range(Q):
  l,r = map(int,input().split())
  print(B[r] - A[l])

### FIXED CODE ###

N,Q = map(int,input().split())
S = list(input())

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    a[i] = 1
    b[i+1] = 1
    
def cumsum(xs):
  result = [xs[0]]
  for x in xs[1:]:
    result.append(result[-1] + x)
  result.append(0)
  result.sort()
  return result

A = cumsum(a)
B = cumsum(b)

for i in range(Q):
  l,r = map(int,input().split())
  print(int(B[r] - A[l-1]))
import math
x = int(input())

L = []
for i in (2,int(math.floor(math.sqrt(x)))+1):
  for j in (range(x//i)):
    if i ** j <= x:
      L.append(i**j)
      
print(max(L))

### FIXED CODE ###

import math
x = int(input())

L = []
for i in range(2,int(math.floor(math.sqrt(x)))+1):
  for j in range(x//i + 1):
    if i ** j <= x:
      L.append(i ** j)
      
if L == []:
  print("1")
else:
  print(max(L))
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
L=[0]*N
R=[0]*N
L[0]=A[0]
R[0]=A[N-1]
ans=0

for n in range(1,N):
  L[n]=gcd(A[n],L[n-1])
  R[n]=gcd(A[N-n-1],R[n-1])
  
  ans=max(L[N-2],R[N-2])

for i in range(1,N-1):
  ans=max(ans,gcd(L[i-1],R[N-i-2]))

print(ans)

### FIXED CODE ###

A,B,T=map(int, input().split())

print(int((T+0.5)//A*B))
print(int(input()**2))


### FIXED CODE ###

print(int(input())**2)