Harryxun/stf_run huggingface dataset:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
sgm=pow(10.-7)
def func(c):
    allp=[]
    for i in range(n-1):
        for j in range(i+1,n):
            xi,yi=xy[i]
            xj,yj=xy[j]
            dx=xi-xj
            dy=yi-yj
            d=((xi-xj)**2+(yi-yj)**2)**0.5
            if c**2-(d/2)**2<0:return False
            h=(c**2-(d/2)**2)**0.5
            mx,my=(xi+xj)/2,(yi+yj)/2
            if dx==0:
                allp.append([mx-h,my])
                allp.append([mx+h,my])
            elif dy==0:
                allp.append([mx,my-h])
                allp.append([mx,my+h])
            else:
                dx,dy=dy,-dx
                dh=(dy**2+dx**2)**0.5
                dx*=h/dh
                dy*=h/dh
                allp.append([mx+dx,my+dy])
                allp.append([mx-dx,my-dy])
    for px,py in allp:
        flg=True
        for x,y in xy:
            if ((px-x)**2+(py-y)**2)**0.5>c+sgm:
                flg=False
                break
        if flg:
            return True
    return False

r=2*max([abs(x) for x,y in xy])+max([abs(y) for x,y in xy])
l,r=0,r
for i in range(300):
    c=(l+r)/2
    if func(c):
        l,r=l,c
    else:
        l,r=c,r
print(c)
#print(c**2)

### FIXED CODE ###

n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
sgm=pow(10,-7)
def func(c):
    allp=[]
    for i in range(n-1):
        for j in range(i+1,n):
            xi,yi=xy[i]
            xj,yj=xy[j]
            dx=xi-xj
            dy=yi-yj
            d=((xi-xj)**2+(yi-yj)**2)**0.5
            if c**2-(d/2)**2<0:return False
            h=(c**2-(d/2)**2)**0.5
            mx,my=(xi+xj)/2,(yi+yj)/2
            if dx==0:
                allp.append([mx-h,my])
                allp.append([mx+h,my])
            elif dy==0:
                allp.append([mx,my-h])
                allp.append([mx,my+h])
            else:
                dx,dy=dy,-dx
                dh=(dy**2+dx**2)**0.5
                dx*=h/dh
                dy*=h/dh
                allp.append([mx+dx,my+dy])
                allp.append([mx-dx,my-dy])
    for px,py in allp:
        flg=True
        for x,y in xy:
            if ((px-x)**2+(py-y)**2)**0.5>c+sgm:
                flg=False
                break
        if flg:
            return True
    return False

r=2*max([abs(x) for x,y in xy])+max([abs(y) for x,y in xy])
l,r=0,r
for i in range(400):
    c=(l+r)/2
    if func(c):
        l,r=l,c
    else:
        l,r=c,r
print(c)
#print(c**2)
N = int(input())

# 二次元配列の初期化
# 0番目をaの出現回数、
# 1番目をbの出現回数とする
x = [[0 for i in range(24)] for j in range(N)]
#print(x)

for n in range(N):
    tmp=list(input())
    # 文字列をソートする
    tmp.sort()

    # 重複排除して、それぞれの文字が何回出現したかを数える
    tmp2 = set(tmp)
    for l in tmp2:
        #print(n, ord(l)-97,l,  tmp.count(l))
        x[n][ord(l)-97]= tmp.count(l)

ans  =[]
# a~zまで調べていき、全員最低1回以上出していれば、
# その文字は出力する。最低出現回数分連続させる。
for i in range(24):
    tmp3 = [row[i] for row in x]
    tmp4 = chr(97+i)* min(tmp3) if min(tmp3) != 0 else ""
    ans.append(tmp4)

print("".join(ans))


### FIXED CODE ###

N = int(input())

# 二次元配列の初期化
# 0番目をaの出現回数、
# 1番目をbの出現回数とする
x = [[0 for i in range(26)] for j in range(N)]
#print(x)

for n in range(N):
    tmp=list(input())
    # 文字列をソートする
    tmp.sort()

    # 重複排除して、それぞれの文字が何回出現したかを数える
    tmp2 = set(tmp)
    for l in tmp2:
        #print(n, ord(l)-97,l,  tmp.count(l))
        x[n][ord(l)-97]= tmp.count(l)

ans  =[]
# a~zまで調べていき、全員最低1回以上出していれば、
# その文字は出力する。最低出現回数分連続させる。
for i in range(26):
    tmp3 = [row[i] for row in x]
    tmp4 = chr(97+i)* min(tmp3) if min(tmp3) != 0 else ""
    ans.append(tmp4)

