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

while True:
    n, a, b = map(int, input().split())
    if 1 <= n <= 10**18 and 0 <= a + b <= 10**18:
        break
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        for c in range(n):
            if l[c] == "b":
                count += 1
        break

print(count)


### FIXED CODE ###

N, A, B = map(int, input().split())
ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
### BUGGY CODE ###

from heapq import heappush, heappop, merge
from collections import defaultdict

N, Q = map(int, input().split())
events = []
for _ in range(N):
    s, t, x = map(int, input().split())
    events.append((s-x, 1, x))
    events.append((t-x, -1, x))
for _ in range(Q):
    d = int(input())
    events.append((d, 2, d))
events = sorted(events)

constructions = []
under_construction = defaultdict(bool)
ans = ''
for _, flag, coord in events:
    if flag == 1:
        heappush(constructions, coord)
        under_construction[coord] = True
    elif flag == -1:
        under_construction[coord] = False
    else:
        while constructions:
            x = heappop(constructions)
            if under_construction[x]: # x is the minimum coordinate under construction
                heappush(constructions, x)
                ans += str(x) + '\n'
                break
        else: # no constructions
            ans += '-1\n'
print(ans)

### FIXED CODE ###

from heapq import heappush, heappop, merge
from collections import defaultdict
import sys
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    N, Q = map(int, line_input())
    events = []
    for _ in range(N):
        s, t, x = map(int, line_input())
        events.append((s-x, 1, x))
        events.append((t-x, -1, x))
    for _ in range(Q):
        d = int(single_input())
        events.append((d, 2, d))
    events = sorted(events)

    constructions = []
    under_construction = defaultdict(bool)
    ans = ''
    for _, flag, coord in events:
        if flag == 1:
            heappush(constructions, coord)
            under_construction[coord] = True
        elif flag == -1:
            under_construction[coord] = False
        else:
            while constructions:
                x = heappop(constructions)
                if under_construction[x]: # x is the minimum coordinate under construction
                    heappush(constructions, x)
                    ans += str(x) + '\n'
                    break
            else: # no constructions
                ans += '-1\n'
    print(ans)
    
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

N, K = map(int, input().split())
p = input().split()
ex = [0 for i in range(N)]
E=0
def expectation(n):
    return (n+1)/2
def ran(n,k,i):
    if i+1>=K and N-(i) >= K:
        return K
    elif i+1 < K:
        return i+1
    else:
        return N-i

for i in range(N):
    p[i] = int(p[i])
    ex[i] = expectation(p[i])

X=N-K+1

for i in range(X):
    newE = 0
    for j in range(K):
        newE += ex[i+j]

    if newE > E:
        E = newE

    
    

print(E)



    


### FIXED CODE ###

N, K = map(int, input().split())
p = input().split()
bubun = [0 for i in range(N)]
sums= [0 for i in range(N+K)]
E=0
S=0

for i in range(N):
    p[i] = int(p[i])
    


sums[0] = p[0]
for i in range(N-1):
    sums[i+1] = sums[i] + p[i+1]

for i in range(N):
    if i == 0:
        bubun[i] = sums[K-1]
    else:
        bubun[i] = sums[i+K-1]-sums[i-1]

for i in range(N):

    if bubun[i] > S:
        S = bubun[i]


E=(S+K)/2

print(E)
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    t = deque()
    for i in s:
        t.append(i)
    q = I()
    k = 0
    for _ in range(q):
        qu = input().split()
        if qu[0] == "1":
            k ^= 1
        else:
            f,c = qu[1:]
            key = (int(f)-1)^k
            if not key:
                t.appendleft(c)
            else:
                t.append(c)
    ans = ""
    if not k:
        while t:
            ans += t.popleft()
    else:
        while t:
            ans += t.pop()
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    t = deque()
    for i in s:
        t.append(i)
    q = I()
    k = 0
    for _ in range(q):
        qu = input().split()
        if qu[0] == "1":
            k ^= 1
        else:
            f,c = qu[1:]
            key = (int(f)-1)^k
            if not key:
                t.appendleft(c)
            else:
                t.append(c)
    ans = ""
    if not k:
        while t:
            ans += t.popleft()
    else:
        while t:
            ans += t.pop()
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

"""
検討
- 閉路が存在する場合、スコアをいくらでも大きくできる可能性がある
- 閉路を1周することで得られるスコア合計の符合によってinfにできるかどうかが判定可能
  - 符合が正: inf
  - 符合が0以下: 最短でNに到達したときのスコアが解
- 閉路が複数ある場合はどうするか
  - 1周したときに得られるスコア合計の符合が正かどうかで判断

必要な処理
- 最短経路探索: ダイクストラ法? -> ベルマンフォード法（コストに正負があるため）
- 閉路を見つけ出す
- 閉路を1周したときのスコア合計
"""

