Harryxun/stf_run huggingface dataset:
import sys
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
  a, b, c = map(int, input().split())
  graph[a].append((b, c))
  graph[b].append((a, c))
q, k = map(int, input().split())
xy = []
for _ in range(q):
  x, y = map(int, input().split())
  xy.append((x, y))

l = [0]*(n+1)
def DFS(node, p_node, length):
  try:
    l[node] = length
  except:
    sys.exit(0)
  for i, j in graph[node]:
    if i==p_node:
      continue
    DFS(i, node, length+j)

DFS(k, -1, 0)
for x, y in xy:
  print(l[x]+l[y])

### FIXED CODE ###

import sys
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    a-=1
    b-=1
    graph[a].append((b, c))
    graph[b].append((a, c))
q, k = map(int, input().split())
k -= 1
xy = []
for _ in range(q):
    x, y = map(int, input().split())
    x-=1
    y-=1
    xy.append((x, y))

def DFS(node, p_node, length):
    l[node] = length
    for i, j in graph[node]:
        if i==p_node:
            continue
        DFS(i, node, length+j)
sys.setrecursionlimit(2 * n)
l = [0]*n
DFS(k, -1, 0)
for x, y in xy:
    print(l[x]+l[y])
m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
elif m == 0:
  print(0, 0)
elif m == 0:
  if k == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
else:
  for i in range(2**n):
    if i == k:
      continue
    print(i, end=" ")
  print(k, end=" ")
  for i in range(2**n-1, -1, -1):
    if i == k:
      continue
    print(i, end=" ")
  print(k)

### FIXED CODE ###

m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
elif m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
else:
  for i in range(2**m):
    if i == k:
      continue
    print(i, end=" ")
  print(k, end=" ")
  for i in range(2**m-1, -1, -1):
    if i == k:
      continue
    print(i, end=" ")
  print(k)
A, B, K = input().split()
A = int(A)
B = int(B)
K = int(K)
if (A + B) - K <= 0:
    Ta = 0
    Ao = 0
else:
    if A > B:
        Ta = (A + B) - K
        Ao = 0
    else:
        Ao = (A + B) - K
        Ta = 0
print(f"{Ta} {Ao}")

### FIXED CODE ###

cookies = [int(x) for x in input().split()]
leftOver = cookies[0] - cookies[2]
takahashi = max(0, leftOver)
print(str(takahashi)+ ' ' + (str(cookies[1]) if takahashi > 0  else str(max(0,cookies[1] - abs(leftOver)))))
N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

if N%2 == 1:
    a_med = a_list[t]
    b_median = b_list[t]
    print(b_list-a_list+1)
elif N%2 == 0:
    a_median = (a_list[t-1]+a_list[t])/2
    b_median = (b_list[t-1]+b_list[t])/2
    print(int(2*(b_median-a_median)+1))

### FIXED CODE ###

