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

n,m = map(int,input().split())
a = [i for i in map(int,input().split())]
bc = [[i for i in map(int,input().split())] for j in range(m)]

a.sort(reverse=True)
bc.sort(key=lambda x: x[1], reverse=True)
arr = []
j = 0
for i in range(n):
  arr.append(bc[j][1])
  bc[j][0]-=1
  if bc[j][0]==0:
    j += 1
  if j >= m:
    break

while len(arr) < n:
  arr.append(a.pop(0))
arr.sort()

for i in range(len(a)):
  if arr[0] < a[0]:
    arr[0] = a.pop(0)
  arr.sort()
  
print(sum(arr))

### FIXED CODE ###

N, M = map(int,input().split())
A = [i for i in map(int,input().split())]
BC = [[i for i in map(int,input().split())] for j in range(M)]
A.sort()
BC.sort(reverse=True, key=lambda x:x[1])

ans_arr = [0 for i in range(N)]

j = 0
for i in range(N):
  if j < M:
    if A[i] < BC[j][1]:
      ans_arr[i] = BC[j][1]
      BC[j][0] -= 1
      if BC[j][0] == 0:
        j+=1
    else:
      ans_arr[i] = A[i]
  else:
    ans_arr[i] = A[i]
      
print(sum(ans_arr))
### BUGGY CODE ###

data = input().split()

n = int(data[0])
a=[]
valueList=[]
for i in range(n):
    line = input().split()
    tmp=[]
    tmp.append(int(line[0]))
    tmp.append(int(line[1]))
    a.append(tmp)
    valueList.append(int(line[1]) + int(line[0]))


taka=0
ao=0

for i in range(n):
    ind = valueList.index(max(valueList))
    if(i%2 == 0):
        taka += a[ind][0]
    else:
        ao += a[ind][1]
    a.pop(ind)
    valueList.pop(ind)

print(taka-ao)


### FIXED CODE ###

data = input().split()

n = int(data[0])
a=[]
for i in range(n):
    line = input().split()
    tmp=[]
    tmp.append(int(line[1]) + int(line[0]))
    tmp.append(int(line[0]))
    tmp.append(int(line[1]))
    a.append(tmp)

res=0
a.sort(key=lambda x: x[0])
a.reverse()

flg=True

for e in a:
    if(flg):
        res +=e[1]
    else:
        res -=e[2]
    flg=not(flg)
    

print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

for i in range(1,N+1):
    print(A.index(i)+1,end=" ")

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

ans = [0] * N
for k,v in enumerate(A):
    ans[v-1] = k+1

for i in range(N):
    print(ans[i],end=" ")
### BUGGY CODE ###

n = int(input())
b = []
st = input().split()
for i in range(n):
    k = st[i]
    if i % 2 == 0:
        b.insert(0, k)
    else:
        b.append(k)
if n % 2 == 0:
    b= list(reversed(b))
s = ""
for k in b:
    s += k + " "
print(s)


### FIXED CODE ###

n = int(input())
b = []
a = input().split()
if n % 2 == 0:
    m = n // 2
    for i in range(m):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i])
else:
    m = n // 2
    for i in range(m+1):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i+1])
s = ""
for k in b:
    s += k + " "
print(s)
### BUGGY CODE ###

import functools
n = int(input())
li_a = list(map(int, input().split()))

if 0 in li_a:
    print(0)
    exit(0)
w = functools.reduce(lambda x, y: x * y, li_a)
if w > 10 ** 18:
    print(-1)
    exit(0)
else:
    print(w)
    exit(0)


### FIXED CODE ###

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

if 0 in li_a:
    print(0)
    exit(0)
w = li_a[0]
for a in li_a[1:]:
    w = w * a
    if w > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(w)
    exit(0)
### BUGGY CODE ###

num_all = int(input())
list = input().split(" ")

list_int = []
for j in list:
  list_int.append(int(j))

i = 1
while i <= num_all:
  data = list_int.count(i)
  print(data)
  i = i+1

### FIXED CODE ###

n=int(input())
#l=list(map(int,input().split()))  #inputした数値列をintにしてlistを作成 けどなぜか使えない
list = input().split(" ")
list_int = []
for i in list:
  list_int.append(int(i)) 