n, m = map(int, input().split())
edges = []
for _ in range(m):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, -c])

inf = 10 ** 18
dist = [inf for _ in range(n)]
dist[0] = 0

for i in range(n-1):
    for edge in edges:
        if dist[edge[0]] == inf:
            continue
        if dist[edge[1]] > dist[edge[0]] + edge[2]:
            dist[edge[1]] = dist[edge[0]] + edge[2]
ans = -dist[n-1]

negative = [False for _ in range(n)]
for i in range(n):
    for edge in edges:
        if dist[edge[0]] == inf:
            continue
        if dist[edge[1]] > dist[edge[0]] + edge[2]:
            dist[edge[1]] = dist[edge[0]] + edge[2]
            negative[edge[1]] = True
        if negative[edge[0]]:
            negative[edge[1]] = True

if negative[n-1]:
    print("inf")
else:
    print(ans)


### FIXED CODE ###

"""

問題:
N 頂点 M 辺の重み付き有向グラフがあります。
i(1≦i≦M) 番目の辺は 頂点 ai から 頂点 bi を重み ciで結びます。
このグラフと駒を利用して、次の1人ゲームを行います。
最初、駒を頂点 1に置いて、プレイヤーのスコアを 0とします。
プレイヤーは、次の条件で駒を繰り返し移動させることができます。
- 頂点 aiに駒があるとき、i 番目の辺を利用して頂点 bi に移動する。移動後にプレイヤーのスコアが ci加算される。
頂点 Nに駒があるときのみ、ゲームを終了できます。
なお、与えられる有向グラフの上で頂点 1 から頂点 Nに移動できることは保障されています。
プレイヤーがゲーム終了時のスコアを出来るだけ大きくするような行動を取ったとき、ゲーム終了時のスコアはいくつになるでしょうか?
ゲーム終了時のスコアをいくらでも大きくできる場合は inf と出力してください。

制約:
- 2≦N≦1000
- 1≦M≦min(N(N−1),2000)
- 1≦ai,bi≦N(1≦i≦M)
- ai≠bi(1≦i≦M)
- ai≠ajまたは bi≠bj(1≦i<j≦M)
- −10 ** 9≦ci≦10 ** 9(1≦i≦M)
- ciは整数である。
- 与えられるグラフには、頂点 1から頂点 N への経路が存在する。

検討:
- 閉路が存在する場合、スコアをいくらでも大きくできる可能性がある
- 閉路を1周することで得られるスコア合計の符合によってinfにできるかどうかが判定可能
  - 符合が正: inf
  - 符合が0以下: 最短でNに到達したときのスコアが解
- 閉路が複数ある場合はどうするか
  - 1周したときに得られるスコア合計の符合が正かどうかで判断

必要な処理:
- 最短経路探索: ダイクストラ法? -> ベルマンフォード法（コストに正負があるため）
- 閉路を見つけ出す
- 閉路を1周したときのスコア合計

計算時間:
- ベルマンフォード法の時間計算量はO(NM)
- 解説通りにpythonで実装したらTLE判定...(約2100ms)
- 制約通りでいけば、NM = 1000 * 2000 = 2 * 10 ** 6
- 20msの化け物がいる...
"""

n, m = map(int, input().split())
edges = []
for _ in range(m):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, -c])

inf = 10 ** 18
dist = [inf for _ in range(n)]
dist[0] = 0

for i in range(n-1):
    for a, b, c in edges:
        dist[b] = min(dist[b], dist[a] + c)

for i in range(n):
    for a, b, c in edges:
        if dist[a] + c < dist[b]:
            dist[b] = -inf

if -inf == dist[-1]:
    print("inf")
else:
    print(-dist[-1])
### BUGGY CODE ###

from functools import reduce
from math import gcd

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

c=max(A)+1
D=[0]*c
div=[0]*c
P=[]

for i in range(2,c):
    if D[i]==0:
        P.append(i)
        D[i]=i
    for j in P:
        if i*j>=c  or j>D[i] :
           break
        D[i*j]=j

for i in A:
    if i==1:
        continue
    temp=i
    pt=[]
    while temp!=1:
        if D[temp] not in pt:
            div[D[temp]]+=1
        pt.append(D[temp])
        temp=temp//D[temp]

#print(div)

if max(div)<=1:
    print('pairwise coprime')

elif reduce(gcd, A) == 1:
    print('setwise coprime')

else:
    print('not coprime')

### FIXED CODE ###