N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
    ab = list(map(int, input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

a_list = sorted(a_list)
b_list = sorted(b_list)

if N%2 == 1:
    a_median = a_list[t]
    b_median = b_list[t]
    print(b_median-a_median+1)
elif N%2 == 0:
    a_median = (a_list[t-1]+a_list[t])/2
    b_median = (b_list[t-1]+b_list[t])/2
    print(int(2*(b_median-a_median)+1))
num = input().split()
a, b =int(num[0]), int(num[1])

ans = [a+b, a-b, a*b , a//b]

print(ans[-1])

### FIXED CODE ###

num = input().split()
a, b =int(num[0]), int(num[1])

ans = sorted([a+b, a-b, a*b])

print(ans[-1])
a = list(map(int, input().split())
print(a[1]//a[0]*(a[2]+0.5))

### FIXED CODE ###

a = list(map(int, input().split()))
print(a[2]//a[0] * a[1])
N , R = tuple(list(map(int, input().split(' '))))
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))


### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    print(int(N / 2))
else:
    print(int(N / 2)+ 1)
import numpy as np
from sys import stdin
sys.setrecursionlimit(10**6) 

def main(args):
    a = args[0]
    b = args[1]
    if 6 <= a and a <= 12:
        v = b//2
    elif a <= 5:
        v = 0
    else:
        v = b
    print(v)

main([int(x) for x in stdin.readline().rstrip().split())

### FIXED CODE ###

import numpy as np
from sys import stdin
#sys.setrecursionlimit(10**6) 

def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if 6 <= a and a <= 12:
        v = b//2
    elif a <= 5:
        v = 0
    else:
        v = b
    print(v)

if __name__ == "__main__":
    main()
k=int(input())

m=k//2

if k%2==0:
print(int((k/2)**2))
else:
  print(int(m*(m+1)))


### FIXED CODE ###

k=int(input())

m=k//2

if k%2==0:
  print(int(k*k/4))
else:
  print(int(m*(m+1)))
s=list(input())
c = collections.Counter(s)
if list(c.values())==[2,2]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###


s=list(input())
import collections
s = collections.Counter(s)
if list(s.values())==[2,2]:
    print("Yes")
else:
    print("No")
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []
N, K =LI()
A = LI()
F = LI()
A.sort(reverse=True)
F.sort()

disA = [0]*N
for i in range(N-1):
    disA[i] = A[i] - A[i+1]
disA[N-1] = A[-1]

sumA = sum(A)
#print(A)
k = int(-1)
cou = sumA
while k<N:
    if cou<=K:
        break
    k +=1
    cou = cou - disA[-k-1]*(N-k)

basic = A[-k-1]
#print(k)
for i in range(N-k-1):
    A[i] = basic
K = K - cou
#print(K)
for i in range(K):
    A[i]-=1
#print(A)
A.sort(reverse=True)

for i in range(N):
    ans.append(A[i]*F[i])
#print(A)
#print(F)
#print(ans)
if k ==-1:
    print("0")
else:
    print(max(ans))


### FIXED CODE ###

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)
N, K =LI()
A = LI()
F = LI()
A.sort(reverse=True)
F.sort()

xupper = max(A)*max(F)
xlower = int(0)
xcandi = xupper//2

sumA = sum(A)

while (True):
#    print(xlower,xupper, xcandi)
    k = int(0)
    for i in range(N):
        k += max((A[i]*F[i]-xcandi+(F[i]-1))//F[i],0)
#    print(k)

    if k>K:
        xlower = xcandi
        xcandi = ((xcandi + xupper) // 2)+1
    else:
        if xupper-xlower<=1:
            ans = xcandi
            break
        else:
            xupper = xcandi
            xcandi = (xcandi + xlower) // 2

print(ans)
import bisect
N = 10**6
dp = [1] * (N+1)
dp[0] =  dp[1] =  0
prime = []
for i in range(2,N+1):
    if dp[i]:
        for j in range(i*i, N+1, i):
            dp[j] = 0
like2017 = [0] * (N+1)
for n in range(N+1):
    if dp[n]==0:
        continue
    query = (p+1)//2
    if dp[query]==1:
        like2017[n] = 1


for n in range(N):
    line2017[n+1] += like2017[n]
    
Q = int(input())
for q in range(Q):
    l, r = map(int,input().split())
    print (like2017[r]-like2017[l])


### FIXED CODE ###

import bisect
N = 10**6
dp = [0] * (N+1)
dp[0], dp[1] = 1, 1
prime = []
for i in range(2,N+1):
    if dp[i]==0:
        prime.append(i)
        for j in range(N//i+1):
            dp[j*i] = 1

like2017 = []
for p in prime:
    query = (p+1)//2
    idx = bisect.bisect_left(prime, query)
    if prime[idx] == query:
        like2017.append(p)
    

Q = int(input())
for q in range(Q):
    l, r = map(int,input().split())
    l = bisect.bisect_left(like2017, l)
    r = bisect.bisect_right(like2017, r)
    print (r-l)
def root(V): # i(Root)
    for i in range(len(V)):
        if V[i][1]==[]:
            return i
    return -1

def add(V,r): # add recursively
    for l in V[r][2]:
        V[l][0]+=V[r][0]
        add(V,l)

N,Q=map(int,input().split())
V=[[0,[],[]] for i in range(N)] # value,prev[],next[]

for i in range(N-1):
    a,b=map(int,input().split())
    V[a-1][2].append(b-1) # append i(Next) to Prev.next
    V[b-1][1].append(a-1) # append i(Prev) to Next.prev

for i in range(Q):
    p,x=map(int,input().split())
    V[p-1][0]+=x

add(V,root(V))

for v in V:
    print(v[0],end=' ')

### FIXED CODE ###

from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])
n, m, k=map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1=[0]

#それぞれの累積和(ai, bj)をもとめる
for i in range(n):
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	acum2.append(acum2[-1]+arr2[i])

ans = 0
for i in range(n+1):
	if acum1[i] > k:
    	break
    while acum2[j]>k - acum1[i] and j>0:
    	j -= 1
        ans = max(ans, i+j)
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)
n=input()
vli = list(map(int,input().split()))
cli = list(map(int,input().split()))
for i in n:
  sli=[]
  sli.append(vli[i]-cli[i])
for j in n:
  ans=[]
  if sli[j]>0:
    ans.append(sli[j])
print(sum(ans))

### FIXED CODE ###

n = int(input())
vli = list(map(int,input().split()))
cli = list(map(int,input().split()))
ans = 0
for i in range(n):
  s=vli[i] - cli[i]
  if s>0:
    ans+=s
print(ans)
k = input()
A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
print(int(A[k-1]))

### FIXED CODE ###

lists = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(int(lists[k-1]))
N = int(input())
for s in range(N):
  print('AC','x',s.count('AC'))
  print('TLE','x',s.count('TLE'))
  print('WJ','X',s.count('WJ'))
  print('RE','X',s.count('RE'))


### FIXED CODE ###

n = int(input())
s = list(input() for i in range(n))
  
print("AC x ",s.count("AC"))
print("WA x ",s.count("WA"))
print("TLE x ",s.count("TLE"))
print("RE x ",s.count("RE"))
a = int(input())
x = [3,5,7]
if a in x:
  pritn("YES")
else:
  print("NO")

### FIXED CODE ###

n = int(input()) 
if (n%5 == 0 or n%3 == 0 or n%7 ==0) and n%9!=0 and n%6 !=0:
    print("YES")
else:
    print("NO")
A,B,N = map(int,input().split())

if N<= B-1:
    ans = (N*A)//B
else:
    ans = ((B-1)*A)//B
    
print(ans)

### FIXED CODE ###

import sys
K = int(input())
A,B = map(int,input().split())

for i in range(0,B-A+1):
    if (A+i)%K==0:
        print("OK")
        sys.exit()
else:
    print("NG")
from collections import deque

N, M = map(int,input().split())
ac = [0] * M
pena = [0] * M

for a in range(M):
    p,s = input().split()
    
    p = int(p) - 1

    if ac[p]:
        continue
    if s == 'AC':
        ac[p] = 1
    else:
        pena[p] += 1

AC = 0
PENA = 0

for a in range(M):
    AC += ac[a]
    if ac[a]:
        PENA += pena[a]

print(AC,PENA)

### FIXED CODE ###

from collections import deque

N, M = map(int,input().split())
ac = [0] * N
pena = [0] * N

for a in range(M):
    p,s = input().split()
    
    p = int(p) - 1

    if ac[p]:
        continue
    if s == 'AC':
        ac[p] = 1
    else:
        pena[p] += 1

AC = 0
PENA = 0

for a in range(N):
    AC += ac[a]
    if ac[a]:
        PENA += pena[a]

print(AC,PENA)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

ans = 0
for i in range(1, s // 3 + 1):
    rest = s - 3 * i
    ans += cmb(rest + i - 1, rest, MOD)

print(ans % MOD)

### FIXED CODE ###

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

s = int(input())

ans = 0
for i in range(1, s // 3 + 1):
    rest = s - 3 * i
    ans += cmb(rest + i - 1, rest, MOD)

print(ans % MOD)
num1 = int(input("Value1:"))
num2 = int(input("Value3:"))
num3 = int(input("Value3:"))
sum=num1+num2+num3
print("Sum:",sum)
if(sum < 22):
   print("Win")
else:
   print("Bust")

### FIXED CODE ###

A1,A2,A3 = map(int,input().split())
sum=A1+A2+A3
if(sum >= 22):
   print("bust")
else:
   print("win")
a=[(input()) for i in range(9)]
print(a[0]+a[4]+a[8])

### FIXED CODE ###

a=list(input())
b=list(input())
c=list(input())
print(a[0]+b[1]+c[2])
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    x,k,d = LI()
    s = abs(x) // x
    c = abs(x) // d

    ans = 0
    if c >= k:
        ans = x - d * k * s
    else:
        ans = x - d * c * s
        if (k-c) % 2 == 1:
            ans = ans - d * s
    print(abs(ans))
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    x,k,d = LI()
    if x == 0:
        if k % 2 == 1:
            print(d)
        else:
            print(0)
        return
    else:
        s = abs(x) // x
    c = abs(x) // d

    ans = 0
    if c >= k:
        ans = x - d * k * s
    else:
        ans = x - d * c * s
        if (k-c) % 2 == 1:
            ans = ans - d * s
    print(abs(ans))
if __name__ == '__main__':
    main()
n = int(input())
a = map(int, input().split())
a.sort()
ans = a[-1] - a[0]
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = a[-1] - a[0]
print(ans)
import numpy as np


def main():
    n, k = map(int, input().split())
    ps = (np.array(list(map(int, input().split()))) + 1) / 2

    if k == 1:
        ans = ps[0]
    else:
        cumulative_sum = [0] * n
        for i in range(n):
            if i == 0:
                cumulative_sum[i] = ps[0]
            else:
                cumulative_sum[i] = ps[i] + cumulative_sum[i-1]

        ans = max([cumulative_sum[i+k] - cumulative_sum[i] for i in range(n-k)])
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    ps = list(map(int, input().split()))
    e = [(1+p)/2 for p in ps]

    s = [0]
    for i in range(n):
        s.append(s[i]+e[i])

    ans = max([s[i+k] - s[i] for i in range(n-k+1)])
    print(ans)


if __name__ == "__main__":
    main()
import sys
readllne = sys.stdin.readllne
A,B,C = map(int,readllne().split())
print(C,A,B)


### FIXED CODE ###

import sys
#readline = sys.stdin.readline()
A,B,C = map(int,input().split())
print(C,A,B)
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

#gridのindexは入力値のまま扱う(grid=[1,1]~[H,W])
#left<x<rightの間が生存範囲(初めはグリッド全てが生存可能状態)
left=0
right=W+1
up=0
down=H+1

ans="YES"
#手を逆順で見ていく。
for s,t in zip(reversed(S),reversed(T)):
    if t=='R':#生存可能範囲を広げる(0より小さくならないようにする)
        left=max(0,left-1)
    elif t=="L":
        right=min(W+1,right+1)
    elif t=="D":
        up = max(0,up-1)
    else:
        down=min(H+1,down+1)


    if s=="R"
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    #もし、途中でright-left==1。つまり、生存可能範囲がなくなってしまったら、
    #落とされてしまうため、ans=NOにして終了する
    if right-left==1 or down-up==1:
        ans="NO"
        break

#全ての手を見た後で、スタート地点が生存可能範囲に入っていればOK
if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
stS = [v for v in input()[:-1]]
stT = [v for v in input()[:-1]]

ans = "YES"
# T=U,A=D
T = "U"
A = "D"
m = sr
# print("U")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m -= 1
        if m <= 0:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m < H:
            m += 1

T = "D"
A = "U"
m = sr
# print("D")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m += 1
        if m > H:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m > 1:
            m -= 1

T = "R"
A = "L"
m = sc
# print("R")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m += 1
        if m > W:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m > 1:
            m -= 1
T = "L"
A = "R"
m = sc
# print("L")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m -= 1
        if m <= 0:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m < H:
            m += 1
print(ans)
w=list(input())
ans=sorted(w)

while ans[-1]==ans[-2]:
  del ans[-2:]
  if len(ans)==0 or len(ans)==1:
    break

if ans==[]:
  print('Yes')
else:
  print('No')



### FIXED CODE ###

w=list(input())
ans=sorted(w)

if len(ans)>1:
  while ans[-1]==ans[-2]:
    del ans[-2:]
    if len(ans)==0 or len(ans)==1:
      break

if len(ans)==0:
  print('Yes')
else:
  print('No')
N=int(input())
A=list(map(int,input().split()))

for i in range(N-1,0,-1) :
    if A[i-1]>A[i] :
        if A[i]<A[i+1] :
            continue
        A.pop(i)
print(A)

if len(A)==1 :
    print(1000)
    exit()

n=len(A)
money=1000
kabu=0


for i in range(n-1) : 
    if i==n-2 :
        if A[i-1]<=A[i] :
            continue
        elif A[i-1]>A[i] :
            kabu+=money//A[i]
            money-=A[i]*(money//A[i])

    if A[i]<A[i+1] and money>=A[i] : #株を買う
        kabu+=money//A[i]
        money-=A[i]*(money//A[i])

    elif A[i]>A[i+1] and kabu>0 :    #株を売る
        money+=kabu*A[i]
        kabu=0

else :
    money+=kabu*A[n-1]
    print(money)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))

money=1000
stock=0

for i in range(N-1) :
    if A[i]<A[i+1] :
        stock=money//A[i]
        money-=stock*A[i]
        money+=stock*A[i+1]

    else :
        continue

print(money)
N, L = map(int, input().split())
S = ["" for i in range(N)]
for i in range(N):
    S[i] = input()

S.sort()
result = ""
for i in range(N):
    result += S[i]
print(result)

### FIXED CODE ###

a = sorted(list(map(int, input().split())))

if a == [5,5,7]:
    print("YES")
else:
    print("NO")
x, y = input().split()

x = int(x)
y = float(y)

print(int(x * y, 10))

### FIXED CODE ###

import math
x, y = list(map(float, input().split()))

x = int(x)
y = int(y * 100 + 0.5)
 
print(x * y // 100)
x=int(input())
y=int(input())
print(x*y)
print(x*2+y*2)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,(a+b)*2)
while True:
    a, op, b = (input().split())

    a = int(a)
    b = int(b)
    if op == "+":
        print(a +b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a / b)
    else op == "?":
        break

### FIXED CODE ###

while True:
    a, op, b = (input().split())
    x = int(a)
    y = int(b)
    if op == "?":
        break
    elif op == "-":
        print(x - y)
    elif op == "+":
        print(x + y)
    elif op =="*":
        print (x * y)
    elif op == "/":
        print (x // y)
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()

ans=0
c=0
for i in range(n-1):
    if len(a)>0 and a[c]==a[c+1]:
        a.pop(0)
        a.pop(0)
    else:
        c+=1
print(len(a))

### FIXED CODE ###

n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
l.append(10000000000000000000000)
f=1
ans=0
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        ans+=f%2
        f=1
print(ans)
from math import factorial as f;b,w=map(int,input().split());gcd=lambda a,b:gcd(max(a,b)%min(a,b),min(a,b))if max(a,b)%min(a,b)else min(a,b);p=f(b+w)//f(b)//f(w)
def g(x,y):print((1000000008*x)//y)
q=2
for i in range(min(b,w)):g(1,2);q*=2
x,y=1,2
for i in range(b+w-min(b,w)-1):bunbo=q;bunsi=q//2+1;x,y=bunbo,bunsi;g(y,x);q*=2
g(y,x)

### FIXED CODE ###

a,b,c=map(int,input().split())
if a==b and b==c:print('Yes')
else:print('No')
def R(xyzr1,xyzr2):
	x1,y1,z1,r1 = xyzr1
	x2,y2,z2,r2 = xyzr2
	return max(0,((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)**0.5 - r1 - r2)

while 1:
	n = input()
	if n == 0: break
	xyzr = [map(float,raw_input().split()) for i in range(n)]
	ans = 1e10
	for i in range(n):
		for j in range(i+1,n):
			l = R(xyzr[i],xyzr[j])
			if l < ans:
				ans = l
				s = i
	chain = [xyzr.pop(s)]
	while xyzr:
		pipe = 1e10
		for i in range(len(xyzr)):
			for j in range(len(chain)):
				l = R(xyzr[i],chain[j])
				if l < pipe:
					pipe = l
					p = i
		ans += pipe
		chain.append(xyzr.pop(p))
	print ans

### FIXED CODE ###

inf = 1 << 28
def calc(xyzr1,xyzr2):
    x1,y1,z1,r1 = xyzr1
    x2,y2,z2,r2 = xyzr2
    d = ((x1-x2)**2+(y1-y2)**2+(z1-z2)**2)**0.5
    return max(0, d-r1-r2)
    
while 1:
    n = int(raw_input())
    if n == 0: break
    xyzr = [map(float,raw_input().split()) for i in xrange(n)]
    
    cost = [[0]*n for i in xrange(n)]
    for i in xrange(n):
        for j in xrange(n):
            cost[i][j] = cost[j][i] = calc(xyzr[i],xyzr[j])
    
    mincost = [inf]*n
    used = [False]*n
    mincost[0] = 0
    ans = 0
    while 1:
        v = -1
        for u in xrange(n):
            if not used[u] and (v == -1 or mincost[u] < mincost[v]): v = u
        if v == -1: break
        used[v] = True
        ans += mincost[v]
        for u in xrange(n):
            mincost[u] = min(mincost[u], cost[v][u])
    
    print "%.3f"%ans