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

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
pre = 0
for b in B:
    tmp = bisect.bisect_right(C[pre:],b)
    pre += tmp
    d[b] = n - pre

pre = 0
for a in A:
    tmp = bisect.bisect_right(B[pre:],a)
    pre += tmp
    for b in B[pre:]:
        ans += d[b]

print(ans)

### FIXED CODE ###

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
for b in B:
    tmp = bisect.bisect_right(C,b)
    tmp2 = bisect.bisect_left(A,b)
    ans += (n-tmp) * tmp2

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

N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dis_lis = [0]*N
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j)==1:
            dis_lis[1] += 1
        else:
            min1 = abs(i-j)
            min2 = abs(i-X)+abs(j-Y)+1
            min3 = abs(i-Y)+abs(j-X)+1
            dis_lis[min(min1, min2, min3)] += 1
for i in range(1, N):
    print(dis_lis[i])

### FIXED CODE ###

from collections import deque
from collections import Counter
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dis_lis = deque()
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j)==1:
            dis_lis.append(1)
        else:
            min1 = abs(i-j)
            min2 = abs(i-X)+abs(j-Y)+1
            min3 = abs(i-Y)+abs(j-X)+1
            dis_lis.append(min(min1, min2, min3))
c = Counter(dis_lis)
for i in range(1, N):
    print(c[i])
### BUGGY CODE ###

N=int(input())


def monum(H):
    if H==1:
        return 1
    else:
        return 1+monum(H//2)+monum(H//2)
print(monum(N))

### FIXED CODE ###

H=int(input())
at=0

if H==1:
    print(1)
    
else:
    while H!=0:
        H=H//2
        at+=1
    ans=1
    preans=1
    for i in range(2,at+1):
        ans+=preans*2
        preans=preans*2
    print(ans)
### BUGGY CODE ###

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

i = 1
while True:
    if i in list_a:
        index = list_a.index(i)
        list_a = list_a[index:]
        i += 1
    else:
        break

print(N - (i - 1) if i != 1 else -1)


### FIXED CODE ###

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

count = 1
for i in list_a:
    if i == count:
        count += 1

print(N - (count - 1) if count != 1 else -1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque
import copy

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
q=deque()
q.append(N)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in rev_al[fro]:
		if Visit[to]==0:
			q.append(to)
			
Visit1=Visit

#スタートからBFS
q=deque()
q.append(1)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to]==0:
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)

fedge=[]	#必要な要素だけをフィルターした辺集合
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		fedge.append((a,b,c))


D=[ float("-inf") for _ in range(N+1) ]	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード
for i in range(N):
	for a,b,c in fedge:
		if D[a]==float("-inf"): continue
		if i==N-1 and D[b]!=max( D[b],D[a]+c ):
			print -1
			quit()
		D[b]=max( D[b],D[a]+c )

print max(0,D[N])

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(N)
Visit[N]=1
while q:
	fro=q.popleft()
	for to in rev_al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)
			
Visit1=Visit

#スタートからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(1)
Visit[1]=1
while q:
	fro=q.popleft()
	for to in al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)

new_N=sum(V)

fedge=[]	#必要な要素だけをフィルターした辺集合
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		fedge.append((a,b,c))


D=[ float("-inf") ]*(N+1)	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード
for i in range(new_N):
	for a,b,c in fedge:
		if D[a]==float("-inf"): continue
		alt=D[a]+c
		if D[b]<alt:
			D[b]=alt
			if i==new_N-1:
				print -1
				quit()

print max(0,D[N])
### BUGGY CODE ###

import queue

N, M = [int(x) for x in input().split(' ')]
A = []
B = []
connected = [set() for _ in range(N)]
for _ in range(M):
  a, b = [int(x) - 1 for x in input().split(' ')]
  A.append(a)
  B.append(b)
  connected[a].add(b)
  connected[b].add(a)
  

print('Yes')

ans = [-1] * N
dist = [N+100] * N
dist[0] = 0
next_all = queue.Queue(N)
next_all.put(0)
processed = set()

