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

n,k = map(int,input().split())
h = list(map(int,input().split()))
if k > len(h):
    print(0)
else:
    for i in range(k):
        h.remove(max(h))
    print(sum(h))

### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
H = sorted(h, reverse=True)
if k >= len(H):
    print(0)
if k<len(H):
    del H[:k]
    print(sum(H))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Oct  7 22:06:12 2018
ABC073D
@author: maezawa
"""
import itertools as itr
import sys
input = sys.stdin.readline

n, m, r = list(map(int, input().split()))
rarray = list(map(int, input().split()))
adjmatrix = [[10**10]*n for _ in range(n)]
#for i in range(n):
#    adjmatrix[i][i] = 0
    
for i in range(m):
    a, b, c = list(map(int, input().split()))
    adjmatrix[a-1][b-1] = c
    adjmatrix[b-1][a-1] = c

#print(abc)

# Warshall-Floyd Algorithm
for k in range(n):
    for i in range(n):
        for j in range(n):
            if adjmatrix[i][j] > adjmatrix[i][k] + adjmatrix[k][j]:
                adjmatrix[i][j] = adjmatrix[i][k] + adjmatrix[k][j]
                adjmatrix[j][i] = adjmatrix[i][k] + adjmatrix[k][j]
        
#print(*adjmatrix, sep='\n')
    
# search for ri to rj
mincnt = 10*10
for route in itr.permutations(rarray):
    cnt = 0
    for i in range(len(rarray)-1):
        cnt += adjmatrix[route[i]-1][route[i+1]-1]
    if cnt < mincnt:
        mincnt = cnt

print(mincnt)
        
        

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Oct  8 10:17:39 2018

@author: maezawa
"""

import math
from itertools import permutations

#フロイド・ワーシャル
def warshall_floyd(glath):
	
	for k in range(len(glath)):
		for i in range(len(glath)):
			for j in range(len(glath[i])):
				if glath[i][j] > glath[i][k] + glath[k][j]:
                                   glath[i][j] = glath[i][k] + glath[k][j]
                                   glath[j][i] = glath[i][k] + glath[k][j]				
	return glath

N, M ,R= [int(x) for x in str(input()).split()]  #グラフの大きさ 
r=[int(x) for x in str(input()).split()]
graph=[[float("inf")]*N for i in range(N)]


for i in range(M):
	a,b,c=[int(x) for x in str(input()).split()]
	#if a in r and b in r:
	graph[a-1][b-1]=c
	graph[b-1][a-1]=c

#all_cost=warshall_floyd(select_graph)
all_cost=warshall_floyd(graph)


max_count=float("inf")
for i in permutations(r):
        cost=0
        for j in range(len(i)-1):                
                cost+= all_cost[i[j]-1][i[j+1]-1]       
        max_count=min(max_count,cost)

print(max_count)
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
import bisect
for i in range(M):
    bisect.insort(A,A[-1]/2)
    A.pop(-1)
for i in range(N):
    A[i] = int(A[i])
print(sum(A))

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
import bisect
for i in range(M):
    bisect.insort(A,A[-1]/2)
    A.pop(-1)
for i in range(N):
    A[i] = int(A[i])
print(sum(A))
### BUGGY CODE ###






# numss = [[] for i in range(n+1)]
# def f(num,pos):
# 	if pos == n+1:
# 		return
# 	numss[pos].append(num)
# 	f(num,pos+1)
# 	if pos < n:
# 		f(num^a[pos],pos+1)

# f(0,0)


# i = 0
# for nums in numss:
# 	if i < n:
# 		print("{},{}: ".format(s[i],a[i]),end="")
# 	else:
# 		print("     ",end="")
# 	for num in nums:
# 		print("{num:^{w}}".format(num=num,w=2**(n+1-i)),end='')
# 	print()
# 	i += 1


def f():
	n = int(input())
	a = list(map(int,input().split()))+[]
	s = input()
	dp = [0]
	for i in reversed(range(n)):
		# print(i,dp)
		if s[i] == '0':
			dp = dp + [v^a[i] for v in dp]
		else:
			if not a[i] in dp:
				dp = []
	# print(dp)
	if dp == []:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	f()

### FIXED CODE ###

for _ in range(int(input())):
	input()
	*a, = map(int,input().split())
	s = input()
	b=[]
	ans=0
	for x,p in zip(a[::-1],s[::-1]):
		for y in b:
			x=min(x,x^y)
		if x:
			if p=="1":
				ans=1
				break
			b.append(x)
	print(ans)