print("".join(ans))
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  l,r = 1,1
  while a[i-l] > a[i] and i-l > -1:
    l += 1
  while a[i+r] > a[i] and i+r < n:
    r += 1
  ans += l*r*a[i]
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)
x=int(input)
print(abs(1-x))

### FIXED CODE ###

x=int(input())
print(abs(1-x))
import re

s = input()
s = s[::-1]
ans = 0
for i in range(s.count('A')):
    a = re.search('(CB)+A', s)
    ans += (a.end()-a.start()-1)//2
    s = s.replace('A', '', 1)
    print((a.end()-a.start()),s,ans)
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

s = input()
s = s[::-1]
ans = 0
a = -1
s = (s.replace('CB', 'D').replace('C', '\t').replace('B', '\t')).split()
for i in range(len(s)):
    for j in range(s[i].count('A')):
        a = s[i].find('A',a+1)
        ans += a-j
    a = -1
print(ans)
A = int(input())
B = int(input())

x = ((B-1) // (A-1))+1
print(x)


### FIXED CODE ###


s = input()
t = input()

list(s)
list(t)

if s[0] == t[0] and s[1] == t[1] and s[2] == t[2]:
    print(3)

elif s[0] == t[0] and s[1] == t[1] and s[2] != t[2]:
    print(2)

elif s[0] == t[0] and s[1] != t[1] and s[2] == t[2]:
    print(2)

elif s[0] != t[0] and s[1] == t[1] and s[2] == t[2]:
    print(2)

elif s[0] == t[0] and s[1] != t[1] and s[2] != t[2]:
    print(1)

elif s[0] != t[0] and s[1] != t[1] and s[2] == t[2]:
    print(1)

elif s[0] != t[0] and s[1] == t[1] and s[2] != t[2]:
    print(1)

else:
    print(0)
d=int(input())
t=int(input())
s=int(input())

if d == 0:
    print ('error')
    
elif t == 0:
    print ('error')
        
elif s == 0:
    print ('error')

else:
    
    if (s*t) >= d :
        print ('Yes')
    
    else:
        print ('No')



### FIXED CODE ###

#輸入字串並分隔，以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))  
#print(num) #D,T,S

#若T<(D/S)->遲到
if num[1] >= (num[0]/num[2]):
    print("Yes")
else:
    print("No")
k = int(input())
x = int(input())

if k * 500 >= x:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

data = input().split()
k = int(data[0])
x = int(data[1])
 
if k * 500 >= x:
  print("Yes")
else:
  print("No")
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
  if n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N-1])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import collections
import math

# 入力
N = int(input())
A = list(input().split())

c = collections.Counter(A)

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

comb_sum = 0
for i in c:
    comb_sum += comb(c[i], 2)
     
for a in A:
    ans = comb_sum
    if c[a] >= 2:
        ans -= (c[a] - 1)
    print(ans)
from bisect import bisect_right
from collections import defaultdict
h, w = map(int, input().split())
c = []
bf, bl = defaultdict(list), defaultdict(list)
ans = 0

for i in range(h):
    s = input()
    c.append(s)
    for j in range(w):
        if s[j] == '#':
            bl[i].append(j)
            bf[j].append(i)

for i in range(h):
    for j in range(w):
        tmp = 0
        if c[i][j] == '.':
            vert = bisect_right(bf[j], i)
            horz = bisect_right(bl[i], j)
            #print(bf[j], bl[i], i, j, vert, horz)
            if bf[j] == []:
                tmp += h-1
            elif i < bf[j][0] or bf[j][-1] < i:
                if i < bf[j][0]:
                    tmp += bf[j][0]-1
                else:
                    tmp += h-bf[j][-1]-2
            else:
                tmp += bf[j][vert]-bf[j][vert-1]-2
            if bl[i] == []:
                tmp += w-1
            elif j < bl[i][0] or bl[i][-1] < j:
                if j < bl[i][0]:
                    tmp += bl[i][0]-1
                else:
                    tmp += w-bl[i][-1]-2
            else:
                tmp += bl[i][horz]-bl[i][horz-1]-2
        ans = max(ans, tmp+1)
print(ans)

### FIXED CODE ###

a, b, c = map(int, input().split())
A = [a+b, b+c, c+a]
print(min(A))
from sympy import nextprime
X = int(input().strip())
print(nextprime(X-1, 1))

### FIXED CODE ###

import math
N = int(input().strip())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while(True):

    if is_prime(N):
        print(N)
        break

    else:
        N += 1
