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

S = input()
N = len(S)
K = int(input())

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    if len(aset)-1 >= K-c:
        break
    c += len(aset)-1


for _ in range(10):
    for i, a in enumerate(aset):
        if i == 0:
            min = a
            continue
        if a < min:
            min = a
    aset.discard(min)
    if min == '':
        continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)


### FIXED CODE ###

def main():
    S = input()
    N = len(S)
    K = int(input())

    S1 = {}
    for i, s in enumerate(S):
        if not s in S1.keys():
            S1[s] = [i]
        else:
            S1[s].append(i)
    alp = sorted(list(S1.keys()))

    c = 0
    for a in alp:
        aset = set()
        inds = S1[a]
        for d in inds:
            up = min(N-d+1, K+1)
            for i in range(up):
                aset.add(S[d:d+i])
        L = len(aset)-1
        if L >= K-c:
            break
        c += L

    for _ in range(10):
        M = '何だこれはもうやめてくれよ'
        for a in aset:
            if a < M:
                M = a
        aset.discard(M)
        if M == '':
            continue
        c += 1
        if c >= K:
            ans = M
            break

    print(ans)



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

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

pre_n = n
while pre_n >= n:
  pre_n = n
  n = abs(n-k)
  
print(pre_n)

### FIXED CODE ###

n,k = map(int, input().split())
print(min(n%k, abs(n%k-k)))
### BUGGY CODE ###

import sys
input=sys.stdin.readline

a,b,c = map(int, input().split())
hp = 2
ans = 0
while True:
    if a == 0 and b == 0 and c == 0:
        break
    if hp == 1 and a == 0 and b == 0:
        break
    if hp > 1 and c > 0:
        ans += 1
        c -= 1
        hp -= 1
    if hp < 2 or c == 0:
        if a > 0:
            a -= 1
            hp = max(2, hp+1)
        elif b > 0:
            b -= 1
            hp = max(2, hp+1)
            ans += 1

print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.readline

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

if a >= c-1 or b >= c-1 or a+b >= c-1:
    print(b+c)
else:
    print(b+(a+b)+1)
### BUGGY CODE ###

import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def fast_pow(num, kata, mod):
    if kata == 0:
        return 1

    res = 1
    while kata > 0:
        if kata & 1 == 1:
            res = res * num % mod
        num = num * num % mod

        kata >>= 1
    return res


def choose(n, r, MOD):
    res = 1
    fac = 1
    for i in range(r):
        res *= n - i
        res %= MOD
        fac *= i + 1
        fac %= MOD
    return res * fast_pow(fac, MOD - 2, MOD) % MOD


def main():
    k = ni()
    s = input()
    l = len(s)

    ans = 0
    for ki in range(k + 1):
        tmpa = fast_pow(25, k - ki, MOD)
        tmpb = fast_pow(26, ki, MOD)
        tmpc = choose(k - ki + l - 1, l - 1, MOD)
        tmpd = (tmpa * tmpb * tmpc) % MOD
        ans += tmpd
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def fast_pow(num, kata, mod):
    if kata == 0:
        return 1

    res = 1
    while kata > 0:
        if kata & 1 == 1:
            res = res * num % mod
        num = num * num % mod

        kata >>= 1
    return res


def choose(n, r, MOD):
    res = 1
    fac = 1
    for i in range(r):
        res *= n - i
        res %= MOD
        fac *= i + 1
        fac %= MOD
    return res * fast_pow(fac, MOD - 2, MOD) % MOD


# nCrの左項にはn以外も来るバージョン、1!～(n-1)!を保持
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def main():
    k = ni()
    s = input()
    l = len(s)

    # 使い方
    facts, invs = prepare(k + l, MOD)

    ans = 0
    for ki in range(k + 1):
        tmpa = fast_pow(25, k - ki, MOD)
        tmpb = fast_pow(26, ki, MOD)
        tmpc = facts[k - ki + l - 1] * invs[l - 1] * invs[k - ki + l - 1 - (l - 1)] % MOD
        tmpd = (tmpa * tmpb * tmpc) % MOD
        ans += tmpd
        ans %= MOD
    print(ans)


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

