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

def main():
    n=int(input())
    s=input()

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()


### FIXED CODE ###

import sys

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

    n=int(input())
    s=list(map(int,input()))
    # s.pop(-1)
    cnt=0
    for i in range(10):
        if i in s[:-2]:
            idx1=s[:-2].index(i)
            for j in range(10):
                if j in s[idx1+1:-1]:
                    idx2=s[idx1+1:-1].index(j)+idx1+1
                    for k in range(10):
                        if k in s[idx2+1:]:
                            cnt+=1
    print(cnt)

    #
    # tmp=[0,0,0]
    # cnt=0
    # for i in range(0,1000):
    #     if i < 10:
    #         tmp[0]=0
    #         tmp[1]=0
    #         tmp[2]=i
    #     elif i < 100:
    #         tmp[0]=0
    #         tmp[1]=i//10
    #         tmp[2]=i-tmp[1]*10
    #     else:
    #         tmp[0]=i//100
    #         tmp[1]=(i-tmp[0]*100)//10
    #         tmp[2]=i-tmp[0]*100-tmp[1]*10
    #     ketaflg=0
    #     for j in s :
    #         if j == '\n':
    #             break
    #         if tmp[0]==int(j) and ketaflg==0:
    #             ketaflg=1
    #         elif tmp[1]==int(j) and ketaflg==1:
    #             ketaflg=2
    #         elif tmp[2]==int(j) and ketaflg==2:
    #             ketaflg=3
    #             cnt+=1
    #             break
    # print(cnt)


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

import copy

T = int(input())

for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input().rstrip()

    if S[-1] == '1':
        print('1')

    win = set()
    win.add(0)
    for j in range(len(S)-1, -1, -1):
        tmp = copy.copy(win)
        if S[j] == '0':
            for v in win:
                tmp.add(v ^ A[j])
        else:
            for v in win:
                if v ^ A[j] not in win:
                    tmp.remove(v)

        win = tmp

    if 0 in win:
        print('0')
    else:
        print('1')


### FIXED CODE ###

T = int(input())

for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input().rstrip()

    win = set()
    win.add(0)
    for j in range(len(S)-1, -1, -1):
        base = A[j]
        for v in win:
            base = min(base, base ^ v)

        if S[j] == '0':
            win.add(base)
        else:
            if base:
                print('1')
                break
    else:
        print('0')
### BUGGY CODE ###

s = str(input())
K = int(input())
S = set()
anslength = 1
while len(s) >= anslength:
    for i in range(0,len(s)-anslength+1):
        S.add(s[i:i+anslength])
    anslength+=1
LS = list(S)
LS.sort()
print(LS[K-1])


### FIXED CODE ###

s = str(input())
K = int(input())
S = set()
anslength = K
while 0 < anslength:
    for i in range(0,len(s)-anslength+1):
        S.add(s[i:i+anslength])
    anslength-=1
LS = list(S)
LS.sort()
print(LS[K-1])
### BUGGY CODE ###

import bisect

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return [1,i]
    return [0,0]


N=int(raw_input())
D=sorted(map(int, raw_input().split()))
M=int(raw_input())
T=sorted(map(int, raw_input().split()))

ans=["NO","YES"]
a=1

for t in T:
    [a,i]=index(D,t)
    if a==0: break
    D.pop(i)
print ans[a]


### FIXED CODE ###

#import bisect

#def index(a, x):
#    'Locate the leftmost value exactly equal to x'
#    i = bisect.bisect_left(a, x)
#    if i != len(a) and a[i] == x:
#        return [1,i]
#    return [0,0]


N=int(raw_input())
D=sorted(map(int, raw_input().split()))
M=int(raw_input())
T=sorted(map(int, raw_input().split()))

DD={}
for d in D:
    if d not in DD:
        DD[d] = 1
    else:
        DD[d]+=1

ans=["NO","YES"]
a=1

for t in T:
    try:
        if DD[t]>0:
            DD[t]-=1
        else:
            a=0
            break
    except:
        a=0
        break
print ans[a]
### BUGGY CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * 2**i % MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * pow(2, i, MOD)
    print(ans % MOD)


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