while not next_all.empty():
  n = next_all.get()
  processed.add(n)
  
  pre = min([(dist[c], c) for c in connected[n]])
  dist[n] = pre[0] + 1 if pre[0] < N else 0
  ans[n] = pre[1]
  for c in connected[n]:
    if c not in processed:
      next_all.put(c)
# print(dist)
for a in ans[1:]:
  print(a+1)



### FIXED CODE ###

import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()

G.add_edges_from(tuple(map(int, input().split())) for _ in range(M))

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])
### BUGGY CODE ###

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

down = 0
#下限
all_time = 0
stack = 0

while(True):
    up = 100000000
    #上限
    for i in range(n):
        if b[i] < up and b[i]>down:
            up = b[i]

#    print("up:"+str(up))
    s_time = 0
    for i in range(n):
        if b[i] == up:
            s_time += a[i]
            stack += 1
    
    all_time += s_time
    if all_time > up:
        print("No")
#        print(all_time)
        break

    if stack == n:
        print("Yes")
        break
    down = up

### FIXED CODE ###

n = int(input())
l = []
for i in range(n):
    c,d = map(int,input().split())
    l.append([c,d])

l.sort(key = lambda x:x[1])

time = 0
ans = "Yes"
for i in range(n):
    limit = l[i][1]
    time += l[i][0]
    if time > limit:
        ans = "No"
        break

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

n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(n-2,-1,-1):
    for j in range(i+1,n):
        L=a[i]-dp[i+1][j]
        R=a[j]-dp[i][j-1]
        dp[i][j]=L if L>R else R
print(dp[0][n-1])


### FIXED CODE ###

def kukan(n, a):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            L = a[i] - dp[i + 1][j]
            R = a[j] - dp[i][j - 1]
            dp[i][j] = L if L > R else R
    return dp[0][n - 1]


n = int(input())
a = list(map(int, input().split()))
print(kukan(n, a))
### BUGGY CODE ###

import numpy as np
from scipy.sparse.linalg import dsolve
from scipy import sparse
N=int(input())
a=list(map(int, input().split()))
for i in range(N):
  a[i]=a[i]*2
X=[[0 for j in range(N)] for i in range(N)]
for i in range(N-1):
    X[i][i]=1
    X[i][i+1]=1
X[N-1][0]=1
X[N-1][N-1]=1
a=sparse.csr_matrix(a)
X=sparse.csr_matrix(X)
b=dsolve.spsolve(X, a)
for i in range(N):
  print(int(b[i]), end=" ")
    

### FIXED CODE ###

N=int(input())
a=list(map(int, input().split()))
for i in range(N):
    a[i]=a[i]*2
b=[0 for i in range(N)]
sum1=0
for i in range(N-1):
    if i%2==0:
        sum1+=a[i]
    else:
        sum1+=a[i]*(-1)
ans=(sum1+a[N-1])/2
b[0]=ans
for i in range(N-1):
    b[i+1]=a[i]-b[i]
for i in range(N):
    print(int(b[i]), end=" ")
### BUGGY CODE ###

import bisect
import heapq
N,Q = list(map(int,input().split(" ")))

hitos = []
ans = [-1] * Q
queries =[]
heapq.heapify(queries)
events = []
for i in range(N):
    S,T,X =list(map(int,input().split(" ")))
    lt = S -X -0.5
    rt = T -X -0.5
    queries.append((lt,-1,X)) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所
    queries.append((rt,1,X)) # 1 → 削除クエリ



for i in range(Q):
    t = int(input())
    queries.append((t,0,-99)) # 0 → チェッククエリ
queries.sort(key = lambda x:x[0])
for t,kind,x in queries:
    if kind == 0:
        if len(events) > 0:
            print(min(events))
        else:
            print(-1)
    if kind == -1:
        events.append(x)
    if kind == 1:
        events.remove(x)



### FIXED CODE ###