n=int(input())
a = list(map(int, input().split()))
memo = {2:0}
x = []
for y in a:
    i = y
    xx = {}
    c = 0
    while i%2==0:
        c += 1
        i //= 2
    memo[2] = max(memo[2], c)
    xx[2]=c
    for j in range(3, int(i**.5)+2, 2):
        if i%j==0:
            c=0
            while i%j==0:
                c += 1
                i //= j
            if j in memo:
                memo[j] = max(memo[j], c)
            else:
                memo[j] = c
            xx[j] = c
    if i!=1:
        xx[i]=1
        if i in memo:
            memo[i] = max(memo[i], 1)
        else:
            memo[i] = 1
    x.append(xx)
mod = 10**9+7
result = 0
for i in range(n):
    num = 1
    for s, t in memo.items():
        if s in x[i]:
            num *= pow(s, t-x[i][s])
        else:
            num *= pow(s,t)
    if result+num >= mod:
        result = (result+num)%mod
    else:
        result += num
print(result)

### FIXED CODE ###

from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7
memo = defaultdict(int)
base = 0
for i in a:
    base = (base+pow(i, mod-2, mod))%mod
    num = i
    for j in range(2, int(i**.5)+1):
        if num%j==0:
            c = 0
            while num%j==0:
                num //= j
                c += 1
            memo[j] = max(memo[j], c)
    if num != 1:
        memo[num] = max(memo[num], 1)
k = 1
for s, t in memo.items():
    k = (k*pow(s, t, mod))%mod

print((k*base)%mod)
### BUGGY CODE ###

import collections, itertools, sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    xy = [LI() for _ in range(N)]

    # x, y全ての重複あり組み合わせに対して含まれる点の個数を算出する

    x_cnt = collections.Counter([i[0] for i in xy])
    x_coordinate = np.array(list((x_cnt.keys())))
    x_coordinate.sort()
    # len_x_c = len(x_coordinate)
    y_cnt = collections.Counter([i[1] for i in xy])
    y_coordinate = np.array(list(y_cnt.keys()))
    y_coordinate.sort()
    len_y_c = len(y_coordinate)

    ans = INF
    for xl, xh in itertools.combinations(x_coordinate, 2):
        # 4番目の辺の探索は、個数条件を満たしたら終了していよい
        for i in range(len_y_c - 1):
            yl = y_coordinate[i]
            for j in range(i + 1, len_y_c):
                yh = y_coordinate[j]
                cnt = len([(i, j) for i, j in xy if xl <= i <= xh and yl <= j <= yh])
                if cnt >= K:
                    ans = min((xh - xl) * (yh - yl), ans)
                    break

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import collections, itertools, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    xy = [LI() for _ in range(N)]

    # x, y全ての重複あり組み合わせに対して含まれる点の個数を算出する

    x_cnt = collections.Counter([i[0] for i in xy])
    x_coordinate = list(x_cnt.keys())
    x_coordinate.sort()
    # len_x_c = len(x_coordinate)
    y_cnt = collections.Counter([i[1] for i in xy])
    y_coordinate = list(y_cnt.keys())
    y_coordinate.sort()
    len_y_c = len(y_coordinate)

    ans = INF
    for xl, xh in itertools.combinations(x_coordinate, 2):
        # 4番目の辺の探索は、個数条件を満たしたら終了していよい
        for i in range(len_y_c - 1):
            yl = y_coordinate[i]
            for j in range(i + 1, len_y_c):
                yh = y_coordinate[j]
                cnt = len([(i, j) for i, j in xy if xl <= i <= xh and yl <= j <= yh])
                if cnt >= K:
                    ans = min((xh - xl) * (yh - yl), ans)
                    break

    print(ans)

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