def resolve():
    '''
    code here
    '''
    import collections

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    fp = [[10**6 for _ in range(W)] for _ in range(H)]

    que = collections.deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0
    next_y_x = [[0, 1], [1, 0], [-1, 0], [0, -1]]
    w_goto = []
    for i in range(5):
        for j in range(5):
            if [i, j] in next_y_x:
                pass
            else:
                w_goto.append([-2 + i, -2 + j])
    w_goto.remove([0,0])
    is_found = False

    while que:
        temp = que.popleft()
        w_num = temp[2]

        for dy, dx in next_y_x:
            ny = temp[0] + dy
            nx = temp[1] + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1:
                if grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                    que.append([ny, nx, temp[2]])
                    fp[ny][nx] = w_num
                elif grid[ny][nx] == '#':
                    for dy, dx in w_goto:
                        nwy = temp[0] + dy
                        nwx = temp[1] + dx
                        nw = w_num +1

                        if 0 <= nwy <= H-1 and 0 <= nwx <= W-1:
                            if grid[nwy][nwx] == '.' and fp[nwy][nwx] > w_num:
                                que.append([nwy, nwx, nw])
                                fp[nwy][nwx] = nw

    if fp[Dh][Dw] != 10**6:
        print(fp[Dh][Dw])
    else:
        print(-1)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    from collections import deque

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [input() for _ in range(H)]
    max_num = 10**6
    fp = [[max_num] * W for _ in range(H)]

    que = deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0

    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    while que:
        y, x, w_num = que.popleft()

        for dy, dx in walk:
            ny = y + dy
            nx = x + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                que.appendleft([ny, nx, w_num])
                fp[ny][nx] = w_num

        for dy, dx in warp:
            ny = y + dy
            nx = x + dx
            nw = w_num +1

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > nw:
                que.append([ny, nx, nw])
                fp[ny][nx] = nw

    if fp[Dh][Dw] != max_num:
        print(fp[Dh][Dw])
    else:
        print(-1)

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

N, K = map(int, input().split())
S = []

for _ in range(K):
  L, R = map(int, input().split())
  S.extend(range(L,R+1))
  
S.sort()

DP =[0]*N
DP[0] = 1

for i in range(N-1):
  for j in S:
    
    if i+j<N:
      DP[i+j] += DP[i]
    else:
      break

print(DP[-1]%998244353)

### FIXED CODE ###

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

L = []
R = []

for _ in range(K):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
  
dp = [0]*(N+5)
dp[1] = 1

for i in range(2, N+1):
  dp[i] = dp[i-1]
  for j in range(K):
    if i-L[j] >= 0:
      dp[i] += dp[i-L[j]]
    if i-R[j]-1 >= 0:
      dp[i] -= dp[i-R[j]-1]
    dp[i] %= 998244353
    
print((dp[N]-dp[N-1])%998244353)
### BUGGY CODE ###

import numpy as np

n, nt = map(int, input().split())
ms = np.array(list(sorted(map(int, input().split()))))
fs = np.array(list(reversed(sorted(map(int, input().split())))))
r = ms*fs

for i in range(nt):
  idx = np.argmax(r)
  if ms[idx] < 1:
    break
  ms[idx] -= 1
  r[idx] = ms[idx] * fs[idx]

print(np.max(ms*fs))

### FIXED CODE ###

import numpy as np
N, train_max = map(int, input().split())
members = np.sort(list(map(int, input().split())))
members_sum = members.sum()
foods = np.sort(list(map(int, input().split())))[::-1]

inferenced_time_max = int(1e+6 * 1e+6)
inferenced_time_min = -1

while inferenced_time_max > inferenced_time_min+1:
  inferenced_time = (inferenced_time_max + inferenced_time_min) // 2
  inferenced_members = np.minimum(members, inferenced_time // foods)
  if members_sum - inferenced_members.sum() <= train_max:
    inferenced_time_max = inferenced_time
  else:
    inferenced_time_min = inferenced_time

print(inferenced_time_max)
### BUGGY CODE ###

n = int(input())
for i in range(1,n+1):
    ans = 0
    for x in range(40):
        for y in range(40):
            for z in range(40):
                if (x+y+z)**2 -(x*y+y*z+z*x) == i and x>=1 and y>=1 and z>=1:
                    ans += 1
    print(ans)


### FIXED CODE ###

cnt=[0] * 11000
n = int(input())

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            value = (x+y+z)**2 -(x*y+y*z+z*x)
            if value <= n:
                cnt[value] += 1

for i in range(1,n+1):
    print(cnt[i])
### BUGGY CODE ###

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

all_length = k*2
point = []
for i in range(n):
    a_left  = k-a[i]
    a_right = k+a[i]
    point.append(a_left)
    point.append(a_right)
point = list(set(point))
point.sort()

num = len(point)
num = round(num/2)
distance = []
for i in range(num):
    dis = 0
    for j in range(n-1):
        dis += point[i+j+1] - point[i+j]
    distance.append(dis)
mindis = min(distance)
print(mindis)

### FIXED CODE ###

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

A.append(A[0]+k)
l = 0
for i in range(n):
    l = max(l, A[i+1]-A[i])
print(k-l)
### BUGGY CODE ###

a = list(map(int,input().split()))
n = a[0]
k = a[1]

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

### FIXED CODE ###

a = list(map(int,input().split()))
n = a[0]
k = a[1]

if 2*n <= k:
  n = n
elif (k<2*n)and(n<=k):
  n = k-n
elif k<n:
  n = n%k
  if 2*n<=k:
    n = n
  else:
    n = k-n
print(n)
### BUGGY CODE ###

#その前のstrと違って、けど一番短いのを足していけばいいだけ。
S = input()
L = [alphabet for alphabet in S]
moji1 = L[0]
moji2 = ''
i = 1
res = 0
while i < len(L):
  if moji1 == moji2:
    moji2 += L[i]
    i+=1
  if moji1 != moji2 and moji2 != '':
    res += 1
    moji1 = moji2
    moji2 = L[i]
    i += 1
print(res)

### FIXED CODE ###

#その前のstrと違って、けど一番短いのを足していけばいいだけ。
S = input()
L = [alphabet for alphabet in S]
i = 0
k = 1
before = ''
res = 0
while i+k <= len(L):
  if L[i:i+k] != before:
    res += 1
    before = L[i:i+k] # "before" updated
    i = i+k #next a of L[a:b]
    k = 1 #initialised
  else:
    k += 1
print(res)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    ans = a[:i] + a[i+1:]
    print(max(ans))
    ans = []

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
ans = sorted(a)
max1 = ans[-1]
max2 = ans[-2]
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)
### BUGGY CODE ###