k = [0]*n                         #大きさnのリスト
for i in list_int:
  k[i-1] = k[i-1]+1
for j in range(n):
  print(k[j])
### BUGGY CODE ###

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

colors = ['R', 'G', 'B']
thirds = {'RG': 'B', 'GR': 'B', 'BR': 'G', 'RB': 'G', 'BG': 'R', 'GB': 'R'}
accs = {color: [] for color in colors}
nums = {color: 0 for color in colors}
sums = {color: len([s for s in S if s == color]) for color in colors}
for i in range(N):
    nums[S[i]] += 1
    for color in colors:
        accs[color].append(sums[color] - nums[color])
        
res = 0
for i in range(N-2):
    first = S[i]
    for j in range(i+1, N-1):
        second = S[j]
        if first == second:
            continue
        third = thirds[first+second]
        res += accs[third][j]
        if 2 *j - i < N and S[2*j - i] == third:
            res -= 1
                
print(res)

### FIXED CODE ###

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

colors = ['R', 'G', 'B']
thirds = {'RG': 'B', 'GR': 'B', 'BR': 'G', 'RB': 'G', 'BG': 'R', 'GB': 'R'}
accs = {color: [] for color in colors}
nums = {color: 0 for color in colors}
sums = {color: len([s for s in S if s == color]) for color in colors}
for i in range(N):
    nums[S[i]] += 1
    for color in colors:
        accs[color].append(sums[color] - nums[color])
        
res = 0
for i in range(N-2):
    first = S[i]
    for j in range(i+1, N-1):
        second = S[j]
        if first == second:
            continue
        third = thirds[first+second]
        res += accs[third][j]
        if 2 *j - i < N and S[2*j - i] == third:
            res -= 1
                
print(res)
### BUGGY CODE ###

MAX = 10**9 + 7

def mod_inv(i, MOD):
    return pow(i, MOD-2, MOD)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up *= (_N - i) % MAX
        low *= (i + 1) % MAX
    ret = up * mod_inv(low, MAX)
    if ret >= MAX:
        ret %= MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = (M*N* ((M*(N+1)*(N-1))%MAX + (N*(M+1)*(M-1)) % MAX)) % MAX
    disSum *= mod_inv(6, MAX)
    if disSum >= MAX:
        disSum %= MAX
    ret = disSum * combination(M*N-2, K-2)
    if ret >= MAX:
        ret %= MAX
    print ret

if __name__ == '__main__':
    solve()


### FIXED CODE ###

MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = (M*N* ((M*(N+1)*(N-1))%MAX + (N*(M+1)*(M-1)) % MAX)) % MAX
    disSum *= mod_inv(6, MAX) % MAX
    ret = disSum * combination(M*N-2, K-2) % MAX
    print ret

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

s = list(input())

MOD = pow(10, 9) + 7

n = len(s)
s.reverse()

dp = [[0] * 13 for _ in range(n)]

r = list(range(10))
#print(s)
#init
if s[0] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    q = int(s[0])
    dp[0][q] = 1

for i in range(1, n):

    for l in range(10):
        r[l] = r[l] * 10 % 13

    #print(r)

    if s[i] == "?":
        for j in range(10):
            q = r[j]
            for k in range(13):
                dp[i][k] += dp[i-1][k-q]
    
    else:
        q = r[int(s[i])]
        #print(q)
        for k in range(13):
            dp[i][k] += dp[i-1][k-q]
    #print(dp[i])

#print(dp)
print(dp[n-1][5] % MOD)

### FIXED CODE ###

s = list(input())

MOD = pow(10, 9) + 7

n = len(s)

dp = [[0] * 13 for _ in range(n)]

#r = list(range(10))

#init
if s[-1] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    q = int(s[-1])
    dp[0][q] = 1

r = 1

for i in range(1, n):
    r = r * 10 % 13
    # for l in range(10):
    #     r[l] = r[l] * 10 % 13

    #print(r)

    if s[n-i-1] == "?":
        for j in range(10):
            q = j * r % 13
            for k in range(13):
                dp[i][k] += dp[i-1][k-q] % MOD
    
    else:
        q = int(s[n-i-1]) * r % 13
        #print(q)
        for k in range(13):
            dp[i][k] += dp[i-1][k-q] % MOD
    #print(dp[i])