import bisect
import heapq
import sys
N,Q = [int(x) for x in sys.stdin.readline().split()]

hitos = []
ans = [-1] * Q
queries =[]
jump = [-1] * Q



queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])





for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l-x - 0.5)
     rind  = bisect.bisect_left(hitos,r -x - 0.5)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

for i  in ans:
    print(i)
### BUGGY CODE ###

def search(n):
    res = 0
    while n:
        n %= bin(n).count("1")
        res += 1
    return res


def main():
    n = int(input())
    x = list(input())
    x_decimal = int("".join(map(str, x)), 2)
    first_mod = sum(map(int, list(x)))
    increase_mod = first_mod + 1
    increase_base = x_decimal % increase_mod  # 反転させる桁が元々0だった場合
    decrease_mod = first_mod - 1
    if decrease_mod:
        decrease_base = x_decimal % decrease_mod  # 反転させる桁が元々1だった場合
    diff = pow(2, n - 1)
    for i in range(n):
        cnt = 0
        if x[i] == "1" and decrease_mod:
            cnt = 1 + search((decrease_base - diff % decrease_mod) % decrease_mod)
        elif x[i] == "0":
            cnt = 1 + search((increase_base + diff % increase_mod) % increase_mod)
        diff //= 2
        print(cnt)


if __name__ == '__main__':
    main()



### FIXED CODE ###

def search(n):
    res = 0
    while n:
        n %= bin(n).count("1")
        res += 1
    return res


def main():
    n = int(input())
    x = list(input())
    x_decimal = int("".join(map(str, x)), 2)
    first_mod = sum(map(int, list(x)))
    increase_mod = first_mod + 1
    increase_base = x_decimal % increase_mod  # 反転させる桁が元々0だった場合
    decrease_mod = first_mod - 1
    if decrease_mod:
        decrease_base = x_decimal % decrease_mod  # 反転させる桁が元々1だった場合
    for i in range(n):
        cnt = 0
        if x[i] == "1" and decrease_mod:
            cnt = 1 + search((decrease_base - pow(2, n - i - 1, decrease_mod)) % decrease_mod)
        elif x[i] == "0":
            cnt = 1 + search((increase_base + pow(2, n - i - 1, increase_mod)) % increase_mod)
        print(cnt)


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

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
list_H = sorted(H, reverse=True)
for k in range(K):
    if len(list_H) > 0:
        list_H.pop(0)
attack = 0
for i in list_H:
    attack += i
print(attack)


### FIXED CODE ###

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
# 解法 bisectとsort(最初だけ)を使う
# dequeでbisectって使えんのかなぁ？
A.sort()
from collections import deque
A = deque(A)
import bisect
for i in range(M):
    a = A.pop()
    new = a/2
    bisect.insort_left(A,new)   # やってることはA.sort(bisect.bisect_left(A,new),new)
import numpy as np
A = np.array(A,dtype=np.int64)
print(A.sum())



### FIXED CODE ###

# 優先度付きキューとか言うものが使えるかどうかが鍵になる
# pythonでは標準でheapqが使える．要するにヒープのこと．ただしヒープでは最小値しか取り出せないのでそこに注意する必要がある.
# 計算量はO(log(N))になる
N,M = map(int,input().split())
A = list(map(int,input().split()))
# 解法 bisectとsort(最初だけ)を使う
# dequeでbisectって使えんのかなぁ？
#A.sort()
#from collections import deque
#A = deque(A)
A = [-a for a in A]
import heapq
heapq.heapify(A)
import bisect
for i in range(M):
    a = heapq.heappop(A)
    new = a/2
    # listに挿入する．ただしpythonのlistは可変長配列なので，linked-listではない.それゆえ末尾や先頭以外への要素の挿入はO(N)かかる
    #bisect.insort_left(A,new)   # やってることはA.sort(bisect.bisect_left(A,new),new)．
    heapq.heappush(A,new)
import numpy as np
A = np.array(A,dtype=np.int64)
print(-A.sum())
### BUGGY CODE ###

