Harryxun/stf_run huggingface dataset:
n=int(input())
a,b=map(int,input().split())
d=[]
e=[]
f=[]
for i in range(n):
    k=int(input())
    if k<=a:
        d.append(k)
    elif a<k<=b:
        e.append(k)
    else:
        f.append(k)
print(min(len(d),len(e),len(f)))

### FIXED CODE ###

n=int(input())
a,b=map(int,input().split())
H=list(map(int,input().split()))
d=[]
e=[]
f=[]
for i in range(n):
    k=H[i]
    if k<=a:
        d.append(k)
    elif a<k<=b:
        e.append(k)
    else:
        f.append(k)
print(min(len(d),len(e),len(f)))
import numpy as np
import math
import sys
sys.float_info.max
H, W, A, B = map(int, input().split())

StoB = np.zeros(B)
BtoE = np.zeros(B)
sum = 0
# print(StoB)
# print(BtoE)
all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# print(all)
for i in range(B):
    # print(i)
    # print(H - A)
    StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
    # print(StoB[i])
# print(StoB)
    BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# print(BtoE)
    sum += StoB[i] * BtoE[i]
print(int(all - sum) % (10 ** 9 - 7))


### FIXED CODE ###

h,w,a,b = map(int,input().split()) #入力
mod = 10**9+7 

#前計算　f[i] = i!
f=[1]
for i in range(h+w):
  f.append(f[i]*(i+1)%mod)

#C(n,r,p) = ( n! * r!^(p-2) * (n-r)!^(p-2) )%p
#pythonだとpow()で二分累乗法が使える
def comb(n, r, p):
  return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) % p

#紫点ごとに調べる
ans=0
for i in range(b, w):
  ans+= comb(h+i-a-1, i, mod) * comb(w-1-i+a-1, a-1, mod) % mod

print(ans%mod)
N = int(input())
n = N%10
if n == 2 or 4 0r 5 0r 7 or 9:
  print("hon")
if n == 0 or 1 or 6 or 8:
  print("pon")
if n == 3:
  print("bon")

### FIXED CODE ###

N = int(input())
n = N%10
if n == 2 or n == 4 or n ==5 or n ==7 or n == 9:
  print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
  print("pon")
else :
  print("bon")
s1, s2, s3 = input().split(" ")

print(s1[0].upper+s1[1:]+s2[0].upper+s2[1:]+s3[0].upper+s3[1:])


### FIXED CODE ###

s1, s2, s3 = input().split(" ")
    
print(s1[0].upper()+s2[0].upper()+s3[0].upper())
import sys
import itertools
import numpy as np

MOD = 998244353
MAX = 10 ** 5 * 2 + 5

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

comInit(MOD)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
n, m, k = map(int, readline().split())

ans = 0
for x in range(k, -1, -1):
    ans += now * com(n - 1, x, MOD) % MOD
    # ans += tmp
print(ans % MOD)

### FIXED CODE ###

import sys
import itertools
import numpy as np

MOD = 998244353
MAX = 10 ** 5 * 2 + 5

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

comInit(MOD)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
n, m, k = map(int, readline().split())

ans = 0
col = m
for x in range(n - 1, -1, -1):
    now = col
    now *= com(n - 1, x, MOD) % MOD
    if x <= k:
        ans += now
    col = (col * (m - 1)) % MOD

print(ans % MOD)
A,B,C,D=map(int,input())
e=A+B-C-D
print("Balanced")if e==0 else print(["Left",0,"Right"][e/abs(e)])


### FIXED CODE ###

A,B,C,D=map(int,input().split())
e=A+B-C-D
print("Balanced")if e==0 else print(["","Left","Right"][int(e/abs(e))])
from math import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)

### FIXED CODE ###

from fractions import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)
a,b,c=input().split();print('YNEOS'[a[-1]^b[0]^b[-1]^c[0]>0::2])

### FIXED CODE ###

a,b,c=map(list,input().split())
print("YNEOS"[a[-1]!=b[0]or b[-1]!=c[0]::2])
a, b, k = map(int, input().split())

l = list(range(a, b + 1))
ans = []
ans.extend(l[:k])
ans.extend(l[len(l) - k:])

ans = sorted(list(set(ans)))
for a in ans:
   print(a)

### FIXED CODE ###

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

for i in range(a, min(b, a + k - 1) + 1):
    print(i)
for i in range(max(a + k, b - k + 1), b + 1):
    print(i)

exit()
l = list(range(a, b + 1))
ans = []
ans.extend(l[:min(k,len(l))])
ans.extend(l[max(0,len(l) - k):])