D,G=map(int,input().split())
p=[0]*D
c=[0]*D
ans=1000000000
for i in range(D):
    p[i],c[i]=map(int,input().split())
for i in range(1<<D):
    s=0
    cnt=0
    P=[0]*D
    for j in range(D):
        if ((i>>j)&1)==1:
            s+=c[j]+(j+1)*p[j]*100
            cnt+=p[j]
            P[j]=1
    while s<G:
        for k in range(D):
            if P[D-k-1]==0:
                for l in range(p[D-k-1]-1):
                    if s>=G:
                        break
                    else:
                        s+=(D-k)*100
                        cnt+=1
    if cnt<ans:
        ans=cnt
print(ans)

### FIXED CODE ###

D,G=map(int,input().split())
p=[0]*D
c=[0]*D
ans=1000000000
for i in range(D):
    p[i],c[i]=map(int,input().split())
for i in range(1<<D):
    s=0
    cnt=0
    P=[0]*D
    for j in range(D):
        if ((i>>j)&1)==1:
            s+=c[j]+(j+1)*p[j]*100
            cnt+=p[j]
            P[j]=1
    m=-1
    for k in range(D):
        if m<0:
            if P[D-k-1]==0:
                m=D-k
        else:
            break
    if m>=0:
        for l in range(p[m-1]-1):
            if s<G:
                s+=m*100
                cnt+=1
    if s>=G and cnt<ans:
        ans=cnt
print(ans)
### BUGGY CODE ###

from collections import Counter

N = int(input())
S = input()

ans_list = [0] * N
for i in range(N):
    count_E = Counter(S[: i])['W']
    count_W = Counter(S[i + 1:])['E']
    ans_list[i] = count_E + count_W
print(min(ans_list))

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()

count_E = Counter(S)['E']
count_W = Counter(S)['W']

right = 0
left = count_E
tmp = N
for i in range(N):
    if S[i] == 'E':
        left -= 1
    if right + left < tmp:
        tmp = right + left
    if S[i] == 'W':
        right += 1
print(tmp)
### BUGGY CODE ###

import numpy as np
a = int(raw_input())
Ali = (np.array( map(int,raw_input().split())))
Bli =(np.array(map(int,raw_input().split())))
Cli =(np.array(map(int,raw_input().split())))
Ali = np.sort(Ali)
Bli = np.sort(Bli)[::-1]
Cli = np.sort(Cli)[::-1]
co=0
for A in Ali:
    if A >= Bli[0]:
        break
    for B in Bli:
        if A >= B:
            break
        for C in Cli:
            if B >= C:
                break
            co +=1 
print(co)


### FIXED CODE ###

import bisect
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort()
Clist.sort()
retnum = 0 
for i in Blist:
    Anum = bisect.bisect_left(Alist,i)
    Cnum =  N - bisect.bisect_right(Clist,i)
    retnum +=(Anum * Cnum)
print(retnum)
### BUGGY CODE ###

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

cnt = 0 

for i in range(N):
        tmp = A[i]
        flag = 1 
        for j in range(N):
                if i == j:
                        continue
                if tmp % A[j] == 0:
                        flag = -1
                        break
        if flag == 1:
                cnt += 1

