Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def resolve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    B = sorted(A)
    for a in A:
        if a == max(B):
            print(B[-2])
        else:
            print(max(B))
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    B = sorted(A)
    mx = B[-1]
    second = B[-2]
    for a in A:
        if a == mx:
            print(second)
        else:
            print(mx)
resolve()
### BUGGY CODE ###

import sys
s = sys.stdin.readline().rstrip()
t = sys.stdin.readline().rstrip()

sn = len(s)
tn = len(t)

dp =[[0 for _ in range(tn+1)] for _ in range(sn+1)]

for i in range(sn):
    for j in range(tn):
        if s[i]==t[j]:
            dp[i+1][j+1] =dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
#print(dp)

L =[]
while sn>0 and tn>0:
    if dp[sn][tn] == dp[sn-1][tn]: #縦優先
        sn-=1
    elif dp[sn][tn] == dp[sn][tn-1]:
        tn-=1
    elif dp[sn][tn] == dp[sn-1][tn-1]+1:
        L.append(s[sn-1])
        sn-=1
        tn-=1
        
print(''.join(L[::-1]))

### FIXED CODE ###

import sys
s = sys.stdin.readline().rstrip()
t = sys.stdin.readline().rstrip()

sn = len(s)
tn = len(t)

dp =[[0 for _ in range(tn+1)] for _ in range(sn+1)]

for i in range(sn):
    for j in range(tn):
        if s[i]==t[j]:
            dp[i+1][j+1] =dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
#print(dp)

L =[]
while sn>0 and tn>0:
    if dp[sn][tn] == dp[sn-1][tn]: #縦優先
        sn-=1
    elif dp[sn][tn] == dp[sn][tn-1]:
        tn-=1
    elif dp[sn][tn] == dp[sn-1][tn-1]+1:
        L.append(s[sn-1])
        sn-=1
        tn-=1
        