print(dp[n-1][5] % MOD)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que, frag = deque(), set()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j)), frag.add((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if (i, j) in frag:  # 処理済みか否か
                continue
            if 0 <= i < h and 0 <= j < w:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j)), frag.add((i, j))
    return dist


if __name__ == '__main__':
    h, w = map(int, input().split())
    a = [input() for _ in range(h)]
    ans = bfs(a)
    print(max(max(ansi) for ansi in ans))


### FIXED CODE ###

from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j))
    return dist[x][y]


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))
### BUGGY CODE ###

import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = (x, y)
c = 0

U = [0]*(N+1)

for k in K:
	if U[k[0]] and U[k[1]]:
		a = U[k[0]]
		while(U[a] != a ):
			a = U[a]
		U[k[1]] = a
	elif U[k[1]]:
		U[k[0]] = U[k[1]]
	elif U[k[0]]:
		U[k[1]] = U[k[0]]
	else:
		U[k[0]] = k[0]
		U[k[1]] = k[0]

ans = 0
group = set()
for u in U[1:]:
	if u == 0:
		ans += 1
		continue
	elif u in group:
		group.add(u)
		continue
	elif u == U[u]:
		ans += 1
		group.add(u)
	else:
		while(u != U[u]):
			group.add(u)
		ans += 1
		group.add(u)
print(ans)

### FIXED CODE ###

import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = (x, y)
c = 0

U = [0]*(N+1)

for k in K:
	if U[k[0]] and U[k[1]]:
		a = U[k[0]]
		b = U[k[1]]
		while(U[a] != a ):
			a = U[a]
		while(U[b] != b ):
			c = b
			b = U[b]
			U[c] = a
		U[b] = a
	elif U[k[1]]:
		U[k[0]] = U[k[1]]
	elif U[k[0]]:
		U[k[1]] = U[k[0]]
	else:
		U[k[0]] = k[0]
		U[k[1]] = k[0]

ans = 0
c = 0
group = set()
for n in range(1,N+1):
	if U[n] == 0:
		ans += 1
		continue
	elif n == U[n]:
		ans += 1
		group.add(U[n])
	elif U[n] in group:
		continue
	else:
		while(n != U[n] and U[n] not in group):
			group.add(U[n])
			n = U[n]
		group.add(U[n])
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
readline = sys.stdin.buffer.readline


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

cnt = np.zeros(1000005)
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)

### FIXED CODE ###

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

cnt = [0] * 1000005
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

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

from collections import Counter

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
for start in range(N):
    if start >= len(A):
        break
    flag = [True] * len(A)
    s = A[start]     
    if C[s] >= 2:   
        for n in range(start,len(A)):
            if A[n]%s == 0:
                flag[n] = False
    else:   
        for n in range(start,len(A)):
            if A[n]%s == 0 and A[n] != s:
                flag[n] = False

    A = [A[n] for n in range(len(flag)) if flag[n]]
print(len(A))

### FIXED CODE ###

N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort()
M = max(A)
dp = [False] * (M+ 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (M// a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(N):
    if P[i] == min(P[:i+1]):
        ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
ans = 0
min = N
for i in range(N):
    if P[i] <= min:
        min = P[i]
        ans += 1
print(ans)
### BUGGY CODE ###

H, W = map(int, input().split())
grid = [input() for i in range(H)]
L = [[0] * W for i in range(H)]
R = [[0] * W for i in range(H)]
U = [[0] * W for i in range(H)]
D = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            continue
        if i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
        if j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i][j-1] + 1
for i in range(H)[::-1]:
    for j in range(W)[::-1]:
        if grid[i][j] == '#':
            continue
        if i == H-1:
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1
        if j == W-1:
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1
print(max(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3for i in range(H) for j in range(W)))


### FIXED CODE ###

import numpy as np

H, W = map(int, input().split())
grid = np.array([list(input()) for i in range(H)]) == '.'
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
for i in range(1, H):
    U[i] = (U[i-1] + 1) * grid[i-1]
for i in reversed(range(H-1)):
    D[i] = (D[i+1] + 1) * grid[i+1]
for i in range(1, W):
    L[:, i] = (L[:, i-1] + 1) * grid[:, i-1]
for i in reversed(range(W-1)):
    R[:, i] = (R[:, i+1] + 1) * grid[:, i+1]
print(((U + D + L + R) * grid).max() + 1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    ans = 0
    l0 = 0
    r0 = 1
    while l0 < N:
        for l1 in range(l0+1, N):
            # find and compare
            if S[l0] == S[l1]:
                k = 1
                while l0 + k < l1 and l1+k < N and S[l0+k] == S[l1+k]:
                    k += 1
                ans = max(ans, k)
        l0 += 1
    return ans

if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))