### BUGGY CODE ###

import numpy as np
MOD = 10**9 + 7
def solve(n, a, p=60):
    b = [np.asarray(list(bin(x)[2:].zfill(p)), dtype=int) for x in a]
    b = np.asarray(b, dtype=int)
    s = np.sum(b, axis=0)
    res = sum(int(s[i]) * int(n - s[i]) * (2**(p-1-i)) for i in range(p))
    return res % MOD

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

### FIXED CODE ###

MOD = 10**9 + 7
def solve(n, a, p=60):
    res, m = 0, 1
    for i in range(p):
        y = sum(x & m for x in a) // m
        res += y * (n-y) * m
        m *= 2
    return res % MOD

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

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
for i in range(n):
    cur = i
    l2 = []
    l3 = []
    score = 0
    cnt = 0
    while True:
        if p[i] - 1 in l2:
            score += c[p[i] - 1]
            l3.append(score)
            break
        l2.append(i)
        score += c[p[i] - 1]
        l3.append(score)
        i = p[i] - 1
        cnt += 1
    l.append([l3, cnt + 1])
A = []
for i in range(n):
    x, y = l[i][0], l[i][1]
    ans = 0
    if x[-1] < 0:
        if k >= y:
            ans = max(x)
        else:
            if k % y == 0:
                pass
            else:
                ans = max(x[:k % y])
    else:
        ans = x[-1] * (k // y)
        if k % y == 0:
            pass
        else:
            ans += max(x[:k % y])
    A.append(ans)
print(max(A))

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
l = [[] for i in range(n)]
for i in range(n):
    l2 = [i + 1]
    cnt = 0
    while True:
        l2.append(p[l2[-1] - 1])
        cnt += c[l2[-1] - 1]
        l[i].append(cnt)
        if l2[-1] == i + 1:
            break
ans = -float("inf")
for i in range(n):
    le = len(l[i])
    for j in range(min(k, le)):
        cnt = l[i][j]
        if l[i][-1] > 0:
            cnt += (k - j - 1) // le * l[i][-1]
        ans = max(ans, cnt)
print(ans)
### BUGGY CODE ###

import sys
import collections


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, input().rstrip('\n').split()))
    a = [list(str(input().rstrip('\n'))) for _ in range(h)]
    ql = []
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                ql.append([0, i, j])
                fq[i, j]

    mt = 0
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            mt = max(mt, cost)
            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if (xv, yv) not in fq and a[xv][yv] == ".":
                        ql.append([cost + 1, xv, yv])
                        fq[xv, yv]
        else:
            break
    print(mt)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [[True] * w for _ in range(h)]
    ql = collections.deque()
    for i in range(h):
        s = list(str(readline().rstrip().decode('utf-8')))
        for j in range(w):
            if s[j] == "#":
                ql.append([0, i, j])
                a[i][j] = False
    while ql:
        cost, x, y = ql.popleft()
        for xv, yv in ((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)):
            if 0 <= xv < h and 0 <= yv < w:
                if a[xv][yv]:
                    ql.append([cost + 1, xv, yv])
                    a[xv][yv] = False
    print(cost)


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

N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])

### FIXED CODE ###

def main():
    n, s = map(int, input().split())
    mod = 998244353
    a = list(map(int, input().split()))
    dp = [[0]*(s+1) for _ in range(n+1)]
    dp[0][0] = 1
    dio = dp[0]
    for i in range(1, n+1):
        ai = a[i-1]
        di = dp[i]
        for j in range(min(s+1, ai)):
            di[j] = (di[j]+2*dio[j])%mod
        for j in range(ai, s+1):
            di[j] = (di[j]+2*dio[j]+dio[j-ai])%mod
        dp[i] = di
        dio = di
    print(dp[n][s])
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys

# import bisect
# import numpy as np
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
# import bisect
# import math
import itertools
from collections import Counter
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    mod =998244353
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    dp =[[0]*(S+1) for _ in range(N+1)]
    dp[0][0]=1
    for i in range(0,N):
        for j in range(S+1):
            if A[i]>j:
                dp[i+1][j] =dp[i][j]*2
                dp[i+1][j] %= mod
            else:
                dp[i+1][j] = dp[i][j]*2 + dp[i][j-A[i]]
                dp[i+1][j] %= mod
    print(dp[N][S]%mod)
    pass