import heapq
from collections import defaultdict
def gijkstra(n,E,key=1,s=1):
    d = [float('inf')]*(n+1)
    p = [-1]*(n+1)
    hq = [(0,s)]
    d[s] = 0
    while hq:
        u = heapq.heappop(hq)[1]
        for e in E[u]:
            c, v = d[u] + e[key], e[0]
            if d[v] > c:
                d[v] = c
                p[v] = u
                heapq.heappush(hq,(c,v))
    return d, p

n, m, s, t =  map(int,input().split())
E = defaultdict(set)

for i in range(m):
    u,v,a,b = tuple(map(int,input().split()))
    E[u].add((v,a,b))
    E[v].add((u,a,b))
d1, _ = gijkstra(n,E,key=1,s=s)
d2, _ = gijkstra(n,E,key=2,s=t)
d = [10**15 - d1[-1] -d2[-1]]
for i in range(n-1,0,-1):
    d = [max(d[0], 10**15 - d1[i] -d2[i])] + d
[print(c) for c in d]

### FIXED CODE ###

import heapq
from collections import defaultdict
def gijkstra(n,E,s=1):
    d = [float('inf')]*(n+1)
    p = [-1]*(n+1)
    hq = [(0,s)]
    d[s] = 0
    while hq:
        u = heapq.heappop(hq)[1]
        for v, c in E[u]:
            if d[v] > d[u] + c:
                d[v], p[v] = d[u]+c, u
                heapq.heappush(hq, (d[u]+c, v))
    return d, p

n, m, s, t =  map(int,input().split())
E1 = defaultdict(set)
E2 = defaultdict(set)

for i in range(m):
    u,v,a,b = tuple(map(int,input().split()))
    E1[u].add((v,a))
    E1[v].add((u,a))
    E2[u].add((v,b))
    E2[v].add((u,b))
d1, _ = gijkstra(n,E1,s=s)
d2, _ = gijkstra(n,E2,s=t)
d = [d1[-1] + d2[-1],]
for i in range(n-1,0,-1):
    d.append(min(d[-1],d1[i]+d2[i]))
[print(10**15-c) for c in reversed(d)]
### BUGGY CODE ###

def resolve():
    H, W, M = list(map(int, input().split()))
    HW = [list(map(int, input().split())) for _ in range(M)]
    rowsum = [0 for _ in range(H)]
    colsum = [0 for _ in range(W)]
    for h, w in HW:
        rowsum[h-1] += 1
        colsum[w-1] += 1
    rmax = 0
    ridx = []
    for i, r in enumerate(rowsum):
        if rmax < r:
            rmax = r
            ridx = [i]
        elif rmax == r:
            ridx.append(i)
    cmax = 0
    cidx = []
    for j, c in enumerate(colsum):
        if cmax < c:
            cmax = c
            cidx = [j]
        elif cmax == c:
            cidx.append(j)
    
    import itertools
    cnt = 0
    for h, w in HW:
        if h-1 in ridx and w-1 in cidx:
            cnt += 1
    
    print(rmax + cmax if cnt < len(cidx)*len(ridx) else rmax + cmax - 1)

    
    


if '__main__' == __name__:
    resolve()



### FIXED CODE ###

def resolve():
    H, W, M = list(map(int, input().split()))
    HW = [list(map(int, input().split())) for _ in range(M)]
    rowsum = [0 for _ in range(H)]
    colsum = [0 for _ in range(W)]
    for h, w in HW:
        rowsum[h-1] += 1
        colsum[w-1] += 1
    rmax = 0
    ridx = []
    for i, r in enumerate(rowsum):
        if rmax < r:
            rmax = r
            ridx = [i]
        elif rmax == r:
            ridx.append(i)
    maxr = [False for _ in range(H)]
    for i in ridx:
        maxr[i] = True
    
    cmax = 0
    cidx = []
    for j, c in enumerate(colsum):
        if cmax < c:
            cmax = c
            cidx = [j]
        elif cmax == c:
            cidx.append(j)
    maxc = [False for _ in range(W)]
    for i in cidx:
        maxc[i] = True
    
    cnt = 0
    for h, w in HW:
        if maxr[h-1] and maxc[w-1]:
            cnt += 1
    
    print(rmax + cmax if cnt < len(cidx)*len(ridx) else rmax + cmax - 1)

    
    


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