MAX = 10**6
N = int(input())
A = list(map(int, input().split()))
B = [0] * (MAX+1)
for i in range(N):
  B[A[i]] += 1
L = [0] * (MAX+1)
for i in range(N):
  k = A[i]
  tmp = 2*k
  while(tmp <= MAX):
    L[tmp] = 1
    tmp += k

ans = 0
for i in range(N):
  if(B[A[i]] == 1 and L[A[i]] == 0):
    ans += 1
print(ans)

### FIXED CODE ###

MAX = 10**6
N = int(input())
A = list(map(int, input().split()))
B = [0] * (MAX+1)
for i in range(N):
  B[A[i]] += 1
L = [0] * (MAX+1)
for k in range(MAX+1):
  if(B[k] >= 1 and L[k] == 0):
    tmp = 2*k
    while(tmp <= MAX):
      L[tmp] = 1
      tmp += k

ans = 0
for i in range(N):
  if(B[A[i]] == 1 and L[A[i]] == 0):
    ans += 1
print(ans)
### BUGGY CODE ###

Q = int(input())

a = [[int(i) for i in input().split()] for j in range(Q)]

for i in range(Q):
    m = a[i][0]
    for j in range(a[i][2]-1):
        m = (m*(a[i][0]+(j+1)*a[i][1]))%1000003
    print(m)

### FIXED CODE ###

MOD = 10**6+3