if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

# import bisect
# import numpy as np
from collections import deque
# map(int, sys.stdin.read().split())



def input():
    return sys.stdin.readline().rstrip()


def main():
    mod =998244353
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    dp =[[0]*(S+1) for _ in range(N+1)]
    dp[0][0]=1
    for i in range(0,N):
        for j in range(S+1):
            if A[i]>j:
                dp[i+1][j] =dp[i][j]*2
                dp[i+1][j] %= mod
            else:
                dp[i+1][j] = dp[i][j]*2 + dp[i][j-A[i]]
                dp[i+1][j] %= mod
    print(dp[N][S])
    pass



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

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(i - k, 0), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(i - k, 0), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])
### BUGGY CODE ###

def main():
    s = input()
    t = input()
    dp = [[0]*(len(s)+1) for _ in range((len(t)+1))]
    ans = ""
    for i in range(len(t)):
        for j in range(len(s)):
            tmp1 = dp[i+1][j]
            tmp2 = dp[i][j+1]
            tmp3 = dp[i][j]
            if t[i] == s[j]:
                tmp3 += 1
            dp[i+1][j+1] = max(tmp1,tmp2,tmp3)
    i = len(t)
    j = len(s)
    while i > 0 and j > 0:
        if dp[i-1][j-1]+1 == dp[i][j] and t[i-1] == s[j-1]:
            ans += t[i-1]
            i -= 1
            j -= 1
        elif dp[i-1][j] == dp[i][j]:
            i -= 1
        else:
            j -= 1
    print(ans[::-1])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    s = input()
    t = input()
    dp = [[0]*(len(s)+1) for _ in range((len(t)+1))]
    ans = ""
    for i in range(len(t)):
        for j in range(len(s)):
            tmp1 = dp[i+1][j]
            tmp2 = dp[i][j+1]
            tmp3 = dp[i][j]
            if t[i] == s[j]:
                tmp3 += 1
            dp[i+1][j+1] = max(tmp1,tmp2,tmp3)
    i = len(t)
    j = len(s)
    while i > 0 and j > 0:
        if dp[i-1][j-1]+1 == dp[i][j] and t[i-1] == s[j-1]:
            ans += t[i-1]
            i -= 1
            j -= 1
        elif dp[i-1][j] == dp[i][j]:
            i -= 1
        else:
            j -= 1
    print(ans[::-1])

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

import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
# x = int(input())
a, b, n = list(map(int, input().split()))
ans = a*n//b - a*(n//b)

# for i in range(n, int(math.sqrt(n))-1, -1):
for i in range(n, int(pow(n, 0.75))-1, -1):
    if ans < a*i//b - a*(i//b):
        ans = a*i//b - a*(i//b)
    #print(ans, end=" ")
    #print(a*i//b - a*(i//b))

print(ans)


### FIXED CODE ###

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

x = min(b-1, n)
ans = a*x//b - a*(x//b)

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

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

ans = S.count("R") * S.count("G") * S.count("B")

res = 0
for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if i+2*d < N and set([S[i], S[i+d], S[i+2*d]]) == {"R", "G", "B"}:
            ans -= 1
print(ans)


### FIXED CODE ###

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

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

n = int(input())

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

Flag = True

for i in range(n):
  for j in range(n):
    if i != j and a[i] == a[j]:
      print('NO')
      Flag = False
      break
  if Flag == False:
    break
if Flag:
  print('YES')

### FIXED CODE ###

n = int(input())

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

Flag = True

a = sorted(a)

for i in range(n-1):
  if a[i] == a[i+1]:
    print('NO')
    Flag = False
    break
  
if Flag:
  print('YES')
### BUGGY CODE ###

MOD = 10**9+7
s = input()
#ind = list(range(len(s)))
dsl = list(s)
#print(sl)
#dsl = dict(zip(ind, sl))
#print(dsl)

#ind2 = list(range(13))
#dp={}
##dp.setdefault(0, dict(zip(ind2,[0]*13)))
#for i in range(len(s)+1):
    ##dp.append(dict(zip(ind2,[0]*13)))
    #dp.setdefault(i, dict(zip(ind2,[0]*13)))
dp=[[0]*13]
for i in range(len(s)):
    dp.append([0]*13)