N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
  L = [dp[j] +abs(h[i] - h[j]) for j in range(max(0,i-K),i)]
  dp[i] = min(L)
print(dp[N-1])

### FIXED CODE ###

N,K = map(int,input().split())
H = [int(x) for x in input().split()]
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)
### BUGGY CODE ###

from scipy.misc import comb

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

mod = 10 ** 9 + 7
ans = 0
for d in range(1, N):
    ans += d * (N - d) * M**2
for d in range(1, M):
    ans += d * (M - d) * N**2
print(ans * comb(N * M - 2, K - 2, exact=True) % mod)


### FIXED CODE ###

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

mod = 10 ** 9 + 7


class comb(object):
    def __init__(self, N, mod):
        self.mod = mod
        self.fac = [1] * N
        for i in range(1, N):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.inv = [1] * N
        self.inv[N - 1] = pow(self.fac[N - 1], mod - 2, mod)
        for i in range(N - 1, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % mod

    def calc(self, n, k):
        return self.fac[n] * (self.inv[k] * self.inv[n - k] %
                              self.mod) % self.mod


ans = 0
for d in range(1, N):
    ans += d * (N - d) * M**2
for d in range(1, M):
    ans += d * (M - d) * N**2
ans *= comb(N * M, mod).calc(N * M - 2, K - 2)
print(ans % mod)
### BUGGY CODE ###

import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==30:
        break
print('Yes')

### FIXED CODE ###

import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')
### BUGGY CODE ###

import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

val = (n-1) // 2

arr = list(map(int, arr_data[1]))


for i in range(0, len(arr)):
    
    arr01=sorted(arr[:i]+arr[i+1:])
    
    print(arr01[val])
    

### FIXED CODE ###

import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

val = (n-1) // 2

arr = list(map(int, arr_data[1]))

arr_sort = sorted(arr)

val1 = arr_sort[(n // 2)-1]
val2 = arr_sort[(n // 2)]

for v in arr:
    
    if v<=val1:
        
        print(val2)
        
    else:
        
        print(val1)
### BUGGY CODE ###

s = input()
q = int(input())
for i in range(q):
    query = input()
    if query[0] == "1":
        s = s[::-1]
    else:
        t, f, c = query.split()
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

### FIXED CODE ###

s = input()
q = int(input())

L = ["" for i in range(q)]
R = ["" for i in range(q)]
l, r = 0, 0

fliped = False
for i in range(q):
    query = input()
    if query[0] == "1":
        fliped = not fliped
    else:
        t, f, c = query.split()
        if (f == "1") ^ fliped:
            L[l] = c
            l += 1
        else:
            R[r] = c
            r += 1
s = "".join(L[::-1]) + s + "".join(R)
if fliped:
    s = s[::-1]
print(s)
### BUGGY CODE ###

n = int(input())
a = [ int(x) for x in input().split() ]

l = []
for e in a:
    l.append(e)
    l.reverse()

print(' '.join(map(str, l)))


### FIXED CODE ###

n = int(input())
a = [ int(x) for x in input().split() ]

l = []
if n % 2 == 1:
    i = n-1
    while i >= 0:
        l.append(a[i])
        i -= 2

    j = 1
    while j < n:
        l.append(a[j])
        j += 2
else:
    i = n-1
    while i >= 0:
        l.append(a[i])
        i -= 2

    j = 0
    while j < n:
        l.append(a[j])
        j += 2

print(' '.join(map(str, l)))
### BUGGY CODE ###

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [float('inf') for _ in range(H+1)]

for i, ab in enumerate(AB):
    a, b = ab
    for j in range(H // AB[i][0] + 2):
        dp[min(AB[i][0] * j, H)] = min(dp[min(AB[i][0] * j, H)], AB[i][1] * j)
        j += 1

for h in range(H):
    for n in range(N):
        for j in range((H - h) // AB[n][0] + 2):
            dp[min(h + AB[n][0] * j, H)] = min(dp[min(h + AB[n][0] * j, H)], dp[h] + AB[n][1] * j)
print(dp[-1])

### FIXED CODE ###

import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [0 for _ in range(H + max(AB, key=lambda x: x[0])[0])]
for h in range(1, len(dp)):
    dp[h] = min(dp[h-a] + b for a, b in AB)

print(dp[H])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
    print(A.count(i))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
    A.append(i)
ans = collections.Counter(A)
tmp = sorted(ans.items())
for i in range(N):
    print(tmp[i][1]-1)
### BUGGY CODE ###

n,a,b = map(int,input().split())
mod = 10**9+7

from math import factorial
cmb_a = factorial(n) / factorial(a) / factorial(n-a)
cmb_b = factorial(n) / factorial(b) / factorial(n-b)

print(int((2**n - 1 - cmb_a - cmb_b) % mod))

### FIXED CODE ###

def cmb(n, r):
	if n - r < r:
		r = n - r
	if r == 0:
		return 1
	if r == 1:
		return n
	
	num = [n - r + k + 1 for k in range(r)] #numerator(分子)
	den = [k + 1 for k in range(r)] #denominator(分母)
	
	for p in range(2, r + 1):
		pivot = den[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p - 1, r, p):
				num[k - offset] /= pivot
				den[k] /= pivot
	
	result = 1
	for k in range(r):
		if num[k] > 1:
			result *= int(num[k])
			result = result % mod
	
	return result

n,a,b = map(int,input().split())
mod = 10**9+7

print((pow(2,n,mod) - 1 - cmb(n,a) - cmb(n,b)) % mod)
### BUGGY CODE ###

from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())
sj = deepcopy(s) 

c = 0
for i in s:
    sj.pop(0)
    sk = deepcopy(sj)
    if len(sk) <= 0:
        break
    cj = 0
    for j in sj:
        cj += 1
        sk.pop(0)
        if len(sk) <= 0:
            break
        if i != j:
            ck = 0
            for k in sk:
                ck += 1
                if i!=k and j!=k and cj != ck:
                    c += 1

print(c)

### FIXED CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 1
for i in range(1,p.index(min(p))+1):
    if p[i] == min(p[:i+1]):
        count += 1
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
t = p[0]
for i in range(n):
    if p[i] <= t:
        count += 1
        t = p[i]
print(count)
### BUGGY CODE ###

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

x = sorted(X)
for v in X:
	i = x.index(v)
	x.pop(i)
	print(x[(N - 1) // 2])
	x.insert(i, v)


### FIXED CODE ###

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

c = N // 2
x = sorted(X)
for v in X:
	if v < x[c]:
		print(x[c])
	else:
		print(x[c - 1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = []
for _ in range(Q):
    b, c = map(int, input().split())
    if b in A:
        for n in range(N):
            if A[n] == b:
                A[n] = c
    print(sum(A))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
Q = int(input())
ans = []
s = sum(A)
for _ in range(Q):
    b, c = map(int, input().split())
    n = cnt[b]
    if b in cnt:
        cnt[c] += cnt[b]
        del cnt[b]
    s += (c-b)*n
    print(s)
### BUGGY CODE ###

x = list(map(int,input().split()))
a = 0
b = x[1]+1
for i in range(x[0],x[1]+1):
    if i % x[2] ==0:
        a = 1
        b=i+x[2]
        break
while x[1]>=b:   
    b += x[2]
    a=a+1
print(a)

### FIXED CODE ###

x = list(map(int,input().split()))
a = 0
if x[0]%x[2]==0:
    b = x[0]
else:
     b = ((x[0] // x[2])+1)*x[2]
c = (x[1]-b)//x[2] + 1

print(c)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n,q=map(int,input().split())
ki=[[] for _ in range(n)]
ans=[0]*n

def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)

for i in range(n-1):
    a,b=map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)

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

dfs(0,-1)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n,q=map(int,input().split())
ki=[[] for _ in range(n)]
ans=[0]*n

def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)

for i in range(n-1):
    a,b=map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)

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

dfs(0,-1)
print(*ans)