print(''.join(L[::-1]))
### BUGGY CODE ###

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0]*A[1]) // gcd
    for x in A[2:]:
        if max(lcm,x) % min(lcm,x) == 0:
            gcd = min(lcm,x)
        else:
            gcd = xgcd(lcm,x)
        lcm = (lcm * x) // gcd
    ans = 0
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    g = gcd(A[0],A[1])
    lcm = (A[0]*A[1]) // g
    for x in A[2:]:
        lcm = (lcm * x) // gcd(lcm,x)
    print(sum((lcm//x) for x in A)%1000000007)
### BUGGY CODE ###

import numpy as np
import math
import itertools
nums = np.arange(1,int(input())+1)
pp = list(itertools.product(nums, repeat=3))
sum = 0
for p in pp:
  k=math.gcd(p[0],p[1])
  sum+=math.gcd(k,p[2])
print(sum)

### FIXED CODE ###

import math
import itertools
n = range(1,int(input())+1)
ppp = list(itertools.combinations(n, 3))
pp = list(itertools.combinations(n, 2))
asum,bsum,csum = 0,0,0
for p in ppp:
  asum+=math.gcd(math.gcd(p[0],p[1]),p[2])

for p in pp:
  bsum+=math.gcd(p[0],p[1])

for p in n:
  csum+=p

print(asum*6+bsum*6+csum)
### BUGGY CODE ###

N = int(input())
flag = 0
if N < 10:
    for a in range(1,3501):
        if flag == 1:
            break
        for b in range(1,1751):
            M = (4*a*b - N*a - N*b)
            C = N*a*b
            #print(M,C,C/M)
            if M < 0 :
                continue
            elif M != 0:
                if C//M == C/M:
                    c = C//M
                    print(a,b,c)
                    flag = 1
                    break
else:
    A = [i for i in range(1,3501)]
    B = [i for i in range(1,3501)]
    for a in A[::-1]:
        if flag == 1:
            break
        for b in B[::-1]:
            M = (4*a*b - N*a - N*b)
            C = N*a*b
            #print(M,C,C/M)
            if M < 0 :
                continue
            elif M != 0:
                if C//M == C/M:
                    c = C//M
                    print(a,b,c)
                    flag = 1
                    break


### FIXED CODE ###

import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*n*h > N*n + N*h and (N*n*h) % (4*n*h-N*h-N*n) == 0:
            w =  (N*n*h) // (4*n*h-N*h-N*n)
            print(n,h,w)
            sys.exit()
### BUGGY CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))

c=0
x=0

for i in range(1,n-k+1):
#  print(sum(p[x:x+k]),sum(p[i:i+k]))
  if sum(p[x:x+k])<sum(p[i:i+k]):
    x=i
#print(x)
for i in range(x,x+k):
  c+=((p[i]*(p[i]+1))/2)/p[i]
print(c)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))

c=0
x=0
m=sum(p[0:k])
z=m
for i in range(1,n-k+1):
#  print(z,p[i-1],p[i+k-1])
  z=z-p[i-1]+p[i+k-1]
#  print(m,z)
  if m<z:
    m=z
    x=i
#print(x)
for i in range(x,x+k):
#  print(p[i])
  c+=((p[i]*(p[i]+1))/2)/p[i]
print(c)
### BUGGY CODE ###

def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

    N = int(input())
    A = sorted(list(map(int,input().split())))
    B = sorted(list(map(int,input().split())))
    C = sorted(list(map(int,input().split())))
    ans = 0
    for a in A:
        bIdx = bisect(B,a)
        if N - bIdx > 0:
            for j in range(bIdx,N):
                b = B[j]
                cIdx = bisect(C,b)
                if N - cIdx > 0:
                    ans += N-cIdx

    print(ans)
main()

### FIXED CODE ###

"""
前処理で下記のようなメモを作っておく必要がある。
candidate[j] -> 昇順ソートされたBの中でインデックスj以降のパーツを使えるときに、考えられるB,Cの組み合わせの数。
candidateリストを作成するためにまずは、下記のmemoを用意して、その総和としてcandidateを作成する。
memo[j] -> Bの中のインデックスjのパーツを使った場合に使用可能なCの数。
"""

def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

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

    memo = [0]*(N)
    for j in range(N):
        b = B[j]
        cIdx = bisect(C,b)
        memo[j] = N-cIdx
    candidate = [0]*(N)
    candidate[-1] = memo[-1]
    for j in range(N-2,-1,-1):
        candidate[j] += candidate[j+1]+memo[j]

    ans = 0
    for a in A:
        bIdx = bisect(B,a)
        if bIdx < N:
            ans += candidate[bIdx]

    print(ans)
main()
### BUGGY CODE ###

from collections import defaultdict
def twopower(n):
    for i in range(32):
        if n < 2**i:
            return 2**i
N = int( input())
A = list( map( int, input().split()))
d = defaultdict( int)
e = defaultdict( int)
for i in range(N):
    d[A[i]] += 1
A.sort(reverse=True)
i = 0
ans = 0
while i < N:
    if e[A[i]] >= d[A[i]]:
        i += 1
        continue
    e[A[i]] += 1
    L = twopower(A[i]) - A[i]
    if e[L] < d[L]:
        ans += 1
        e[L] += 1
    i += 1
print(ans)


### FIXED CODE ###

from collections import defaultdict
def twopower(n):
    for i in range(32):
        if n < 2**i:
            return 2**i
N = int( input())
A = list( map( int, input().split()))
d = defaultdict( int)
e = defaultdict( int)
for i in range(N):
    d[A[i]] += 1
A.sort(reverse=True)
i = 0
ans = 0
while i < N:
    if e[A[i]] >= d[A[i]]:
        i += 1
        continue
    e[A[i]] += 1
    L = twopower(A[i]) - A[i]
    if e[L] < d[L]:
        ans += 1
        e[L] += 1
    i += 1
print(ans)
### BUGGY CODE ###

import heapq
def SME(start,end):
    count = 0
    ANS = [heapq.heappush(A,[x,i]) for i,x in enumerate(Whole)]
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.98
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    ans=10**18
    for i in range(1,n):
        x=abs(sum(l[:i])-sum(l[i:]))
        ans=min(x,ans)
    print(ans)
resolve()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    from itertools import accumulate

    N = int(input())  # len(A)
    A = list(map(int, input().split()))
    zenbu=sum(A)
    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成


    ans=10**18
    for i in range(1, N):
        ans = min(abs(B[i]-(zenbu-B[i])),ans)
    print(ans)

resolve()
### BUGGY CODE ###

N,M=map(int,input().split())
a=[]
b=[]
for i in range(0,M):
	c,d=map(int,input().split())
	a.append(c)
	b.append(d)

pos=0
i=0
e=[]
f=[]
k=0
l=0
for i in range(0,M):
	if a[i] == 1:
		e.append(b[i])
		k=k+1
	if b[i] == 1:
		e.append(a[i])
		k=k+1
	if a[i] == N:
		f.append(b[i])
		l=l+1
	if b[i] == N:
		f.append(a[i])
		l=l+1
for i in range(0,k):
	for j in range(0,l):
		if e[i]==f[j]:
			pos = 1
if pos == 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

### FIXED CODE ###

N,M=map(int,input().split())
a=[]
b=[]
for i in range(0,M):
	c,d=map(int,input().split())
	a.append(c)
	b.append(d)

pos=0
i=0
g=[0 for i in range(0,200000)]
e=[]
f=[]
k=0
l=0
while i < M and pos == 0:
	if a[i] == 1:
		g[b[i]] = 1
	if b[i] == 1:
		g[a[i]] = 1
	i=i+1
i=0
while i < M and pos == 0:
	if a[i] == N:
		if g[b[i]] == 1:
			pos=1
	if b[i] == N:
		if g[a[i]] == 1:
			pos=1
	i = i + 1
if pos == 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)
n,m=map(int,input().split())
divisors=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        divisors.append(i)
        if not i**2==m:
            divisors.append(m//i)
divisors.sort()
dp={}
def f(i,l):
    if (i,l) in dp:
        return dp[(i,l)]
    else:
        if i==n:
            if l==1:
                return 1
            else:
                return 0
        else:
            Sum=0
            for j in divisors:
                if j>l:
                    break
                else:
                    if l%j==0:
                        Sum=Sum+f(i+1,l//j)
            Sum=Sum%(10**9+7)
            dp[(i,l)]=Sum
            return Sum
print(f(0,m))


### FIXED CODE ###

n,M=map(int,input().split())
from math import factorial
i=2
c_list=[]
m=M
while not m==1:
    count=0
    while m%i==0:
        m=m//i
        count=count+1
    if not count==0:
        c_list.append(count)
    i=i+1
if M==1:
    print(1)
else:
    INF=10**9+7
    Sum=1
    for i in c_list:
        Sum=Sum*(factorial(n-1+i)//(factorial(n-1)*factorial(i)))
        Sum=Sum%INF
    print(Sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    a = list(map(int, input().split()))
    A = deque(sorted(a))
    ans = []
    S = True
    while len(A)>0:
        rem = []
        L = A.popleft()
        for i in A:
            if i == L:
                S = False
            if i%L == 0:
                rem.append(i)
        for r in rem:
            A.remove(r)
        if S:
            ans.append(L)
        S = True
    print(len(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    a = list(map(int, input().split()))
    arr = [0]*(10**6 + 1)
    for x in a:
        if arr[x] == 0:
            for i in range(x, 10**6 + 1, x):
                arr[i] += 1
        else:
            arr[x] += 1
    ans = 0
    for i in a:
        if arr[i] == 1:
            ans += 1
    print(ans)
        
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
S = []
for _ in range(n):
  s = input()
  S.append(s)
S.sort()

l = max(S.count(i) for i in S)
ans = []
for j in S:
  if S.count(j) == l:
    if j not in ans:
      ans.append(j)
      print(j)

### FIXED CODE ###

n=int(input())
d={}
a=[]
for i in range(n):
  s=input()
  if s not in d:
    d[s]=1
    a.append(s)
  else:
    d[s]+=1
m=max(d.values())
a.sort()
for i in a:
  if d[i]==m:
    print(i)
### BUGGY CODE ###

N, A, B, C, D = map(int, input().split())

B = B - A
A = 0

dp = {}
dp[1] = {}
dp[1][A] = True
for i in range(2, N + 1):
    dp[i] = {}
    for n in dp[i - 1]:
        for x in range(C, D + 1):
            dp[i][n + x] = True
            dp[i][n - x] = True

if B in dp[N]:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N, A, B, C, D = map(int, input().split())

# k : count of plus
diff = B - A

is_ok = False
for k in range(N - 1):
    min = k * C - (N - 1 - k) * D
    max = k * D - (N - 1 - k) * C
    if min <= diff and diff <= max:
        is_ok = True
        break

if is_ok:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        print(s[l[j]-1:r[j]].count('A'+'C'))




### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

t=[0]*n
for i in range(n-1):
        t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j in range(q):
        l,r=map(int,input().split())
        print(t[r-1]-t[l-1])
### BUGGY CODE ###



def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  factorial_inv_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    factorial_inv_map[i] = (factorial_inv_map[i - 1] * pow_mod(i, MOD - 2)) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]
      del factorial_inv_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= factorial_inv_map[r2 + 1]
  a %= MOD
  a *= factorial_inv_map[c2 + 1]
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= factorial_inv_map[r2 + 1]
  b %= MOD
  b *= factorial_inv_map[c1]
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= factorial_inv_map[r1]
  c %= MOD
  c *= factorial_inv_map[c2 + 1]
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= factorial_inv_map[r1]
  d %= MOD
  d *= factorial_inv_map[c1]
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()

### FIXED CODE ###



def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  a %= MOD
  a *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  b %= MOD
  b *= pow_mod(factorial_map[c1], MOD - 2)
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= pow_mod(factorial_map[r1], MOD - 2)
  c %= MOD
  c *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= pow_mod(factorial_map[r1], MOD - 2)
  d %= MOD
  d *= pow_mod(factorial_map[c1], MOD - 2)
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())
if X<Y and X<Z:
  X,Z=Z,X
  A,C=C,A
elif Y<X and Y<Z:
  Y,Z=Z,Y
  B,C=C,Y
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
k=min(K,X*Y)
AB=sorted([a+b for a in A for b in B],reverse=True)[:k]
ABC=sorted([ab+c for ab in AB for c in C],reverse=True)[:K]
for x in ABC:
  print(x)

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
ans=[]
for i in range(X):
  if i+1>K:
    break
  for j in range(Y):
    if (i+1)*(j+1)>K:
      break
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)>K:
        break
      ans.append(A[i]+B[j]+C[k])
ans=sorted(ans,reverse=True)
for a in ans[:K]:
  print(a)
### BUGGY CODE ###

from collections import Counter


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

cnt = 0
if P in [2, 5]:
    for i, s in enumerate(S):
        if int(s) % P == 0:
            cnt += (i + 1)
else:
    num = 0
    mods = Counter()
    for i, s in enumerate(reversed(S)):
        num += int(s) * (10 ** i)
        mods[num % P] += 1
    mods[0] += 1
    for i, s in enumerate(S):
        c = num % P
        cnt += mods[c] - 1
        mods[c] -= 1
        num -= int(s) * (10 ** (N - 1 - i))

print(cnt)


### FIXED CODE ###

from collections import Counter


N, P = map(int, input().split())
S = input()

cnt = 0
if P in [2, 5]:
    for i, s in enumerate(S):
        if int(s) % P == 0:
            cnt += (i + 1)
else:
    T = [0] * (N + 1)
    mods = Counter({0: 1})
    for i, s in enumerate(reversed(S)):
        T[N - 1 - i] = (T[N - i] + int(s) * pow(10, i, P)) % P
        mods[T[N - 1 - i]] += 1
    for t in T:
        mods[t] -= 1
        cnt += mods[t]

print(cnt)
### BUGGY CODE ###

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

ss = [-10**10]+[int(input()) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(input()) for _ in range(B)]+[2*10**10]
# xs = [int(input()) for _ in range(Q)]

def binarysearch(ls,x):
    n = len(ls)
    width = n//2
    pos = n//2
    while True:
        width = (width+1)//2
        if ls[pos] < x < ls[pos+1]:
            index = pos
            break    
        elif x < ls[pos]:
            pos -= width
        elif ls[pos+1] < x:
            pos += width
        pos = min(n-1,pos)
        pos = max(pos,0)
    return index

# for x in xs:
for i in range(Q):
    x = int(input())
    sind = binarysearch(ss,x)
    tind = binarysearch(ts,x)
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print(min(d1,d2,d3,d4))

### FIXED CODE ###

from bisect import bisect_right as binarysearch
A, B, Q = map(int,input().split())

ss = [-10**10]+[int(input()) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(input()) for _ in range(B)]+[2*10**10]
xs = [int(input()) for _ in range(Q)]
for x in xs:
    sind = binarysearch(ss,x)-1
    tind = binarysearch(ts,x)-1
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print(min(d1,d2,d3,d4))
### BUGGY CODE ###

n = int(input())
s = [input() for _ in range(n)]

cnt = 0

for i, item in enumerate(s):
    s[i] = ''.join(sorted(s[i]))

visited = []
for i in range(0, n):
    for j in range(i+1, n):
        if s[i] == s[j] and (i, j) not in visited:
            visited.append((i, j))
            visited.append((j, i))
            cnt += 1
print(cnt)

### FIXED CODE ###

import math
n = int(input())
s = [input() for _ in range(n)]

cnt = 0

for i, item in enumerate(s):
    s[i] = ''.join(sorted(s[i]))
s = sorted(s)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


cnt2 = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        if cnt2 == 0:
            cnt2 += 2
        else:
            cnt2 += 1
    else:
        if cnt2 != 0:
            f = combinations_count(cnt2, 2)
            cnt += f
            cnt2 = 0

if cnt2 != 0:
    f = combinations_count(cnt2, 2)
    cnt += f
    cnt2 = 0
print(cnt)
### BUGGY CODE ###

import bisect

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

for j in range(M):
    A.sort()
    B,C=map(int,input().split()) #B枚まで選んでCに書き換え
    n=bisect.bisect_left(A,C)
    if n>=B:
        for k in range(B):
            A[k]=C
    else:
        for k in range(n):
            A[k]=C
            
print(sum(A))

### FIXED CODE ###

import bisect

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

A.sort()
BC.sort(key=lambda x: x[1],reverse=True) 
ans=0
for j in range(M):
    if A[0]>=BC[j][1]:
        break
    else:
        b=BC[j][0]
        c=BC[j][1]
        R=bisect.bisect_left(A,c)
        n=len(A)
        if R>b:
            if n<=b:
                A=[]
                ans+=n*c
                break
            else:
                del A[0:b]
                ans+=b*c
        else:
            del A[0:R]
            ans+=R*c
    if len(A)==0:
        break        
print(sum(A)+ans)
### BUGGY CODE ###

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(m):
        b, c = map(int, input().split())
        a += [c for _ in range(b)]

    a = sorted(a, reverse=True)
    print(sum(a[:n]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    x = [[aa, 1] for aa in a]
    for i in range(m):
        b, c = map(int, input().split())
        x += [[c, b]]

    x = sorted(x, reverse=True)
    count = 0
    sum = 0
    for i in range(n):
        count += x[i][1]
        if count <= n:
            sum += x[i][0] * x[i][1]
        else:
            sum += x[i][0] * (x[i][1] - (count - n))
            break
    print(sum)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
x = [int(i) for i in input().split()]
x_dict = {i:j for i,j in enumerate(x)}
x.sort()
for i in range(n):
    num = x_dict[i]
    a = x.copy()
    a.remove(num)
    print(a[int(n/2)-1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
y = x.copy()
y.sort()
y_e = y[n//2]
y_o = y[n//2 - 1]
for xx in x:
    if xx >= y_e:
        print(y_o)
    else:
        print(y_e)