ans = sorted(list(set(ans)))
for a in ans:
   print(a)
s = int(input())
x1 = 10 ** 9

if s < x1:
    print(0, 0, s, 0, 0, 1)
elif a - int(a) == 0:
    print(0, 0, i, 0, 0, i)
else:
    y2 = s // x1
    if s % x1 == 0:
        print(0, 0, x1, 0, 0, y2)
    else:
        y2 += 1
        y1 = y2 * x1 - s
        print(0, 0, x1, y1, 1, y2)

### FIXED CODE ###

s = int(input())
x1 = 10 ** 9
if s < x1:
    print(0, 0, s, 0, 0, 1)
else:
    y2 = s // x1
    if s % x1 == 0:
        print(0, 0, x1, 0, 0, y2)
    else:
        y2 += 1
        y1 = y2 * x1 - s
        print(0, 0, x1, y1, 1, y2)
import math
from functools import reduce
#import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
n, k  = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(k)
x.sort()


def gcd_list(numbers):
    return reduce(math.gcd, numbers)

dif = []
for i in range(n):
    dif.append(x[i+1]-x[i])

ans = gcd_list(dif)
print(ans)

### FIXED CODE ###

import math
from functools import reduce
import fractions
#import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
n, k  = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(k)
x.sort()

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

dif = []
for i in range(n):
    dif.append(x[i+1]-x[i])

ans = gcd_list(dif)
print(ans)
def prod(array):
    res = 1
    for a, _ in array:
        res *= a
        res %= MOD
    return res

MOD = 10**9 + 7
N, K = map(int, input().split())
if N==K:
    res = 1
    for a in map(int, input().split()):
        res *= a
        res %= MOD
    print(res)
    exit()
A = []
allsgn = 0
for a in map(int, input().split()):
    A.append((abs(a), a < 0))
    allsgn += a<0
A.sort(reverse=True)
sgn = 0
s0 = -1
lastA = -1
for i, p in enumerate(A[:K]):
    a, s = p
    sgn += s
    if s != s0:
        lastA = i-1
    s0 = s
lasts = s0
if allsgn==N:
    if K%2==1:
        print((-prod(A[-K:]))%MOD)
        exit()
    else:
        raise Exception('Error!')
        print(prod(A[:K])%MOD)
        exit()
if sgn%2==0:
    print(prod(A[:K])%MOD)
    exit()
if lasts != A[K][1]:
    res = prod(A[:K-1])*A[K][0]
else:
    firstA = None
    for i, p in enumerate(A[K:],start=K):
        a, s = p
        if s != lasts:
            firstA = i
            break
    res1 = prod(A[:K-1])*A[firstA][0] if firstA is not None else -float("inf")
    res2 = prod(A[:lastA])*prod(A[lastA+1:K+1]) if lastA != -1 else -float("inf")
    res = max(res1, res2)
print(res%MOD)
"""
6 4
5 -3 -3 -3 -3 -2

5 3
-1 -2 -3 -4 -5
"""

### FIXED CODE ###

def prod(array):
    res = 1
    for a, _ in array:
        res *= a
        res %= MOD
    return res

MOD = 10**9 + 7
N, K = map(int, input().split())
if N==K:
    res = 1
    for a in map(int, input().split()):
        res *= a
        res %= MOD
    print(res)
    exit()
A = []
allsgn = 0
for a in map(int, input().split()):
    A.append((abs(a), a < 0))
    allsgn += a<0
A.sort(reverse=True)
sgn = 0
s0 = -1
lastA = -1
for i, p in enumerate(A[:K]):
    a, s = p
    sgn += s
    if s != s0:
        lastA = i-1
    s0 = s
lasts = s0
if allsgn==N:
    if K%2==1:
        print((-prod(A[-K:]))%MOD)
        exit()
    else:
        print(prod(A[:K])%MOD)
        exit()
if sgn%2==0:
    print(prod(A[:K])%MOD)
    exit()
if lasts != A[K][1]:
    res = prod(A[:K-1])*A[K][0]
else:
    firstA = None
    for i, p in enumerate(A[K:],start=K):
        a, s = p
        if s != lasts:
            firstA = i
            break
    if lastA == -1 or (firstA is not None and A[K][0]/A[lastA][0] < A[firstA][0]/A[K-1][0]):
        res = prod(A[:K - 1]) * A[firstA][0]
    else:
        res = prod(A[:lastA]) * prod(A[lastA + 1:K + 1])