N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
          N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
            print 0
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
                print 0
                flug =1
                break
        else:
            if not A[i] == i+1:
                print 0
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
           
                flug =1
                break
        else:
            if not A[i] == i+1:
                
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
else:
    print 0

### FIXED CODE ###

N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
            flug = 1
            break

else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
                flug =1
                break
        else:
            if not A[i] == i+1:
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))%(pow(10,9)+7)
else:
    print 0
%%timeit

import math
N = 100

def make_prime_list(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)
    

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num+1, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

prime_list = make_prime_list(100)
e = len(prime_list)*[0]

for i in range(N):
    cur = i + 2
    for index,j in enumerate(prime_list):
        while cur % j == 0:
            e[index] += 1
            cur //= j
print(num(75) + num(25) * (num(3) -1) + num(15) * (num(5) -1)
    +num(5) * (num(5) -1 ) * (num(3) - 2) //2)

### FIXED CODE ###

N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x>=m-1, e)))

print(num(75) + num(25) * (num(3) -1) + num(15) * (num(5) -1)
    +num(5) * (num(5) -1 ) * (num(3) - 2) //2)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

a = list(set(A))
a_n = []
c = []
new = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(cmb(x,2, mod))
    if x >= 2: new.append(cmb(x-1,2, mod))
    else: new.append(0)

  ans = sum(c)
  for i in range(N):
    n = a.index(A[i])
    print(ans-c[n]+new[n])
else:
  for _ in range(N):
    print(0)

### FIXED CODE ###

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

a = list(set(A))
a_c = {}
for v in A:
  if v in a_c:
    a_c[v] += 1
  else:
    a_c[v] = 1

def cmb(n):
  if n < 2: return 0
  else:
    return n * (n-1)//2

S = 0
for k in a_c:
  S += cmb(a_c[k])

for i in range(N):
  print(S - cmb(a_c[A[i]]) + cmb(a_c[A[i]]-1))
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=-1
ans=[]
for ai in a:
  if len(ans)==2:
    break
  if b==ai:
    ans.append(ai)
    b=-1
  else:
    b=ai
print(ans[0]*ans[1])

### FIXED CODE ###

n=int(input())
a=sorted((list(map(int,input().split()))),reverse=True)
con=1
sta=a[0]
check=0
for i in range(1,n):
  if a[i]==sta:
    con+=1
    if con==2:
      check+=1
      x=sta
      a.remove(sta)
      a.remove(sta)
      break
  else:
    con=1
    sta=a[i]
sta=a[0]
con=1
for i in range(1,n-2):
  if a[i]==sta:
    con+=1
    if con==2:
      check+=1
      y=sta
      break
  else:
    con=1
    sta=a[i]
print(x*y if check==2 else "0")
n,m=map(int,input().split())

ab = [map(int, input().split()) for _ in range(m)]
a,b = [list(i) for i in zip(*ab)]

indexlist=[-1]*n

def findroot(x):
    while 1:
        if indexlist[x-1] < 0:
            return x
        else:
            x=indexlist[x-1]
            
def merge(a,b):
    art=findroot(a)
    brt=findroot(b)
    if not art == brt:
        indexlist[art-1]+=indexlist[brt-1]
        indexlist[brt-1]=a
        return
    else:
        return     

for j in range(m):
    a1=a[j]
    b1=b[j]
    merge(a1,b1)

ans=min(indexlist)*(-1)
print(ans)

### FIXED CODE ###

import sys

#UnionFindTreeクラスの定義
class UnionFind():
    #クラスコンストラクタ
    #selfはインスタンス自身
    def __init__(self, n):
        #親ノードを-1に初期化する
        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]

    #xとyの木を併合する
    def union(self, x, y):
        #x,yの根をX,Yとする
        X = self.find(x)
        Y = self.find(y)

        #根が同じなら結合済み
        if X == Y:
            return

        #ノード数が多い方をXとする
        if self.parents[X] > self.parents[Y]:
            X, Y = Y, X

        #XにYのノード数を足す
        self.parents[X] += self.parents[Y]
        #Yの根をXとする
        self.parents[Y] = X


N, M = map(int, input().split())
info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]

#UnionFindインスタンスの生成
uf = UnionFind(N)
for a, b in info:
    #インデックスを調整し、a,bの木を結合
    a -= 1; b -= 1
    uf.union(a, b)

ans = min(uf.parents)

print(-ans)
a,b=map(int,input().split())
from math import gcd
print(int(a*b/gcd(a,b)))