### FIXED CODE ###

import random
from collections import defaultdict


class RollingHash():

    def __init__(self, S, b=3491, m=999999937):
        """任意の基数と法でハッシュを生成する"""
        n = len(S)
        self.prefix = prefix = [0] * (n+1)
        self.power = power = [1] * (n+1)
        self.b = b
        self.m = m
        for i in range(n):
            c = ord(S[i])
            prefix[i+1] = (prefix[i] * b + c) % m
            power[i+1] = (power[i] * b) % m
    
    def get(self, l, r):
        """S[l, r) のハッシュを求める"""
        return (self.prefix[r] - self.power[r-l] * self.prefix[l]) % self.m
    
    def concat(self, h1, h2, l2):
        """S1+S2 のハッシュを、それぞれのハッシュから求める"""
        return (self.power[l2] * h1 + h2) % self.m
    
    def lcp(self, l1, r1, l2, r2):
        """S[l1, r1) とS[l2, r2) の最大共通接頭辞を求める"""
        low = 0
        high = min(r1-l1, r2-l2) + 1
        while high - low > 1:
            mid = (high + low) // 2
            if self.get(l1, l1 + mid) == self.get(l2, l2 + mid):
                low = mid
            else:
                high = mid
        return low


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    ans = []
    for m in [999999937, 10**9+7]:
        b = random.randint(10000, m-1)
        rh = RollingHash(S, b=b, m=m)
        low = 0
        high = (N+1) // 2 + 1
        dmax = defaultdict(int)
        dmin = defaultdict(int)
        while high - low > 1:
            dmax.clear()
            dmin.clear()
            mid = (high + low) // 2
            for i in range(0, N-mid+1):
                h = rh.get(i, i+mid)
                dmax[h] = max(dmax[h], i+1)
                dmin[h] = max(dmin[h], N+1-i)
            is_match = False
            for h in dmax.keys():
                if dmax[h] - (N+2 - dmin[h]) >= mid:
                    is_match = True
                    break
            if is_match:
                low = mid
            else:
                high = mid
        ans.append(low)
    return min(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**12, N)

dp = np.zeros((n, 10**5+1), np.int64)
dp[0, vws[0][1]:] = vws[0][0]
for i in range(1, n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V][L])
    else:
        d = {0: 0}
        while V >= n:
            v, w = vws[V]
            iterator = list(d.items())
            for w_sum, v_sum in iterator:
                if w_sum + w not in d:
                    d[w_sum + w] = v_sum + v
                else:
                    d[w_sum + w] = max(v_sum + v, d[w_sum + w])
            V = (V-1) // 2

        v_max = 0
        for w1, v1 in d.items():
            if 0 <= L-w1:            
                v_max = max(v_max, v1 + dp[V][L-w1])
        print(v_max)


### FIXED CODE ###

import sys
import numpy as np
from numba import njit

input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**11, N)
vws_arr = np.array(vws, np.int32)

dp = np.zeros((n, 10**5+1), np.int32)
for i in range(n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])


@njit("i4(i4[::1], i4[::1], i4, i4[::1])", cache = True)
def func(vs, ws, L, dp_):
    values = np.zeros(1 << len(vs), np.int32)
    weights = np.zeros(1 << len(vs), np.int32)
    for i in range(len(vs)):
        for bits in range(1 << len(vs)):
            if bits & (1 << i):
                values[bits] += vs[i]
                weights[bits] += ws[i]
    ret = 0
    for v, w in zip(values, weights):
        if w <= L:
            ret = max(dp_[L - w] + v, ret)
    return ret

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws_arr[Vs, 0]
        ws = vws_arr[Vs, 1]
        print(func(vs, ws, L, dp[V]))