print(res%MOD)
"""
6 3
5 -3 -3 -3 -3 -2

10 7
-10 -10 -10 -10 10 10 10 10 10 10
"""
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)
print(*ans, sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in ans:
    print(i)
n = I()
dp = [0] * (500000)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            pe = x**2 + y**2 + z**2 + x*y + y*z + z*x
            dp[pe] += 1
print(*dp[1:n+1],sep='\n')

### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
dp = [0] * (500000)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            pe = x**2 + y**2 + z**2 + x*y + y*z + z*x
            dp[pe] += 1
print(*dp[1:n+1],sep='\n')
import math
H, W = list(map(int, input().split()))

sum = float(H*W)

if sum == 0:
    print(0)
else if sum%2 == 0:
    print(H*W//2)
else:
    print(math.floor(H*W/2)+1)

### FIXED CODE ###

import math
H, W = list(map(int, input().split()))

sum = float(H*W)
if sum%2 == 0:
    if H == 1 or W == 1:
        print(1)
    else:
        print(H*W//2)
else:
    if H == 1 or W == 1:
        print(1)
    else:
        print(math.floor(H*W/2)+1)
# -*- coding: utf-8 -*-
import sys

# スペース区切りの整数の入力
N, *d = map(int, open(0).read().split())

if 0 in d:
  print(0)
  return
  
for O in d:
	A = A * O
	#print(O)
	if A > 1000000000000000000:
		A = -1
		break

print(A)

### FIXED CODE ###

N, M = map(int, input().split())

print(N*M)
a=intput()
if a=="ABC":
    print("ARC")
elif a=="ARC":
    print("ABC")

### FIXED CODE ###

a=input()
if a=="ABC":
    print("ARC")
elif a=="ARC":
    print("ABC")
n=int(input())
from math import log, floor
  
def ten_to_n(X,n):
  if X//n:
    ans = ten_to_n(X//n,n)
    ans.append(X%n)
    return ans
  else:
    return [X%n]
  
dic = {}
l = ten_to_n(n-1,26)
l[-1]+=1
for i in range(len(l)-1,0,-1):
  if l[i] > 25:
    t = l[i]
    l[i-1] += t//26
    l[i] = t%26
#print(l)
    
for v1,v2 in zip(range(1,27),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''.join([dic[v] for v in l])
print(ans)  



### FIXED CODE ###

n=int(input())
from math import log, floor
dic = {}    
for v1,v2 in zip(range(26),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''
for i in range(1,99):
  if n <= 26**i:
    n-=1
    for j in range(i):
      ans += dic[n%26]
      n //= 26
    break
  else:
    n -= 26**i

print(ans[::-1])
def resolve():
    N = int(input())
    x_list = list(map(int, input().split()))

    x_min = min(x_list)
    x_max = max(x_list)
    hp_min = None

    for i in range(x_min, x_max+1):
        tmp_hp = 0
        for j in x_list:
            tmp_hp += (j - i)**2
        if (hp_min is None) or (tmp_hp < hp_min):
            hp_min = tmp_hp

    print(hp_min)

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    N, R = map(int, input().split())  

    if N >= 10:
        print(R)
    else:
        R = R + 100 * (10 - N)
        print(R)
 
if __name__ == "__main__":
    resolve()
A, B = map(int,input().split())

if A < 9 and b < 9:
        print('Yay!')
else:
        print(':(')

### FIXED CODE ###

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

if A < 9 and B < 9:
        print('Yay!')
else:
        print(':(')
a=list(map(int, input().split()))
index = input.a(0)
print(a)

### FIXED CODE ###

c=list(map(int, input().split()))
for i in range(len(c)):
    if(c[i]==0):
        a = i+1
        print(a)
N,K = map(int,input().split())
l = [map(int,input().split())]
m = sorted(l).reverse()
b = []
for i in range(K):
  b.append(m[i])
print(sum(b))

### FIXED CODE ###

N , K = map(int,input().split())
l = list(map(int,input().split()))
asc_lst = sorted(l)
ans = []
for i in range(K):
    ans.append(asc_lst[-(i+1)])

A = sum(ans)
print(A)
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i - j):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

### FIXED CODE ###

n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")
def dis(x1, y1, x2, y2):
  d = math.sqrt((x2-x1)**2 + (y2-y1)**2)
  return d

def dfs(visited, x, y, prev, dis, total_dis):
  n = len(x) 
  allCityVisited = True
  for i in range(n):
    if visited[i] is False:
      allCityVisited = False
  if allCityVisited:
    total_dis += dis
    return total_dis
    
  for i in range(n):
    if visited[i] is False:
      dis += dis(x[i], y[i], x[prev], y[prev])
      visited[i] = True
      org_prev = prev
      prev = i
      dfs(visited, x, y, prev, dis, total_dis)
      visited[i] = False
      prev = org_prev
      
  return total_dis

n = int(input())
x = [0]*n
y = [0]*n

for i in range(n):
  x[i], y[i] = map(int, input().split())
  
visited = [False]*n
total_dis = 0

for i in range(n):
  visited[i] = True
  total_dis += dfs(visited, x, y, i, 0, totala_dis)
  visited[i] = False
  
prem = 1
for i in range(n):
  perm*=n
  
print(total_dis/perm)


### FIXED CODE ###

def dfs(coord, visited, route, sum):
    n = len(visited)

    allVisited = True
    for city in range(n):
        if visited[city] is False:
            allVisited = False
            break

    if allVisited is True:
        dist = 0

        for i in range(1, len(route)):
            prev = route[i - 1]
            cur = route[i]
            dist += (
                (coord[prev][0] - coord[cur][0]) ** 2
                + (coord[prev][1] - coord[cur][1]) ** 2
            ) ** 0.5
        sum += dist
        return sum

    for next_city in range(n):
        if visited[next_city] is False:
            visited[next_city] = True
            route.append(next_city)
            sum = dfs(coord, visited, route, sum)
            visited[next_city] = False
            route.pop(-1)

    return sum


n = int(input())
coord = []
route = []
visited = [False] * n

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


sum = 0
sum = dfs(coord, visited, route, sum)

perm = 1
for i in range(1, n + 1):
    perm *= i

print(sum / perm)
from collections import deque
import copy

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p1 = deque(p)
q1 = deque(q)
r1 = deque(r)
p2 = copy.deepcopy(p1)
q2 = copy.deepcopy(q1)
r2 = copy.deepcopy(r1)


ans = 0

ans1 = 0
for _ in range(X):
    if len(r1) > 0:
        if p1[0] > r1[0]:
            ans1 += p1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += p1.popleft()

for _ in range(Y):
    if len(r1) > 0:
        if q1[0] > r1[0]:
            ans1 += q1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += q1.popleft()

ans2 = 0
for _ in range(Y):
    if len(r2) > 0:
        if q2[0] > r2[0]:
            ans2 += q2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += q2.popleft()

for _ in range(X):
    if len(r2) > 0:
        if p2[0] > r2[0]:
            ans2 += p2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += p2.popleft()

ans = max(ans1, ans2)
print(ans)


### FIXED CODE ###

X = int(input())
ans = 0
ans += 1000 * (X // 500)
X = X % 500
ans += 5 * (X // 5)
print(ans)
N=int(input())
import math
A=list(map(int,input().split()))
b=math.ceil(math.log2(max(A))) 
B=[0 for i in range(b)] #0のリスト
C=[0 for i in range(b)] #1のリスト
for i in A:
  for j in range(b):
    if ((i>>j) & 1):
      C[j]+=1
    else:
      B[j]+=1
 # print(B,C,i)
mod =10**9+7
ans=[(B[i]*C[i])*2**i % mod for i in range(b)]
print(sum(ans)%mod)

### FIXED CODE ###

N=int(input())
import math
A=list(map(int,input().split()))
b=math.ceil(math.log(max(max(A),1),2)) 
B=[0 for i in range(b)] #0のリスト
C=[0 for i in range(b)] #1のリスト
for i in A:
  for j in range(b):
    if ((i>>j) & 1):
      C[j]+=1
    else:
      B[j]+=1
 # print(B,C,i)
mod =10**9+7
ans=[(B[i]*C[i])*2**i % mod for i in range(b)]
print(sum(ans)%mod)
for i in range(n)
 i += 1
 x = input()
 if x == 0:
  break:
 print "case %d: %d" %(i x)

### FIXED CODE ###

 

import sys
for i,ws in enumerate(sys.stdin, 1):
    w = ws[:-1]
    if w =='0': break
    print 'Case %d: %s' % (i, w)
D,N=map(int,input().split())
if N=100 :
    print((N+1)*100*D)
else :    
    print(N*100**D)


### FIXED CODE ###

D,N=map(int,input().split())
if N<100 :
    print(N*100**D)
else :
    print((N+1)*100**D)
from sys import stdin
X = (stdin.readline().rstrip())
stack = []
for i in X:
    if i == "S":
        stack.append(i)
    elif i == "T" and stack[-1] == "S":
        stack.pop()
    else:
        stack.append(i)
print(len(stack))

### FIXED CODE ###

from sys import stdin
from collections import deque
X = (stdin.readline().rstrip())
stack = []
for i in X:
    if i == "S":
        stack.append(i)
    elif (i == "T" and stack == []):
        stack.append(i)
    elif (i == "T" and stack[-1] == "S"):
        stack.pop()
    else:
        stack.append(i)
print(len(stack))
n = input()
l = len(n)

if set(list(n[1:])) == {"9"}:
    print(int(n[0])+9*(len(n)-1))
else:
    print(int(n[0])-1+9*(len(n)-1))n = input()
l = len(n)
if l == 1:
    print(n)
elif set(list(n[1:])) == {"9"}:
    print(int(n[0])+9*(l-1))
else:
    print(int(n[0])-1+9*(l-1))

### FIXED CODE ###

n = input()
l = len(n)

if l == 1:
    print(n)
elif set(list(n[1:])) == {"9"}:
    print(int(n[0])+9*(l-1))
else:
    print(int(n[0])-1+9*(l-1))
n,m=map(int,input().split())
g=[[] for _ in range((n+m))]
for i in range(n):
    a=[int(i)-1 for i in input().split()][1:]
    for l in a:
        g[i].append(l)
        g[n+l].append(i)

par=[i for i in range(n+m)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
        
def connect(x,y):
    rx=root(x)
    ry=root(y)
    if rx==ry:
        0
    else:
        par[rx]=ry
    return

for i in range(n+m):
    for nb in g[i]:
        connect(i,nb)

p=par[0]
ans='YES'
for i in range(n):
    if par[i]!=p:
        ans='NO'

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n,m=map(int,input().split())
g=[[] for _ in range((n+m))]
for i in range(n):
    a=[int(i)-1 for i in input().split()][1:]
    for l in a:
        g[i].append(n+l)
        g[n+l].append(i)

par=[i for i in range(n+m)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
        
def connect(x,y):
    rx=root(x)
    ry=root(y)
    if rx!=ry:
        par[rx]=ry
    return

for i in range(n+m):
    for nb in g[i]:
        connect(i,nb)

p=par[0]
ans='YES'
for i in range(n):
    if par[i]!=p:
        ans='NO'

print(ans)
from math import gcd

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

D = gcd(A, B)
d = D.copy()
ans = 1
i = 2
while i <= pow(D, 1/2):
  if d%i == 0:
    ans += 1
    while d%i == 0:
      d //= i
  i += 1
print(ans)

### FIXED CODE ###

from math import gcd

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

d = gcd(A, B)
ans = 1
i = 2
while i <= pow(d, 1/2)+1:
  if d%i == 0:
    ans += 1
    while d%i == 0:
      d //= i
  i += 1
ans += (d > 1)
print(ans)
N, M = map(int, input().split())

sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 100000 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

p = []
for i in range(N - 1, -1, -1):
    if sieve[i] == i:
        p.append(i)
p.append(1)

t = set()
pp = 0
for i in range(M):
    x = i + 1
    y = x + p[pp]
    while y in t:
        pp += 1
        y = x + p[pp]
    t.add(x)
    t.add(y)
    print(x, y)
    pp += 1


### FIXED CODE ###

N, M = map(int, input().split())

for i in range(1, M + 1):
    if i % 2 == 1:
        j = (i - 1) // 2
        print(1 + j, M + 1 - j)
    else:
        j = (i - 2) // 2
        print(M + 2 + j, 2 * M + 1 - j)
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]
    ans = 0
    pre = -1
    for i in range(n):
        ans += b[a[i] - 1]
        if pre == a[i] - 1:
            ans += c[pre - 1]
        pre = a[i]
    print(ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    b = [int(i) for i in input().split()]

    a = ([b[0]])
    for i in range(1,n-1):
        a.append(min(b[i-1],b[i]))
    a.append(b[-1])
    print(sum(a))
if __name__ == "__main__":
    main()
while True:
	x,y=sorted(map(int,input().split()))
	if (x==0) and(y==0):
		break
	print(*a)


### FIXED CODE ###

while True:
	x,y=sorted(map(int,input().split()))
	if x==0 and y==0:
		break
	print(x, y)
1 N, K = map(int, input().split())
2 h = [int(input()) for i in range(N)]
3 h.sort()
4 print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
n = int(input())
lis = [int(input()) for i in range(n)]
li=sort(lis,reverse=True)
for i in range(n):
  if lis[i] == lis[0]:
    print(lis[1])
  else:
    print(lis[0])

### FIXED CODE ###

n = int(input())
lis = [int(input()) for i in range(n)]
li=sorted(lis,reverse=True)
for i in range(n):
  if lis[i] == li[0]:
    print(li[1])
  else:
    print(li[0])