from functools import reduce
from math import gcd

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

c=max(A)+1
D=[0]*c
div=[0]*c
P=[]

for i in range(2,c):
    if D[i]==0:
        P.append(i)
        D[i]=i
    for j in P:
        if i*j>=c  or j>D[i] :
           break
        D[i*j]=j
f=0
for i in A:
    if i==1:
        continue
    temp=i
    while temp!=1:
        if div[D[temp]]==1:
            f=1
            break
        div[D[temp]]+=1
        temp2=D[temp]
        while temp%temp2==0 and temp>=temp2:
            temp=temp//temp2
    if f==1:
        break
        


if max(div)<=1 and f==0:
    print('pairwise coprime')

elif reduce(gcd, A) == 1:
    print('setwise coprime')

else:
    print('not coprime')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

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

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):
    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

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

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):

    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))
### BUGGY CODE ###

import numpy as np
N = int(input())
A = [input() for i in range(N)]
a = []*N
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

count=0
ans = a[0]
for i in range(0,N):
    ans = a[i]
    for j in range(i+1,N):
        if ans == a[j]:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
A=[]
S={}
for i in range(N):
    a = list(input())
    a.sort()
    b = ''.join(a)
    if b not in S:
        S[b] = 1
    else:
        S[b] += 1


count=0
for i in S.values():
    if i==1:
        continue
    count += i*(i-1)//2
print(count)
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a,b,c=l[i],l[j],l[k]
      if abs(a-b)<c<a+b:
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  k=i
  for j in range(i+1,n):
    while k<n and l[k]<l[i]+l[j]:
      k+=1
    ans+=k-(j+1)
print(ans)
### BUGGY CODE ###

# https://atcoder.jp/contests/abc051/tasks/abc051_b

# n n,
K, S = map(int, input().split())

# initialize
ans = 0

# logic: 全探索: 基本形
for i in range(K + 1):
    if i + K + 1 + K + 1 < S:
        continue
    for j in range(K + 1):
        if i + j + K + 1 < S:
            continue
        if 0 <= S - i - j <= K:
            ans += 1

print(ans)


### FIXED CODE ###

k,s=map(int,input().split())
count=0
for a in range(k+1):
  for b in range(k+1):
    if 0<=s-a-b<=k:
      count+=1
print(count)
### BUGGY CODE ###

n =int(input())
s = [input() for i in range(n)]
z = list(set(s))
ans = []
x = 0
for i in z:
    sc = s.count(i)
    if sc > x:
        ans.clear()
        ans.append(i)
        x = sc
    elif sc == x:
        ans.append(i)
for i in sorted(ans):
    print(i)

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
  s.append(input())
s.sort()
k = 0
f = s
mk = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    k = k+1
    if k == mk :
      mk = k
      f.append(s[i])
    elif k > mk :
      mk = k
      f = [s[i]]
  else:
    k = 0
for i in range(len(f)):
  print(f[i])
### BUGGY CODE ###

from collections import defaultdict
import itertools

N=input()

Parts=defaultdict(lambda: 0)

for i in range(1,N+1):
	num_sqrt=int(i**0.5)+2

	for n in range(2,num_sqrt):
		while i%n==0:
			i/=n
			Parts[n]+=1
	else:
		if i!=1:
			Parts[i]+=1

L=[]
for x in Parts.values():
	L.append( range(x+1) )


K=list(itertools.product(*L))	#Kouho

ans=0
for x in K:
	multiple=1
	for v in x:
		multiple*=(v+1)
	if multiple==75:
		ans+=1


print ans

### FIXED CODE ###

import math
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0)

#L=(2,3,5,7)
L=range(2,101)


for i in range(N,0,-1):
	for l in L:
		while i%l==0:
			i/=l
			C[l]+=1

D=defaultdict(lambda: 0)

for x,y in C.items():
	if y>=4:	D[4]+=1
	if y>=2:	D[2]+=1
	if y>=24:D[24]+=1
	if y>=14:D[14]+=1
	if y>=74:D[74]+=1

ans=0

ans+=D[4]*(D[4]-1)/2*(D[2]-2)
ans+=D[24]*(D[2]-1)
ans+=D[14]*(D[4]-1)
ans+=D[74]
print ans
### BUGGY CODE ###

H,W=map(int,input().split())
w=[[]for i in range(H)]
for i in range(H):
  S=input()
  for j in range(W):
    w[i].append(S[j])
    
L=[[0 for i in range(W)] for j in range(H)]
R=[[0 for i in range(W)] for j in range(H)]
U=[[0 for i in range(W)] for j in range(H)]
D=[[0 for i in range(W)] for j in range(H)]