def main():
    # preprocess
    fac = [1, 1]
    f_inv = [1, 1]
    inv = [0, 1]

    for i in range(2, MOD+1):
        fac.append((fac[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD//i)) % MOD)
        f_inv.append((f_inv[-1] * inv[-1]) % MOD)

    Q = int(input())
    for i in range(Q):
        x, d, n = map(int, input().split())

        if d == 0:
            print(pow(x, n, MOD))
            continue
        
        xd = (x * pow(d, MOD-2, MOD)) % MOD
        if xd == 0 or xd + (n-1) >= MOD:
            print(0)
            continue

        print(pow(d, n, MOD) * fac[xd+(n-1)] * f_inv[xd-1] % MOD)


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

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

a_sorted = sorted(a)
divisible_list = [True] * n
for i in range(n-1):
    if not divisible_list[i]:
        continue
    for j in range(i+1, n):
        if a_sorted[j] == a_sorted[i]:
            divisible_list[i] = False
            divisible_list[j] = False
        if a_sorted[j] % a_sorted[i] == 0:
            divisible_list[j] = False
print(sum(divisible_list))

### FIXED CODE ###

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

a_sorted = sorted(a)
divisible_list = [0] * (max(a)+1)

for i in range(len(a)):
    for j in range(0, len(divisible_list), a[i]):
        divisible_list[j] += 1

ans = 0
for i in range(len(a)):
    if divisible_list[a[i]] == 1:
        ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
# a,b = map(int, input().split())
l = list(map(int, input().split()))

ans = 1
for i in range(n):
    ans *= l[i]

if ans > 10**18:
    print(-1)
    exit()
print(ans)



### FIXED CODE ###

# a,b = map(float, input().split())

# print(int(a*b))

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

ans = 1
if l.count(0) != 0:
    print(0)
    exit()
for i in range(n):
    ans *= l[i]
    if ans > 10**18:
        print(-1)
        exit()

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

l,r = map(int,input().split())
ans = 2019

if l == 0:
    print(0)
    quit()

for i in range(l,r):
    for j in range(i+1,r+1):
        if ans == 0:
            break
        ans = min(ans,i*j%2019)

print(ans)

### FIXED CODE ###

l,r = map(int,input().split())
ans = 2019

for i in range(l,min(r+1,l+2020)):
    for j in range(i+1,min(r+1,l+2020)):
        if ans == 0:
            break
        ans = min(ans,i*j%2019)

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

import sys
from operator import itemgetter
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
def main():
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while(e[0] > d):
			if cont == True:
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			else:
				mini = min(kouho)
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			cont = True
			if q < Q-1:
				q = q + 1
				d = int(inputs())
			else:
				flag = True
				q = q + 1
				break
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			cont = False
	for t in [None]*(Q-q):
		print(-1)
		
def sub():
	V = [list(map(int,inputs().split())) for p in [0]*N]
	M = [int(inputs()) for p in [0]*Q]
	V.sort(key = lambda x:(x[2],x[0],x[1]))
	for v in V:
		v[0] -= v[2]
		v[1] -= v[2] + 1
	for m in M:
		for n in range(N):
			if V[n][0] <=m and m <= V[n][1]:
				print(V[n][2])
				break
		else:
			print(-1)

#N200000
if Q>200000:
	sub()
else:
	main()

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

N = int(input())
x_list = [i for i in map(int, input().split())]

for i, x in enumerate(x_list):
    tmp = x_list.copy()
    tmp.pop(i)
    tmp.sort()
    print(tmp[(len(tmp))//2])

### FIXED CODE ###

N = int(input())
x_list = [i for i in list(map(int, input().split()))]
tmp = x_list.copy()
x_list.sort()
big = x_list[len(x_list)//2]
small = x_list[len(x_list)//2-1]

for x in tmp:
    if x >= big:
        print(small)
    else:
        print(big)
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())
    for _ in range(q):
        qu = [x for x in input().split()]
        if len(qu) == 1:
            s = s[::-1]
        else:
            if qu[1] == '1':
                s = qu[2] + s
            else:
                s = s + qu[2]
    print(s)
main()

### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    jun = True
    mae = ""
    ushiro = ""
    for _ in range(q):
        qu = input()
        if qu == '1':
            jun = not jun
        else:
            if qu[2] == '1':
                if jun:
                    mae = qu[4] + mae
                else:
                    ushiro = ushiro + qu[4]
            else:
                if jun:
                    ushiro = ushiro + qu[4]
                else:
                    mae = qu[4] + mae
    s = mae + s + ushiro
    if not jun:
        s = s[::-1]
    print(s)
main()
### BUGGY CODE ###

from collections import deque

s=input()

d=deque()
for i in s:
  d.append(i)
  
v=1

q=int(input())

for i in range(q):
  a=input()
  if len(a)==1:
    if v:
      v=0
    else:
      v=1
  else:
    b,f,c=a.split()
    if f=="1":
      if v:
        d.appendleft(c)
      else:
        d.append(c)
    else:
      if v:
        d.append(c)
      else:
        d.appendleft(c)
        
ans=""
if v:
  for i in range(len(d)):
    ans+=d[i]
else:
  for i in range(len(d)):
    ans+=d.pop()
    
print(ans)

### FIXED CODE ###

from collections import deque

s=input()

d=deque()
for i in s: #10**5
  d.append(i)
  
v=1

q=int(input())

for i in range(q): #2*10**5
  a=input()
  if len(a)==1:
    if v:
      v=0
    else:
      v=1
  else:
    b,f,c=a.split()
    if f=="1":
      if v:
        d.appendleft(c)
      else:
        d.append(c)
    else:
      if v:
        d.append(c)
      else:
        d.appendleft(c)
        
if v:
  for i in range(len(d)):
    print(d[i],end="")
else:
  for i in range(len(d)):
    print(d[len(d)-1-i],end="")
    
print()
### BUGGY CODE ###

n = int(input())
li = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans = ans * li[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

n = int(input())
mod = 10**18
li = list(map(int, input().split()))
li.sort()
ans = 1
for i in range(n):
    ans *= li[i]
    if ans > mod:
        ans = -1
        break
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

h = sorted(h, reverse=True)
is_zero = False
for i in range(k):
    try:
        del h[0]
    except:
        is_zero = True
        break
if is_zero:
    print(0)
else:
    print(sum(h))

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

if n <= k:
    print(0)
else:
    h = sorted(h, reverse=True)
    print(sum(h[k:]))