### FIXED CODE ###

a,b=map(int,input().split())
from fractions import gcd
print(int(a*b/gcd(a,b)))
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def lcm(a, b):
    return a * b // gcd(a, b)

n, m = map(int, input().split())
s = str(input())
t = str(input())
l = lcm(n, m)
L = [0] * l
for i in range(n):
    L[i*(l//n)] = s[i]
for j in range(m):
    if L[j*(l//m)] == 0:
        L[j*(l//m)] = t[j]
    elif L[j*(l//m)] == t[j]:
        pass
    else:
        print(-1)
        break
else:
    print(l)


### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def lcm(a, b):
    return a * b // gcd(a, b)

n, m = map(int, input().split())
s = str(input())
t = str(input())
g = gcd(n, m)
l = lcm(n, m)
for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else:
    print(l)
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if l[a-1] >= l[b-1]:
        tmp[b-1]=-1
    if l[a-1] <= l[b-1]
        tmp[a-1]=-1

print(tmp.count(0))

### FIXED CODE ###

n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if l[a-1] >= l[b-1]:
        tmp[b-1]=-1
    if l[a-1] <= l[b-1]:
        tmp[a-1]=-1

print(tmp.count(0))
N = int(input())
d = list(map(int, input().split()))
ans = 0

from itertools import combinations
for i,j in combinations(d,2):
  ans += d[i-1]*d[j-1]
print(ans)
  


### FIXED CODE ###

N = int(input())
d = list(map(int, input().split()))
ans = 0

from itertools import combinations
for i,j in combinations(range(N),2):
  ans += d[i-1]*d[j-1]
print(ans)
I =[int(input())for i in range(5)]

if I[4] - I[0] > I[5] :
	print(":(")
else :
	print(("Yay!"))

### FIXED CODE ###

I =[int(input())for i in range(6)]

if I[4] - I[0] > I[5] :
	print(":(")
else :
	print("Yay!")
H, W, M = map(int, input().split())
bom = [[0]*W for _ in range(H)]
row = [0] * H
col = [0] * W

for _ in range(M):
    h, w = map(int, input().split())
    bom[h-1][w-1] += 1
    row[h-1] += 1
    col[w-1] += 1

max_row = max(row)
max_col = max(col)
ans = max_row + max_col - 1

max_ix_row = [i for i, v in enumerate(row) if v == max_row]
max_ix_col = [i for i, v in enumerate(col) if v == max_col]

flag = False
"""
for i in max_ix_row:
    for j in max_ix_col:
        if not bom[i][j]:
            ans += 1
            flag = True
            break
    
    if flag:
        break"""

print(ans)


### FIXED CODE ###

H, W, M = map(int, input().split())
bom = set()
row = [0] * H
col = [0] * W

for _ in range(M):
    h, w = map(int, input().split())
    bom.add((h-1, w-1))
    row[h-1] += 1
    col[w-1] += 1

max_row = max(row)
max_col = max(col)
ans = max_row + max_col - 1

p, q = [], []

for i in range(H):
    if row[i] == max_row:
        p.append(i)

for j in range(W):
    if col[j] == max_col:
        q.append(j)

flag = False
for i in p:
    for j in q:
        if (i, j) not in bom:
            ans += 1
            flag = True
            break
    if flag:
        break

print(ans)
a,b,k = map(int, input().split())

q = [1]

for i in range(2,50):
  if a % i == 0 and b % i == 0:
    q.append(i)

print(q[k - 1])

### FIXED CODE ###

a,b,k = map(int, input().split())
 
q = []
 
for i in range(1,min(a,b)+1):
  if a % i == 0 and b % i == 0:
    q.append(i)
 
print(q[-k])
a, op, b = map(int, input().split())
op = str(op)
 
if op == "+":
  print(a+b)
else:
  print(a-b)

### FIXED CODE ###

a,o,b=input().split()
a=int(a)
b=int(b)
print(a+b if o=="+" else a-b)
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    check[0]=min(check[n]+n*d,check.get(0))
    if n//ttf==0:
        check[n//ttf]=min(check.get(n//ttf),check[n]+(n%ttf)*d)
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global b
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0}
    dfs(N)
    print(check[0])

### FIXED CODE ###

import sys
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    if 0 in check:
        check[0]=min(check[n]+n*d,check[0])
    else:
        check[0]=check[n]+n*d
    if n//ttf==0:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d:
                check[n//ttf]=check[n]+(n%ttf)*d
        else:
            check[n//ttf]=check[n]+(n%ttf)*d
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global check,a,b,c,d
    dfs_sub(n,2,a)
    dfs_sub(n,3,b)
    dfs_sub(n,5,c)

t=int(input())
ans=[0]*t
for i in range(t):
    N,a,b,c,d=map(int,input().split())
    check={N:0}
    dfs(N)
    ans[i]=check[0]
for i in range(t):
    print(ans[i])
import sys
    sys.setrecursionlimit(10**8)
     
    def treetrace(i):
      score = [-1] * (n + 1)
      if src[i] == 0:
        return point[i]
      elif score[i] != 0:
        return score[i]
      else:
        score[i] = point[i] + treetrace(src[i])
        return score[i]
      
    tmp = list(map(int, (input().split())))
    n = tmp[0]
    q = tmp[1]
     
    src = [0] * (n + 1)
    for i in range(1, n):
      tmp = list(map(int, (input().split())))
      src[tmp[1]] = tmp[0]
     
    point = [0] * (n + 1)
    for i in range(1, q+1):
      tmp = list(map(int, (input().split())))
      point[tmp[0]] += tmp[1]
      
    for i in range(1, n + 1):
      print(treetrace(i), end=" ")

### FIXED CODE ###

tmp = list(map(int, (input().split())))
n = tmp[0]
q = tmp[1]

#edge = defaultdict(list)
edge = [[] for i in range(n+1)]
fixed = [False] * (n + 1)
fixed[1] = True
point = [0] * (n + 1)

for i in range(1, n):
  tmp = list(map(int, (input().split())))
  edge[tmp[0]].append(tmp[1])
  edge[tmp[1]].append(tmp[0])

for i in range(1, q+1):
  tmp = list(map(int, (input().split())))
  point[tmp[0]] += tmp[1]

que = []
que += edge[1]
frm = 1

while len(que) != 0:
  cur = que.pop()
  for i in edge[cur]:
    if fixed[i]:
      point[cur] += point[i]
    else:
      que.append(i)
  fixed[cur] = True

for i in range(1, n+1):
  print (point[i], end=" ")
N,K=map(int,input().split())
l=[False for _ in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in range(N):
        if l[i]==A[i]:
            l[i]=True
print(list.count(False))

### FIXED CODE ###

N,K=map(int,input().split())
l=[False for x in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in A:
        l[j-1]=True
print(l.count(False))
import heapq
N,K = map(int, input().split())

I = []
for _ in range(N):
  t,d = map(int, input().split())
  I.append((d,t))
  
I.sort(reverse=True)

# heap_can_delete
h_d = []
# heap_can_add
h_a = []

wk = 0
kind = 0
# 出現したことのあるネタ
ap = set()
for i in range(K):
  d,t = I[i]
  wk += d
  if t not in ap:
    ap.add(t)
    kind += 1
  else:
    heapq.heappush(h_d, (d,t))

for i in range(K,N):
  d,t = I[i]
  if t not in ap:
    ap.add(t)
    # maxをpopさせるために、価値を-1かけておく
    heapq.heappush(h_a, ((-1) * d, t))
  
ans = wk + kind ** 2
while len(h_d) > 0:
  d1,t1 = heapq.heappop(h_d)
  d2,t2 = heapq.heappop(h_a)
  d2 = (-1) * d2
  wk = wk - d1 + d2
  kind += 1
  ans = max(ans, wk + kind ** 2)
  
print(ans)
  
  

### FIXED CODE ###

import heapq
N,K = map(int, input().split())

I = []
for _ in range(N):
  t,d = map(int, input().split())
  I.append((d,t))
  
I.sort(reverse=True)

# heap_can_delete
h_d = []
# heap_can_add
h_a = []

wk = 0
kind = 0
# 出現したことのあるネタ
ap = set()
for i in range(K):
  d,t = I[i]
  wk += d
  if t not in ap:
    ap.add(t)
    kind += 1
  else:
    heapq.heappush(h_d, (d,t))

for i in range(K,N):
  d,t = I[i]
  if t not in ap:
    ap.add(t)
    # maxをpopさせるために、価値を-1かけておく
    heapq.heappush(h_a, ((-1) * d, t))
  
ans = wk + kind ** 2
while len(h_d) > 0 and len(h_a) > 0:
  d1,t1 = heapq.heappop(h_d)
  d2,t2 = heapq.heappop(h_a)
  d2 = (-1) * d2
  wk = wk - d1 + d2
  kind += 1
  ans = max(ans, wk + kind ** 2)
  
print(ans)