print(cnt)  

### FIXED CODE ###

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

A.sort()

l = [0] * (A[N - 1] + 1)

for i in A:
        j = i 
        while j <= A[N - 1]: 
                l[j] += 1
                j += i 

cnt = 0 
for k in A:
        if l[k] == 1:
                cnt += 1

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
    for j in range(K, -1, -1):
        dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(K, -1, -1):
        # 後ろiこの合計がjのもの
        if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
            # K-j > x >= K-j-a
            break
    else:
        r += 1
    dp2 |= dp2<<a
print(r)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(a):
        if dp2 & dpm[N-i-1]:
            break
        dpm[N-i-1] >>= 1
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)
### BUGGY CODE ###

n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i)
	elif s[i] == "G":
		g.append(i)
	else:
		b.append(i)
count = 0
for i in r:
	for j in g:
		u = abs(i-j)
		count += [0,1][(max(i,j)+u) in b] + [0,1][(min(i,j)-u) in b] + [0,1][u%2 == 0 and (i+j)//2 in b]
print(len(r)*len(g)*len(b)-count)

### FIXED CODE ###

from collections import Counter
# これは, u749194f さんの改造です。
# オリジナルではございません。
# https://atcoder.jp/contests/abc162/submissions/11825963
n = int(input())
s = input()
flag = True
if len(set(s))<=2:
    print(0)
    flag = False
if flag:
    r = [i+1 for i in range(n) if s[i]=='R']
    b = [i+1 for i in range(n) if s[i]=='B']
    g = [i+1 for i in range(n) if s[i]=='G']
    minus = 0
    def cnt_cmb(a, b, c):
        cnt = 0
        set_c = set(c)
        for i in a:
            for j in b:
                if (i+j)/2 in set_c:
                    cnt += 1
        return cnt
    minus += cnt_cmb(r, b, g)
    minus += cnt_cmb(b, g, r)
    minus += cnt_cmb(g, r, b)
    a = Counter(s)
    rslt = 1
    for value in a.values():
        rslt *= value
    print(len(r)*len(b)*len(g)-minus)
### BUGGY CODE ###

from fractions import gcd

def main():

    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7
    def lcm(a,b):
        return a*b // gcd(a,b)

    LCM = 1
    for a in A:
        LCM = lcm(LCM, a)

    B = []
    for i in range(N):
        B.append(LCM // A[i])

    print(sum(B) % MOD)


if __name__ == "__main__":
    main()

### FIXED CODE ###

from fractions import gcd


def main():
        
    N = int(input())
    A = list(map(int, input().split())) 
    MOD = 10**9 + 7


    l = 1

    for a in A:
        l = l * a // gcd(l, a)


    ans = 0
    for a in A:
        ans += (l // a)
    ans %= MOD

    print(ans)


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

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [set([]) for _ in range(N+1)]
for a,b in AB:
    graph[a].add(b)
    graph[b].add(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
check = [False for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        check[p] = True
        for e in graph[p]:
            if not check[e]:
                counter[e] += counter[p]
                stk.append(e)
                check[e] = True

dfs(graph,counter,1)

counter = counter[1:]
ans = " ".join(map(str,counter))
print(ans)


### FIXED CODE ###

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [[] for _ in range(N+1)]

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x:x[1], reverse=True)
 
ans = 0
b,c = BC.pop(0)
for i,a in enumerate(A):
    if b>=1:
        if c > a:
            ans += c
            b -= 1
        else:
            ans += a
    if b<=0:
        if len(BC)==0:
            ans += sum(A[i+1:])
            break
        else:
            b,c = BC.pop(0)
 
print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x:x[1], reverse=True)
 
ans = 0
b,c = BC.pop(0)
for i,a in enumerate(A):
    if b>=1:
        if c > a:
            ans += c
            b -= 1
        else:
            ans += a
    if b<=0:
        if len(BC)==0:
            ans += sum(A[i+1:])
            break
        else:
            b,c = BC.pop(0)
 
print(ans)
### BUGGY CODE ###

n = int( input() )
a = list( map( int, input().split() ) )
 
ret = 1
if 0 in a:
  ret = 0
else:
  for ai in a:
    ret = ret * ai
    if ret > 10 ** 18:
      ret = -1
 
print( ret)

### FIXED CODE ###

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

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))

c = (n - 1) // 2

for i in range(len(x)):
    x2 = x.copy()
    x2.pop(i)
    x2.sort()
    print(x2[c])


### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))

x2 = x.copy()
x2.sort()
c1 = x2[n // 2 - 1]
c2 = x2[n // 2]
for i in x:
    if(c1 >= i):
        print(c2)
    else:
        print(c1)