#print(dp)
dp[0][0]=1

for i in range(len(s)):
    for k in range(10):
        if dsl[i] != "?" and dsl[i] != str(k):
            continue
        for j in range(13):
            dp[i+1][(j*10+k)%13] += dp[i][j]%MOD
    #for k in range(13):
    #    dp[i+1][k] %= MOD

#print(dp)
print(dp[len(s)][5]%MOD)


### FIXED CODE ###

MOD = 10**9+7
s = input()
ind = list(range(len(s)))
sl = list(s)
#print(sl)
dsl = dict(zip(ind, sl))
#print(dsl)

ind2 = list(range(13))
dp={}
#dp.setdefault(0, dict(zip(ind2,[0]*13)))
for i in range(len(s)+1):
    #dp.append(dict(zip(ind2,[0]*13)))
    dp.setdefault(i, dict(zip(ind2,[0]*13)))


#print(dp)
dp[0][0]=1

for i in range(len(s)):
    for k in range(10):
        if dsl[i] != "?" and dsl[i] != str(k):
            continue
        for j in range(13):
            dp[i+1][(j*10+k)%13] += dp[i][j]%MOD
    #for k in range(13):
    #    dp[i+1][k] %= MOD

#print(dp)
print(dp[len(s)][5]%MOD)
### BUGGY CODE ###

import math

def search(S):

    for i, a in enumerate(A):
        if a < S:
            A[i] = S
            return 
    return



def main():
    N = int(input())
    A[0] = int(input())
    m = A[0]
    for _ in range(N-1):
        S = int(input())
        if S <= m:
            A.append(S)
        else:
            search(S)
        m = A[-1]
    print(len(A))

    

if __name__ == "__main__":
    A = [0]
    main()


### FIXED CODE ###

from bisect import bisect


def main():
    N = int(input())
    A = [-int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a >= L[-1]:
            L.append(a)
        else:
            L[bisect(L, a)] = a
    print(len(L))


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

import itertools


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

scores = [list(map(int,input().split())) for _ in range(n) ]

max_socre = 0
for cakes in itertools.combinations(scores, m):
    b = 0
    t = 0
    p = 0
    for cake in cakes:
        b += cake[0]
        t += cake[1]
        p += cake[2]

    score = abs(b) + abs(t) + abs(p)
    if score > max_socre:
        max_socre = score

print(max_socre)



### FIXED CODE ###

import itertools


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

scores = [list(map(int,input().split())) for _ in range(n) ]

# 8 pattern

max_of_sum = 0
for pick in range(8):
    sum_scores = []
    for score in scores:
        sum_of_score = 0
        if pick & 0b001 == 0:
            # plus
            sum_of_score += score[0]
        else:
            sum_of_score -= score[0]

        if pick & 0b010 == 0:
            # plus
            sum_of_score += score[1]
        else:
            sum_of_score -= score[1]

        if pick & 0b100 == 0:
            # plus
            sum_of_score += score[2]
        else:
            sum_of_score -= score[2]

        sum_scores.append(sum_of_score)

    sum_scores.sort(reverse=True)
    current_sum = sum(sum_scores[:m])
    if current_sum > max_of_sum:
        max_of_sum = current_sum

print(max_of_sum)
### BUGGY CODE ###

import itertools
import heapq
import sys
import functools
import operator
import numpy as np
input = sys.stdin.readline
#-------------
n,k = map(int,input().split())
a = list(map(int,input().split()))
#-------------
a.sort()
D = [[a[i+j-k] for j in range(k)] for i in range(n-1)]
A = (functools.reduce(operator.mul,D[_]) for _ in range(len(D)))
l_max = max(A)
waru = 10**9 + 7
print(l_max % waru)

### FIXED CODE ###

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(n-k+1):
    e = (sum(p[i:i+k]) + k) / 2
    if ans < e:
        ans = e
print(ans)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

s_list = [0]*(n+1)
s_list[1] = p[0]
for i in range(1, n+1):
    s_list[i] = p[i-1] + s_list[i-1]

for i in range(n-k+1):
    e = (s_list[i+k] - s_list[i] + k)/2
    if ans < e:
        ans = e
print(ans)
### BUGGY CODE ###

from collections import defaultdict


def dfs(graph, start):
    visited, stack = set(), [start]
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex] - visited)
    return visited