for i in range(H):
  for j in range(W):
    if w[i][j]=='#':
      L[i][j]=0
    elif j==0:
      L[i][j]=1
    else:
      L[i][j]=L[i][j-1]+1
for i in range(H):
  for j in range(W-1,-1,-1):
    if w[i][j]=='#':
      R[i][j]=0
    elif j==W-1:
      R[i][j]=1
    else:
      R[i][j]=R[i][j+1]+1
for i in range(H):
  for j in range(W):
    if w[i][j]=='#':
      D[i][j]=0
    elif i==0:
      D[i][j]=1
    else:
      D[i][j]=D[i-1][j]+1  
for i in range(H-1,-1,-1):
  for j in range(W):
    if w[i][j]=='#':
      U[i][j]=0
    elif i==H-1:
      U[i][j]=1
    else:
      U[i][j]=U[i+1][j]+1
ans=[]
for i in range(H):
  for j in range(W):
    x=L[i][j]+R[i][j]+D[i][j]+U[i][j]-3
    ans.append(x)
print(max(ans))

### FIXED CODE ###

H,W=map(int,input().split())
import heapq
w=[[0 for i in range(W)]for j in range(H)]
for i in range(H):
  S=input()
  for j in range(W):
    w[i][j]=S[j]
    
L=[[0 for i in range(W)] for j in range(H)]
R=[[0 for i in range(W)] for j in range(H)]
U=[[0 for i in range(W)] for j in range(H)]
D=[[0 for i in range(W)] for j in range(H)]

for i in range(H):
  for j in range(W):
    if w[i][j]=='#':
      L[i][j]=0
    elif j==0:
      L[i][j]=1
    else:
      L[i][j]=L[i][j-1]+1
for i in range(H):
  for j in range(W-1,-1,-1):
    if w[i][j]=='#':
      R[i][j]=0
    elif j==W-1:
      R[i][j]=1
    else:
      R[i][j]=R[i][j+1]+1
for i in range(H):
  for j in range(W):
    if w[i][j]=='#':
      D[i][j]=0
    elif i==0:
      D[i][j]=1
    else:
      D[i][j]=D[i-1][j]+1  
for i in range(H-1,-1,-1):
  for j in range(W):
    if w[i][j]=='#':
      U[i][j]=0
    elif i==H-1:
      U[i][j]=1
    else:
      U[i][j]=U[i+1][j]+1
m=0

for i in range(H):
  for j in range(W):
    x=L[i][j]+R[i][j]+D[i][j]+U[i][j]-3
    m=max(x,m)
print(m)
### BUGGY CODE ###

#%%
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp >= 0 and tmp % b == 0:
            ans += 1

print(ans)

### FIXED CODE ###

r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

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

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
for i in range(k):
    h.append(0)

dp = [float('inf')] * (n + k)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[n-1])


### FIXED CODE ###

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
for i in range(k):
    h.append(0)

dp = [float('inf')] * (n + k)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

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

import numpy as np