### BUGGY CODE ###

N=int(input())
Slist=[]
for _ in range(N):
    Slist.append(input())
maxi=0
anslist=[]
for strings in Slist:
    if Slist.count(strings)>maxi:
        maxi=Slist.count(strings)
        if not strings in anslist:
            anslist=[strings]
    elif Slist.count(strings)==maxi:
        if not strings in anslist:
            anslist.append(strings)
for string in sorted(anslist):
    print(string)

### FIXED CODE ###

from collections import defaultdict
charnums=defaultdict(int)
N=int(input())
for _ in range(N):
    charnums[input()]+=1
ans=[]
m=max(charnums.values())
for key,value in charnums.items():
    if value==m:
        ans.append(key)
for an in sorted(ans):
    print(an)
### BUGGY CODE ###

def main():
  N,D,A=map(int,input().split())
  m=sorted([int(j) for j in input().split()] for i in range(N))

  c,l=0,0
  while l<N:
    p=(m[l][1]+A-1)//A
    m[l][1],n,r,c=0,0,l+1,c+p
    while r<N and m[l][0]+2*D>=m[r][0]:
      if m[r][1]>A*p:
        m[r][1]-=A*p
        if n==0:
          n=r
      elif m[r][1]!=0:
        m[r][1]=0
      r+=1
    else:
      l=n if n!=0 else r

  print(c)

main()


### FIXED CODE ###

import bisect

def main():
  N,D,A=map(int,input().split())
  m=sorted([int(j) for j in input().split()] for i in range(N))

  x=[m[i][0] for i in range(N)]
  es=[0]*(N+1)
  a,c=0,0
  for i in range(N):
    c-=es[i]
    if m[i][1]>A*c:
      t=(m[i][1]-A*c+A-1)//A
      a+=t
      c+=t
      es[bisect.bisect_right(x,x[i]+2*D)]+=t
  print(a)

main()
### BUGGY CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse=True)
if len(h) < k:
    print(0)
else:
    [h.pop(0) for x in range(k)]
    print(sum(h))

### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
total = 0
h.sort(reverse=True)
for i in range(k,n):
    total += h[i]
print(total)
### BUGGY CODE ###

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

array = [0] * (N+1)
set_a = set(a)
for ai in a:
    try:
        array[ai] += 1
    except:
        pass

ans = 0
for sa in set_a:
    if sa > N:
        ans += a.count(sa)
        continue
    while array[sa] != sa and array[sa] > 0:
        array[sa] -= 1
        ans += 1
print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = 0
for k, v in cnt.items():
    if k > v:
        ans += v
    elif k < v:
        ans += (v-k)
print(ans)
### BUGGY CODE ###

import sys

s = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())
Query = [(input().split()) for qn in range(Q)]

for q in Query:
	if  q[0]== '1':
		s = s[::-1]
	else:
		if q[0] == '2':
			if '1' == q[1]:
				s = q[2] + s
			if '2' == q[1]:
				s += q[2]
print(s)

### FIXED CODE ###

from collections import deque
import sys

def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]

    s = deque(s)
    r = 1
    for q in qs:
        if len(q) == 1:
            r = r * -1

        else:
            if q[1] == '1':
                if r == 1:
                    s.appendleft(q[2])
                else:
                    s.append(q[2])
            else:
                if r == 1:
                    s.append(q[2])
                else:
                    s.appendleft(q[2])

    if r == 1:
        print(''.join(s))
    else:
        s.reverse()
        print(''.join(s))

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

import bisect

N = int(input())
L = sorted(map(int, input().split()),reverse=True)

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        tmp  = L[i] - L[j]
        for k in range(j+1,N):
            if tmp < L[k]:
                cnt += 1
            else:
                break
print(cnt)





### FIXED CODE ###

import bisect
N = int(input())
L = sorted(map(int, input().split()))

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ab = L[i] + L[j]
        c_index = bisect.bisect_left(L, ab)
        cnt += c_index - 1 - j
print(cnt)