if __name__ == "__main__":
    n, m, k = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(m)]
    CD = [map(int, input().split()) for _ in range(k)]

    graph_f = defaultdict(set)
    graph_b = defaultdict(set)

    for a, b in AB:
        graph_f[a - 1].add(b - 1)
        graph_f[b - 1].add(a - 1)

    for c, d in CD:
        graph_b[c - 1].add(d - 1)
        graph_b[d - 1].add(c - 1)

    searched = set()
    conns = []
    for i in range(n):
        if i not in searched:
            conn = dfs(graph_f, i)
            searched |= conn
            conns.append(conn)

    res = [0] * n
    for conn in conns:
        for i in conn:
            res[i] = len(conn - graph_f[i] - graph_b[i]) - 1

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


### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnt = [0] * n
    b_cnt = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        u.union(a - 1, b - 1)
        f_cnt[a - 1] += 1
        f_cnt[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if u.same(c - 1, d - 1):
            b_cnt[c - 1] += 1
            b_cnt[d - 1] += 1

    print(*[(u.size(i) - f_cnt[i] - b_cnt[i] - 1) for i in range(n)])
### BUGGY CODE ###

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

# ユークリッドの互除法により最大公約数を求める
ans = 0
val1, val2 = a[0], a[1]
while 1:
  if val1 % val2 == 0:
    ans = a[0]*a[1]/val2
    break
  else:
    tmp = val2
    val2 = val1 % val2
    val1 = tmp

for i in range(2, N):
  val1, val2 = ans, a[i]
  while 1:
    if val1 % val2 == 0:
      ans = ans*a[i]/val2
      break
    else:
      tmp = val2
      val2 = val1 % val2
      val1 = tmp

f_ans = 0
for i in range(N):
  f_ans += (ans-1)%a[i]
print(int(f_ans))
  
      
  

### FIXED CODE ###

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

# ユークリッドの互除法により最大公約数を求める
ans = 0
val1, val2 = a[0], a[1]
while 1:
  if val1 % val2 == 0:
    ans = a[0]*a[1]//val2
    break
  else:
    tmp = val2
    val2 = val1 % val2
    val1 = tmp

for i in range(2, N):
  val1, val2 = ans, a[i]
  while 1:
    if val1 % val2 == 0:
      ans *= a[i]//val2
      break
    else:
      tmp = val2
      val2 = val1 % val2
      val1 = tmp

f_ans = 0
for i in range(N):
  f_ans += (ans-1)%a[i]
print(int(f_ans))
### BUGGY CODE ###

N, Q = map(int, input().split())
s = input()
T = []
D = []
for i in range(Q):
    t, d = input().split()
    T.append(t)
    D.append(d)

s_idx = {}
s_inv = {}
for i in range(N):
    if(s[i] in s_idx):
        s_idx[s[i]] = s_idx[s[i]] + [i]
        s_inv[s[i]] = [i] + s_idx[s[i]]
    else:
        s_idx[s[i]] = [i]
        s_inv[s[i]] = [i]
#print("s_idx={}".format(s_idx))

golems = [1] * N
g_num = N
for idx in range(Q):
#    print("spl={}, {}".format([T[idx], D[idx]], T[idx] in s_idx))
    if(True != (T[idx] in s_idx)):
        continue
    if("L" == D[idx]):
        for i in s_idx[T[idx]]:
            if(0 == i):
                g_num -= golems[i]
            else:
                golems[i - 1] += golems[i]
            golems[i] = 0
    elif("R" == D[idx]):
        for i in s_inv[T[idx]]:
            if(N - 1 == i):
                g_num -= golems[i]
            else:
                golems[i + 1] += golems[i]
            golems[i] = 0

print(str(g_num))


### FIXED CODE ###

N, Q = map(int, input().split())
s = " " + input() + " "
td = []
for i in range(Q):
    td.append(input().split())
#print("td = {}".format(td))

llim = 0
rlim = N + 1
for t, d in reversed(td):
    if((s[llim + 1] == t) and ("L" == d)):
        llim += 1
    elif((s[llim] == t) and ("R" == d)):
        llim -= 1
    if((s[rlim - 1] == t) and ("R" == d)):
        rlim -= 1
    elif((s[rlim] == t) and ("L" == d)):
        rlim += 1
#    print("td = {}, llim = {}, rlim = {}".format([t, d], llim, rlim))

print(str(max(0, rlim - llim - 1)))