def Probability(p,n):
    dp = np.zeros((n+1 ,n+1)) 
    for i in range(n+1):
        for j in range(n+1):
            dp[i][j] = 0.0 
    dp[0][0] = 1.0
    
    for i in range(1,n+1):
        for j in range(i+1):
            if j==0:
                dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) 
            else : 
                dp[i][j] = (dp[i - 1][j] * (1.0 - p[i]) +
                            dp[i - 1][j - 1] * p[i])  
    ans=0.0
    for i in range((n+1)//2,n+1):
        ans+=dp[n][i]
    return ans 

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

a=[0]+a 

print(Probability(a,n))



    
        
    
    

### FIXED CODE ###


    

n=int(input())
p=list(map(float,input().split()))

 
dp = [[0 for i in range(n+1)] for j in range(n+1)]
   
dp[0][0] = 1.0

for i in range(1,n+1):
    for j in range(0,n+1):
        if j==0:
            dp[i][j] = dp[i - 1][j] * (1.0 - p[i-1]) 
        else : 
            dp[i][j] = (dp[i - 1][j] * (1.0 - p[i-1]) +
                        dp[i - 1][j - 1] * p[i-1])  
ans=0.0
for i in range((n+1)//2,n+1):
    ans+=dp[n][i]
print( ans)
### BUGGY CODE ###

n = int(input())
height = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i+height[i]-1, n):
        if(j-i == height[j] + height[i]):
            ans += 1
print(ans)


### FIXED CODE ###

from collections import defaultdict

n = int(input())
height = list(map(int, input().split()))
ans = 0

d = defaultdict(int)

for i in range(n):
    x = i+height[i]
    d[x] += 1

for i in range(n):
    x = i-height[i]
    ans += d[x]

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

import math

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

for i in range(m):
    a[a.index(max(a))] = math.floor(a[a.index(max(a))] / 2)

print(sum(a))

### FIXED CODE ###

import heapq


n, m = map(int, input().split())
a = [-int(x) for x in input().split()]

heapq.heapify(a)

for i in range(m):
    t = -heapq.heappop(a)
    heapq.heappush(a, (t // 2) * (-1))

print(-sum(a))
### BUGGY CODE ###

_input = input().split()
n = int(_input[0])
k = int(_input[1])

input_hp = input().split()

list_monster = []
for i in range(n):
  list_monster.append(int(input_hp[i]))
  
list_monster.sort() 
list_monster.reverse() #降順にソート

#使用できる必殺技の残りカウント
count = k 
  
if n <= k:
  print(0)
else:
  for i in range(k): #最初に持っていた必殺技の数だけ繰り返す
    count -= 1 #使用ごとに必殺技の残りカウントを減らす
    
    list_monster.pop(0)
    
  number = 0

  for i in range(len(list_monster)):
  	number += list_monster[i]

  print(number)

### FIXED CODE ###

N, K = map(int, input().split())
 
list_monster = list(map(int, input().split()))
list_monster.sort(reverse = True) 
 
if N <= K:
  print(0)
  
elif K == 0:
  print(sum(list_monster))
  
else:
  print(sum(list_monster[K:]))
### BUGGY CODE ###

N,K = map(int,input().split())
A = [0] + [int(i) for i in input().split()]

route = [1]
start = 1
cnt = 0
while True:
  if cnt == K:
    print(route[-1])
    exit()
  elif A[start] in route:
    index = route.index(A[start])
    loop = len(route) - index
    break
  else:
    route.append(A[start])
    start = A[start]
    cnt += 1

K -= index
K = K % loop
print(route[index:][K])

### FIXED CODE ###

N,K = map(int,input().split())
A = [0] + [int(i) for i in input().split()]

route = [1]
route_set = set()
start = 1
cnt = 0
while True:
  if cnt == K:
    print(route[-1])
    exit()
  elif A[start] in route_set:
    index = route.index(A[start])
    loop = len(route) - index
    break
  else:
    route.append(A[start])
    route_set.add(A[start])
    start = A[start]
    cnt += 1

K -= index
K = K % loop
print(route[index:][K])
### BUGGY CODE ###

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

flg=1               #N枚のお札の合計金額がY円となることがありえない場合
for i in range(N+1):
    for j in range(N-i+1):
        for k in range(N-i-j+1):
            if i+j+k==N and 10000*i+5000*j+1000*k==Y:
                flg=0
                x=i
                y=j
                z=k
if flg==1:
    print('-1 -1 -1')
else:
    print(x,end=" ")
    print(y,end=" ")
    print(z)



### FIXED CODE ###

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

flg=1               #N枚のお札の合計金額がY円となることがありえない場合
for i in range(N+1):
    for j in range(N-i+1):
        k=N-(i+j)
        if 10000*i+5000*j+1000*k==Y:
            flg=0
            x=i
            y=j
            z=k
if flg==1:
    print('-1 -1 -1')
else:
    print(x,end=" ")
    print(y,end=" ")
    print(z)
### BUGGY CODE ###

N=int(input())

ya = []

for i in range(1,N+1):
    if N % i == 0:
        ya.append(i)
answer=[]

lenarray=len(ya)
if lenarray%2==0:
  for i in range(lenarray//2):
    x=ya.pop(0)+ya.pop(-1)
    answer.append(x)
else:
  for i in range((lenarray-1)//2):
    x=ya.pop(0)+ya.pop(-1)
    answer.append(x)


  y=ya[0]
  answer.append(y*2)
  
print(min(answer)-2)


### FIXED CODE ###

n=int(input())
xlist=[]
 
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        xlist.append(i)
 
ans=max(xlist)
print(int(ans+n/ans-2))
### BUGGY CODE ###

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

delKeta = N-3
ans = []
for V3 in range(10):
    for i in range(N):
        if(V3==int(S[i])):
            p1=i
            for V2 in range(10):
                for j in range(p1+1,N):
                    if(V2==int(S[j])):
                        p2=j
                        for V1 in range(10):
                            for k in range(p2+1,N):
                                if(V1==int(S[k])):
                                    ans.append(S[k]+S[p2]+S[p1])
                                    break
                        break
            break
                



print(len(set(ans)))



### FIXED CODE ###

N = int(input())
S = list(map(int,input()))
count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)