CodeEff/ECCO huggingface dataset:
# Original solution
from functools import reduce
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))

r = reduce(lambda x,y : x^y , A[2:],0)

a,b = A[:2]

def answer(ta,tb,tr):
    for i in range(ta):
        if (ta-i)^(tb+i) == tr:
            ans = i
            break
    else:
        ans = -1
    return ans

def solve(a,b,r):
    orga = a

    ans = 0
    l = max([len(bin(x)) for x in [a,b,r]]) - 2
    cand = {(a,b,r):0}
    for i in range(l):
        temp = defaultdict(lambda : 10**10)
        for (a,b,r),s in list(cand.items()):
            x,y,z = a%2,b%2,r%2
            if not x^y == z:
                continue
            else:
                if s < temp[(a//2,b//2,r//2)]:
                    temp[(a//2,b//2,r//2)] = s
                a -= 1
                b += 1
                if a < 0:
                    continue
                s += (1<<i)
                if s < temp[(a//2,b//2,r//2)]:
                    temp[(a//2,b//2,r//2)] = s
        cand = temp

    if not (0,0,0) in cand:
        ans = -1
    else:
        ans = cand[(0,0,0)]
        if ans == orga:
            ans = -1
    return ans

print((answer(a,b,r)))


# Optimized solution
from functools import reduce
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))

r = reduce(lambda x,y : x^y , A[2:],0)

a,b = A[:2]

def answer(ta,tb,tr):
    for i in range(ta):
        if (ta-i)^(tb+i) == tr:
            ans = i
            break
    else:
        ans = -1
    return ans

def solve(a,b,r):
    orga = a

    ans = 0
    l = max([len(bin(x)) for x in [a,b,r]]) - 2
    cand = {(a,b,r):0}
    for i in range(l):
        temp = defaultdict(lambda : 10**20)
        for (a,b,r),s in list(cand.items()):
            x,y,z = a%2,b%2,r%2
            if not x^y == z:
                continue
            else:
                if s < temp[(a//2,b//2,r//2)]:
                    temp[(a//2,b//2,r//2)] = s
                a -= 1
                b += 1
                if a < 0:
                    continue
                s += (1<<i)
                if s < temp[(a//2,b//2,r//2)]:
                    temp[(a//2,b//2,r//2)] = s
        cand = temp

    if not (0,0,0) in cand:
        ans = -1
    else:
        ans = cand[(0,0,0)]
        if ans == orga:
            ans = -1
    return ans

print((solve(a,b,r)))
# Original solution
import sys
N = int(eval(input()))
A = list(map(int,input().split()))
ALL = 0
for a in A:
    ALL ^= a

ALL ^= A[0] ^ A[1]

for i in range(A[0]):
    if ALL ^ (A[0] - i) ^ (A[1] + i) == 0:
        print(i)
        sys.exit()

print((-1))

# Optimized solution
import sys
N = int(eval(input()))
A = list(map(int,input().split()))
ALL = 0
for a in A:
    ALL ^= a

if ALL == 0:
    print((0))
    sys.exit()

ALL ^= A[0] ^ A[1]

K = A[0] + A[1]
L = []

for i in range(40, -1, -1):
    if (1 << i) & ALL:
        L.append(1)
        K -= (1 << i)
    else:
        if K >= 2 * (1 << i):
            L.append(2)
            K -= 1 << (i + 1)
        else:
            L.append(0)

if K != 0:
    print((-1))
    sys.exit()

ans = 0
for i in range(41):
    if L[i] == 2:
        ans += 1 << (40 - i)

if ans >= A[0]:
    print((-1))
    sys.exit()

for i in range(41):
    if L[i] == 1:
        if ans + (1 << (40 - i)) < A[0]:
            ans += 1 << (40 - i)

if ans == 0:
    print((-1))
    sys.exit()

print((A[0] - ans))
# Original solution
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(eval(input()))
    a = list(map(int, input().split()))

    x = 0
    for i in range(2, n):
        x ^= a[i]
    d = a[0]+a[1]-x
    if d%2 == 1 or d < 0:
        print((-1))
        return
    d >>= 1
    if d&x != 0 or d > a[0]:
        print((-1))
        return
    k = x.bit_length()
    tmp = d
    # d^tmp はd&x=0からd|tmpと一緒
    for i in range(40, -1, -1):
        if (x >> i) & 1:
            if tmp|1<<i <= a[0]:
                tmp |= 1<<i
    if 0 < tmp <= a[0]:
        print((a[0]-tmp))
    else:
        print((-1))



if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(eval(input()))
    a = list(map(int, input().split()))

    x = 0
    for i in range(2, n):
        x ^= a[i]
    d = a[0]+a[1]-x
    if d%2 == 1 or d < 0:
        print((-1))
        return
    d >>= 1
    if d&x != 0 or d > a[0]:
        print((-1))
        return
    k = x.bit_length()
    tmp = d
    # d^tmp はd&x=0からd|tmpと一緒
    for i in range(k, -1, -1):
        if (x >> i) & 1:
            if tmp|1<<i <= a[0]:
                tmp |= 1<<i
    if 0 < tmp <= a[0]:
        print((a[0]-tmp))
    else:
        print((-1))



if __name__ == '__main__':
    main()
# Original solution

def main(n,a):
    s=a[0]+a[1]
    z=0
    for ai in a[2:]:
        z^=ai
    # i+j=s,i<=a[0],i^j=z となるi,jを探す
    # i+j=i^j+2*(i & j)
    # s = z + 2*(i & j)
    # i & j = (s-z)/2 = d
    # z = 2*(i & j) - s = i ^ j
    # d = (s-z) / 2
    # z = x^y , x&y=0
    # d^x,d^yは条件を満たす。d^x+d^y=d^x^d^y + 2*((d^x)&(d^y))= z + 2*d = s
    # (d^x)^(d^y)=x^y=z
    # (d^x)&(d^y)=d (z & d = 0 のときのみ)
    if s-z<0 or (s-z)%2==1:return -1
    d=(s-z)//2
    if d&z!=0:return -1
    part=[]
    i=0
    while z//pow(2,i):
        if (z//pow(2,i))%2==1:part.append(pow(2,i))
        i+=1
    ans=float('inf')
    k=len(part)
    for i in range(2**k):
        x=0
        y=0
        for j in range(k):
            if (i>>j)&1:
                x+=part[j]
            else:
                y+=part[j]
        u=d^x
        v=d^y
        if u+v==s and u<=a[0] and u!=0:
            ans=min(ans,a[0]-u)
    return ans if ans!=float('inf') else -1





n=int(eval(input()))
a=list(map(int,input().split()))
print((main(n,a)))

# Optimized solution
def main(n,a):
    s=a[0]+a[1]
    z=0
    for ai in a[2:]:
        z^=ai
    # i+j=s,i<=a[0],i^j=z となるi,jを探す
    # i+j=i^j+2*(i & j)
    # s = z + 2*(i & j)
    # i & j = (s-z)/2 = d
    # z = 2*(i & j) - s = i ^ j
    # d = (s-z) / 2
    # z = x^y , x&y=0
    # d^x,d^yは条件を満たす。d^x+d^y=d^x^d^y + 2*((d^x)&(d^y))= z + 2*d = s
    # (d^x)^(d^y)=x^y=z
    # (d^x)&(d^y)=d (z & d = 0 のときのみ)
    if s-z<0 or (s-z)%2==1:return -1
    d=(s-z)//2
    if d&z!=0:return -1
    if not d<=a[0]:return -1
    part=[]
    i=0
    while z//pow(2,i):
        if (z//pow(2,i))%2==1:part.append(pow(2,i))
        i+=1
    ans=float('inf')
    k=len(part)
    x=0
    while part:
        tmp=part.pop()
        if d^(x+tmp)<=a[0]:
            x+=tmp
    return a[0]-(d^x) if d^x else -1


n=int(eval(input()))
a=list(map(int,input().split()))
print((main(n,a)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

a, b = A[0], A[1]
X = 0
for i in range(2, N):
    X ^= A[i]
S = a + b

M = 42
dp = [[[-1] * 2 for _ in range(2)] for _ in range(M + 1)]
dp[0][0][0] = 0
v = 1
for i in range(M):
    cs = S & 1
    cx = X & 1
    ca = a & 1
    for j in range(2):
        for k in range(2):
            if dp[i][j][k] == -1:
                continue
            for na in range(2):
                for nb in range(2):
                    # 条件②: A' ^ B' = X
                    if na ^ nb != cx:
                        continue
                    # 条件①: A' + B' = S
                    ns = na + nb + j
                    if ns & 1 != cs:
                        continue
                    
                    ni = i + 1
                    nj = 1 if ns >= 2 else 0
                    if na > ca:
                        nk = 1
                    elif na < ca:
                        nk = 0
                    else:
                        nk = k
                    
                    dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k] + na * v)
    S >>= 1
    X >>= 1
    a >>= 1
    v <<= 1

ans = dp[M][0][0]
if ans <= 0:
    print((-1))
else:
    print((A[0] - ans))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

# a = A_1, b = A_2, x = A_3 ^ ... ^ A_N, s = a + b とする
a, b = A[0], A[1]
x = 0
for i in range(2, N):
    x ^= A[i]
s = a + b

M = 42
# dp[桁][繰り上げフラグ][これまでの桁でAより大きいフラグ] := Aとなり得る値の最大値
dp = [[[-1] * 2 for _ in range(2)] for _ in range(M + 1)]
dp[0][0][0] = 0
v = 1
for i in range(M):
    cs = s & 1
    cx = x & 1
    ca = a & 1
    for j in range(2):
        for k in range(2):
            if dp[i][j][k] == -1:
                continue
            for na in range(2):
                for nb in range(2):
                    # 条件1: na ^ nb = x
                    if na ^ nb != cx:
                        continue
                    # 条件2: na + nb = S
                    ns = na + nb + j
                    if ns & 1 != cs:
                        continue
                    
                    # 遷移先のi, j, kを求める
                    ni = i + 1
                    nj = 1 if ns >= 2 else 0
                    if na > ca:
                        nk = 1
                    elif na < ca:
                        nk = 0
                    else:
                        nk = k
                    
                    # 遷移先を最大化
                    dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k] + na * v)
    s >>= 1
    x >>= 1
    a >>= 1
    v <<= 1

amax = dp[M][0][0]
if amax <= 0:
    print((-1))
else:
    print((A[0] - amax))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

A3 = 0
for i in range(2, N):
    A3 ^= A[i]

ans = -1
for i in range(A[0]):
    if (A[0] - i) ^ (A[1] + i) == A3:
        ans = i
        break
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
P = 41

X = 0
for i in range(2, N):
    X ^= A[i]

S = A[0] + A[1]
A1 = A[0]

D, M = divmod(S - X, 2)
ans = -1
if M % 2 == 0 and D & X == 0 and D <= A1:
    Y = 0
    for p in range(P, -1, -1):
        if (X >> p) & 1 == 1:
            new_Y = Y ^ (1 << p)
            if D ^ new_Y <= A1:
                Y = new_Y

    ans = A1 - (D ^ Y)
    if ans == A1:
        ans = -1

print(ans)
# Original solution
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    if N == 2:
        if A[0] == A[1]:
            print((0))
        elif A[0] < A[1]:
            print((-1))
        else:
            if (A[0] - A[1]) %2 == 0:
                print(((A[0] -  A[1])//2))
            else:
                print((-1))
        exit()

    g1 = A[0]
    g2 = A[1]
    g3 = 0
    for i in range(2, N):
        g3 ^= A[i]
    n1 = g1.bit_length()
    n2 = g2.bit_length()
    n3 = g3.bit_length()
    NN = max(n1, n2, n3)
    ans = 0
    while True:
        for i in range(NN):
            if (g1 >> i & 1) ^ (g2 >> i & 1) != (g3 >> i & 1):
                r1 = g1 % (1 << i) + 1
                r2 = (1<<i) - g2 % (1 << i)
                if r1 < r2:
                    g1 -= r1
                    g2 += r1
                    ans += r1
                    break
                elif r1 > r2:
                    g1 -= r2
                    g2 += r2
                    ans += r2
                    break
                else:
                    print((-1))
                    exit()
            if g1 ^ g2 == g3:
                if ans != A[0]:
                    print(ans)
                else:
                    print((-1))
                exit()


if __name__ == '__main__':
    main()


# Optimized solution
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    if N == 2:
        if A[0] == A[1]:
            print((0))
        elif A[0] < A[1]:
            print((-1))
        else:
            if (A[0] - A[1]) %2 == 0:
                print(((A[0] -  A[1])//2))
            else:
                print((-1))
        exit()

    g1 = A[0]
    g2 = A[1]
    g3 = 0
    for i in range(2, N):
        g3 ^= A[i]
    n1 = g1.bit_length()
    n2 = g2.bit_length()
    n3 = g3.bit_length()
    NN = max(n1, n2, n3)
    ans = 0
    cnt = 0
    while True:
        cnt += 1
        if cnt == 10000:
            print((-1))
            exit()
        for i in range(NN):
            if (g1 >> i & 1) ^ (g2 >> i & 1) != (g3 >> i & 1):
                r1 = g1 % (1 << i) + 1
                r2 = (1<<i) - g2 % (1 << i)
                if r1 < r2:
                    g1 -= r1
                    g2 += r1
                    ans += r1
                    break
                elif r1 > r2:
                    g1 -= r2
                    g2 += r2
                    ans += r2
                    break
                else:
                    print((-1))
                    exit()
            if g1 ^ g2 == g3:
                if ans != A[0]:
                    print(ans)
                else:
                    print((-1))
                exit()


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

xor = 0
for a in A[2:]:
    xor ^= a

n = A[0] + A[1] - xor
if n < 0 or n%2:
    print((-1))
    quit()

n //= 2
a = b = 0
digit = [1]
d = []
count = 0    
while n or xor:
    n0 = n & 1; xor0 = xor & 1
    if n0:
        if xor0:
            print((-1))
            quit()
        else:
            a += digit[-1]
            b += digit[-1]
    else:
        if xor0:
            b += digit[-1]
            d.append(count)

    digit.append(digit[-1] * 2)
    count += 1
    n >>= 1; xor >>= 1

if a > A[0]:
    print((-1))
    quit()

while d:
    c = d.pop()
    if a + digit[c] <= A[0]:
        a += digit[c]; b -= digit[c]

if a:
    print((A[0] - a))
else:
    print((-1))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

xor = 0
for a in A[2:]:
    xor ^= a

n = A[0] + A[1] - xor
if n < 0 or n%2:
    print((-1))
    quit()

n //= 2
a = b = 0
digit = 1
d = []
while n or xor:
    n0 = n & 1; xor0 = xor & 1
    if n0:
        if xor0:
            print((-1))
            quit()
        else:
            a += digit
            b += digit
    else:
        if xor0:
            b += digit
            d.append(digit)

    digit *= 2
    n >>= 1; xor >>= 1

if a > A[0]:
    print((-1))
    quit()

while d:
    dd = d.pop()
    if a + dd <= A[0]:
        a += dd; b -= dd

if a:
    print((A[0] - a))
else:
    print((-1))
# Original solution
from functools import lru_cache
N, = list(map(int, input().split()))
X = list(map(int, input().split()))
t = 0
for x in X:
    t = t^x
inf = float('inf')
@lru_cache(None)
def it(x, y, z):
    xm, ym, zm = x%2, y%2, z%2
    if xm ^ ym != zm:
        return inf
    if x^y == z:
        return 0
    Rz = 2*it(x>>1, y>>1, z>>1)
    Ro = inf
    if x:
        Ro = 2*it((x-1)>>1, (y+1)>>1, z>>1)+1
    Rz = min(Rz, Ro)
    return Rz

r = it(X[0], X[1], t^X[0]^X[1])
if 0 <= r < X[0]:
    print(r)
else:
    print((-1))


# Optimized solution
import sys
N, = list(map(int, input().split()))
X = list(map(int, input().split()))
S = X[0]+X[1]
T = 0
for i in range(2, N):
    T ^= X[i]
if S<T or (S-T)%2:
    print((-1))
    sys.exit()
D = (S-T)//2
if D&T:
    print((-1))
    sys.exit()
M = T.bit_length()+1
if D > X[0]:
    print((-1))
    sys.exit()
Y = 0
for i in range(M, -1, -1):
    if T & (1<<i) and ((1<<i)|Y)^D <= X[0]:
        Y = (1<<i)|Y
if Y^D == 0:
    print((-1))
else:
    print((X[0]-(Y^D)))
# Original solution
import sys
N, = list(map(int, input().split()))
X = list(map(int, input().split()))
S = X[0]+X[1]
T = 0
for i in range(2, N):
    T ^= X[i]
if S<T or (S-T)%2:
    print((-1))
    sys.exit()

D = (S-T)//2
if D&T:
    print((-1))
    sys.exit()

Y = D
for i in range(T.bit_length()+1, -1, -1):
    if T&(1<<i)|Y <= X[0]:
        Y |= T&(1<<i)
if 0<Y<=X[0]:
    print((X[0]-Y))
else:
    print((-1))


# Optimized solution
import sys
N, = list(map(int, input().split()))
X = list(map(int, input().split()))
S = X[0]+X[1]
T = 0
for i in range(2, N):
    T ^= X[i]
D = (S-T)//2
if S<T or (S-T)%2 or T&D:
    print((-1))
    sys.exit()
for i in range(T.bit_length()+1, -1, -1):
    if T&(1<<i)|D <= X[0]:
        D |= T&(1<<i)
if 0<D<=X[0]:
    print((X[0]-D))
else:
    print((-1))
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))


for i in range(N):
    a = X[:i] + X[i+1:]
    med = sorted(a)[(N//2)-1]
    print(med)

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))

SORTED = sorted(X)
med1 = SORTED[N//2 - 1]
med2 = SORTED[N//2]
# print(med1, med2)

for xi in X:
    if xi <= med1:
        print(med2)
    else:
        print(med1)
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
d = dict(list(zip(list(range(0,n)), x)))
x.sort()
for i in range(0, n):
    if d[i] in x[0:n//2] :
        print((x[n//2]))
    else :
        print((x[n//2-1]))

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
d = dict(list(zip(list(range(0,n)), x)))
x.sort()
for i in range(0, n):
    if d[i] <= x[n//2-1] :
        print((x[n//2]))
    else :
        print((x[n//2-1]))
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()

for i in X:
    if Y.index(i) >= N//2:
        print((Y[N//2-1]))
    if Y.index(i) <= N//2 - 1:
        print((Y[N//2]))

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()

l = Y[N//2-1]
r= Y[N//2]

for i in X:
    if i <= l:
        print(r)
    else:
        print(l)
# Original solution
import copy
N=int(eval(input()))
X=list(map(int,input().split()))
Y=copy.deepcopy(X)

Z=N//2
for i in range(N):
    
    Y.pop(i)

    Y.sort()
    
    print((Y[Z-1]))
    Y=copy.deepcopy(X)
    

# Optimized solution
import copy
N=int(eval(input()))
X=list(map(int,input().split()))
Y=copy.deepcopy(X)
Y.sort()
kiteichiA=Y[N//2-1]
kiteichiB=Y[N//2]
for i in range(N):
    if X[i]>=kiteichiB:
        print(kiteichiA)
    elif X[i]<=kiteichiA:
        print(kiteichiB)
# Original solution
n=int(eval(input()))
x=list(map(int,input().split()))
d=sorted(x)
b1=d[len(x)//2-1]
b2=d[len(x)//2]
for i in x:
  if i<=b1:
    print(b2)
  elif i>=b2:
    print(b1)



# Optimized solution
n=int(eval(input()))
x=list(map(int,input().split()))
ans=sorted(x)
ans2=ans[n//2-1]
ans1=ans[n//2]

for i in range(n):
  if x[i]>=ans[n//2]:
    print(ans2)
  else:
    print(ans1)
# Original solution
import statistics
n = int(eval(input()))
x = list(map(int,input().split()))

for i in range(n):
  xx = x[:i] + x[i+1:]
  print((statistics.median(xx)))
  

# Optimized solution
import statistics
n = int(eval(input()))
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] == median_right:
    print(median_left)
  elif x[i] == median_left:
    print(median_right)
  else:
    if x[i] < median_left:
      print(median_right)
    else:
      print(median_left)
# Original solution
import statistics
n = int(eval(input()))
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] == median_right:
    print(median_left)
  elif x[i] == median_left:
    print(median_right)
  else:
    if x[i] < median_left:
      print(median_right)
    else:
      print(median_left)
  

# Optimized solution
import statistics
n = int(eval(input()))
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] >= median_right:
    print(median_left)
  else:
    print(median_right)
# Original solution
import statistics
n = int(eval(input()))
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] >= median_right:
    print(median_left)
  else:
    print(median_right)

  

# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, X: "List[int]"):
    Y = sorted(X)
    me1 = Y[N//2]
    me2 = Y[N//2-1]

    for i in range(N):
        if X[i]<=me2:
            print(me1)
        elif X[i]>=me1:
            print(me2)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
x_l = list(map(int,input().split()))
s_x_l = [ (i, j) for i,j in enumerate(x_l) ]
s_x_l = sorted(s_x_l, key=lambda x: x[1])
size = len(s_x_l)
med_idx = int((size-1+1)/2)-1

ans = []
for i in range(n):
    left = s_x_l[:i]
    right = s_x_l[i+1:]
    idx = s_x_l[i][0]
    merge = left+right
    med = merge[med_idx][1]
    ans.append([idx, med])

ans = sorted(ans, key=lambda x:x[0])
for i in ans:
    print((i[1]))

# Optimized solution
n = int(eval(input()))
x_l = list(map(int,input().split()))
s_x_l = sorted(x_l)

med_idx = n//2
med_l = s_x_l[med_idx-1]
med_r = s_x_l[med_idx]

for i in range(n):
    if  x_l[i] <= med_l:
        print(med_r)
    else:
        print(med_l)
# Original solution
n = int(eval(input()))
x = input().split()
for i in range(n):
    x[i] = int(x[i])

for i in range(n):
    xm = x[:i] + x[i+1:]
    xm = sorted(xm)
    print((xm[int(n/2)-1]))

# Optimized solution
n = int(eval(input()))
x = input().split()
for i in range(n):
    x[i] = int(x[i])
xs = sorted(x)
ml = xs[n//2-1]
mr = xs[n//2]

for i in range(n):
    if x[i] <= ml:
        print(mr)
    elif x[i] >= mr:
        print(ml)
# Original solution
import bisect
N = int(input())
X = [int(i) for i in input().split()]
ans = []
for i in range(N):
    num = X.pop(i)
    a = X[:]
    a.sort()
    ans.append(a[(N-1)//2])
    X.insert(i, num)
print(*ans, sep='\n')


# Optimized solution
N = int(eval(input()))
X = [int(i) for i in input().split()]
a = X[:]
a.sort()
l = a[N//2-1]
r = a[N//2]
if l == r:
    for i in range(N):
        print(l)
else:
    for i in range(N):
        if X[i] <= l:
            print(r)
        elif X[i] >= r:
            print(l)
# Original solution
n=int(eval(input()))
p=n//2
l=list(map(int,input().split()))
for i in range(n):
    m=l[:i]+l[i+1:]
    m.sort()
    print((m[p-1]))

# Optimized solution
n=int(eval(input()))
x=list(map(int,input().split()))
l=sorted(x)
m1=l[n//2-1]
m2=l[n//2]
for i in range(n):
    if x[i]<=m1:
        print(m2)
    else:
        print(m1)
# Original solution
n = int(eval(input()))
ary = list(map(int,input().split()))
a = sorted(ary)
c = (len(ary)+1)//2-1
for i in range(n):
    b = a.copy()
    b.remove(ary[i])
    print((b[c]))

# Optimized solution
n = int(eval(input()))
ary = list(map(int,input().split()))
a = sorted(ary)
b = (len(ary)+1)//2-1
for i in range(n):
    if a[b] < ary[i]:
        print((a[b]))
    elif a[b] == ary[i]:
        print((a[b+1]))
    elif a[b] > ary[i]:
        print((a[b+1]))
# Original solution
n = int(eval(input()))
ary = list(map(int,input().split()))
a = sorted(ary)
b = (len(ary)+1)//2-1
for i in range(n):
    if a[b] < ary[i]:
        print((a[b]))
    elif a[b] == ary[i]:
        print((a[b+1]))
    elif a[b] > ary[i]:
        print((a[b+1]))

# Optimized solution
n = int(eval(input()))
ary = list(map(int,input().split()))
a = sorted(ary)
b = (len(ary)+1)//2-1
for i in range(n):
    if a[b] < ary[i]:
        print((a[b]))
    elif a[b] >= ary[i]:
        print((a[b+1]))
# Original solution
n = int(eval(input()))
ary = list(map(int,input().split()))
a = sorted(ary)
b = (len(ary)+1)//2-1
for i in range(n):
    if a[b] < ary[i]:
        print((a[b]))
    elif a[b] >= ary[i]:
        print((a[b+1]))

# Optimized solution
n = int(eval(input()))
ary = list(map(int,input().split()))
ary_sort = sorted(ary)
a = len(ary)//2-1
for i in range(n):
    if ary_sort[a] < ary[i]:
        print((ary_sort[a]))
    elif ary_sort[a] >= ary[i]:
        print((ary_sort[a+1]))