Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def solve(a):
    ans = 1
    for i in a:
        ans *= i
    if ans > 10**18:
        return -1
    else:
        return ans

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(a))

Fixed submission:
def solve(a):
    if 0 in a:
        return 0
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            return -1
    else:
        return ans

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(a))
Buggy python submission (verdict: Runtime Error):
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
lis1 = deque(lis[:N//2+1])
lis2 = deque(lis[N//2+1:])
if M % 2 == 0:
    
    for i in range(M//2):
        a = lis1.popleft
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft
        b = lis2.pop()
        print(a,b)
else:
    for i in range(M//2+1):
        a = lis1.popleft
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft
        b = lis2.pop()
        print(a, b)



Fixed submission:
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
lis1 = deque(lis[:N//2+1])
lis2 = deque(lis[N//2+1:])
if M % 2 == 0:
    
    for i in range(M//2):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a,b)
else:
    for i in range(M//2+1):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a, b)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
if M % 2 == 0:
    lis1 = lis[:N//2+1]
    lis2 = lis[N//2+1:]
    for i in range(M//2):
        a = lis1.pop(0)
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.pop(0)
        b = lis2.pop()
        print(a,b)
else:
    lis1 = lis[:N//2+1]
    lis2 = lis[N//2+1:]
    for i in range(M//2+1):
        a = lis1.pop(0)
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.pop(0)
        b = lis2.pop()
        print(a, b)



Fixed submission:
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
lis1 = deque(lis[:N//2+1])
lis2 = deque(lis[N//2+1:])
if M % 2 == 0:
    
    for i in range(M//2):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a,b)
else:
    for i in range(M//2+1):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a, b)
Buggy python submission (verdict: Runtime Error):
N = int(input())

tprev = 0
xprev = 0
yprev = 0

result = 'YES'

for i in range(N):
    t, x, y = map(int, input())

    xlen = x - xprev
    ylen = y - yprev
    
    time = t - tprev

    length = xlen + ylen

    if time%2 == length%2 and time >= length:
        tprev = t
        xprev = x
        yprev = y

    else:
        result = 'NO'
        break
print(result)


Fixed submission:
N = int(input())

tprev = 0
xprev = 0
yprev = 0

result = 'Yes'

for i in range(N):
    t, x, y = map(int, input().split())

    xlen = abs(x - xprev)
    ylen = abs(y - yprev)
    
    time = t - tprev

    length = xlen + ylen

    if time%2 == length%2 and time >= length:
        tprev = t
        xprev = x
        yprev = y

    else:
        result = 'No'
        break
print(result)
Buggy python submission (verdict: Runtime Error):
import sys
import pprint
sys.path.append('C:\\ARIHON')

from Kraskal import compute_mst_kruskal
import UnionFind
import array
import collections
from operator import itemgetter
 
Edge = collections.namedtuple("Edge", "start end weight")

def main():
    n = int(input())
    l = []
    for i in range(n):
        x,y = map(int,input().split())
        l.append((x,y,i))
    
    edges = []

    lxsort = sorted(l,key=itemgetter(0))
    for i in range(n-1):
        edges.append(Edge(lxsort[i][2],lxsort[i+1][2],lxsort[i+1][0]-lxsort[i][0]))
    
    lysort = sorted(l,key=itemgetter(1))
    for i in range(n-1):
        edges.append(Edge(lysort[i][2],lysort[i+1][2],lysort[i+1][1]-lysort[i][1]))
    
    mst = compute_mst_kruskal(n,edges)

    print(sum(edge.weight for edge in mst))
 
if __name__ == '__main__':
    main()

Fixed submission:
import sys
import pprint
sys.path.append('C:\\ARIHON')

# from Kraskal import compute_mst_kruskal
# import UnionFind
import array
import collections
from operator import itemgetter

class UnionFind(object):
 
    def __init__(self, number_of_nodes):  # 初期化
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))
 
    def root(self, node):  # 根を求める
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r  # 経路圧縮
            return r
 
    def in_the_same_set(self, node1, node2):  # 同じ集合に属するか
        return self.root(node1) == self.root(node2)
 
    def unite(self, node1, node2):  # 属する集合を併合
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
 
# Kruskal法により最小全域木を求める
def compute_mst_kruskal(max_v, edges):
    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(max_v)
    mst = []
    for edge in edges:
        if not uf.in_the_same_set(edge.start, edge.end):
            uf.unite(edge.start, edge.end)
            mst.append(edge)
    return mst
 
Edge = collections.namedtuple("Edge", "start end weight")

def main():
    n = int(input())
    l = []
    for i in range(n):
        x,y = map(int,input().split())
        l.append((x,y,i))
    
    edges = []

    lxsort = sorted(l,key=itemgetter(0))
    for i in range(n-1):
        edges.append(Edge(lxsort[i][2],lxsort[i+1][2],lxsort[i+1][0]-lxsort[i][0]))
    
    lysort = sorted(l,key=itemgetter(1))
    for i in range(n-1):
        edges.append(Edge(lysort[i][2],lysort[i+1][2],lysort[i+1][1]-lysort[i][1]))
    
    mst = compute_mst_kruskal(n,edges)

    print(sum(edge.weight for edge in mst))
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

def solve(n,a):
    res = -float('inf')
    for k in range(n,2*n+1):
        a1 = a[:k]
        a2 = [-a[i] for i in range(k,3*n)]

        heapq.heapify(a1)
        heapq.heapify(a2)

        while len(a1) > n:
            heapq.heappop(a1)
        while len(a2) > n:
            heapq.heappop(a2)
        
        tmp = sum(a1) + sum(a2)

        res = max(res,tmp)

    return res

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(n,a))

Fixed submission:
import heapq

def solve(n,a):
    a1 = a[:n]
    a2 = [-a[i] for i in range(2*n,3*n)]

    l = [[0,0] for i in range(n+1)]

    heapq.heapify(a1)
    heapq.heapify(a2)

    l[0][0] = sum(a1)
    l[n][1] = sum(a2)
    
    for k in range(n,2*n):

        heapq.heappush(a1,a[k])
        tmp = heapq.heappop(a1)
        l[k-n+1][0] = l[k-n][0] + a[k] - tmp

        heapq.heappush(a2,-a[3*n-k-1])
        tmp = heapq.heappop(a2)
        l[2*n-k-1][1] = l[2*n-k][1] - a[3*n-k-1] - tmp

    res = -float('inf')

    for ans in l:
        res = max(res,ans[0]+ans[1])

    return res

if __name__ == '__main__':
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(n,a))
Buggy python submission (verdict: Runtime Error):
import itertools

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

lis = [[] for i in range(N)]

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

count = 0
for i in itertools.permutations(list(range(1,N)),N-1):
    s = 0
    for j in range(N-1):
        if i[j] not in lis[s]:
            break
        
        s = i[j]
    else:
        count += 1
    

print(count)

Fixed submission:
import itertools

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

path = [[False] * N for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    path[a-1][b-1] = True
    path[b-1][a-1] = True

count = 0
for i in itertools.permutations(list(range(N)),N):
    if i[0] == 0:
        for j in range(N):
            if j == N-1:
                count += 1
                break
            if not path[i[j]][i[j+1]]:
                break
    

print(count)
Buggy python submission (verdict: Runtime Error):
import math

k, s = map(int, imput().split())

res = 0

for x in range(k+1):
    for y in range(k+1):
        if x+y < s:
            z = s - x - y
            res += 1

print(res)

Fixed submission:
import math

k, s = map(int, input().split())

res = 0

for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            res += 1

print(res)

Buggy python submission (verdict: Runtime Error):
import math

k, s = map(int, imput().split())

res = 0

for x in range(k+1):
    for y in range(k+1):
        if x+y < s:
            z = s - x - y
            res += 1

print(res)

Fixed submission:
import math

k, s = map(int, input().split())

res = 0

for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            res += 1

print(res)
Buggy python submission (verdict: Runtime Error):
def milor(a,b):
    if a == b:
        return a
    if a > b:
        a,b = b,a
    return milor(b-a,a) + 2*a

def solve(n,x):
    res = n + milor(x,n-x)
    return res



if __name__ == '__main__':
    n,x = map(int,input().split())
    print(solve(n,x))

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def solve(n,x):
    res = 3 * (n - gcd(n,x))
    return res



if __name__ == '__main__':
    n,x = map(int,input().split())
    print(solve(n,x))
Buggy python submission (verdict: Runtime Error):
import itertools

h, w, k = map(int, input().split())
s = 0
l= []
for _ in range(h):
    a = list(map(int, input().split()))
    s += a.count("#")
    l.append(a)
if (k > s):
    print(0)
else:
    ans=0
    for pair in itertools.combinations([0, 1], h + w):
        hx = pair[:h]
        wx = pair[h + 1 :]
        if (sum(wx) == 0):
         ans=ans+1
    print(ans)

Fixed submission:
  
import copy
from itertools import combinations
h, w, k = map(int, input().split())
c =[input() for i in range(h)]
ans = 0
y = []
for i in range(h):
    y.append(i)
x = []
for i in range(w):
    x.append(i)
for i in range(h+1):
    ty = list(combinations(y, i))
    for j in range(w+1):
        tx = list(combinations(x, j))
        for l in ty:
            for m in tx:
                cnt = 0
                for p in l:
                    for q in m:
                        if c[p][q] == '#':
                            cnt += 1
                if cnt == k:
                    ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

h, w, k = map(int, input().split())
s = 0
l= []
for _ in range(h):
    a = list(map(int, input().split()))
    s += a.count("#")
    l.append(a)
if (k > s):
    print(0)
else:
    for pair in itertools.combinations([0, 1], h + w):
        hx = pair[:h]
        wx = pair[h + 1 :]
        if (sum(wx) == 0):


Fixed submission:
  
import copy
from itertools import combinations
h, w, k = map(int, input().split())
c =[input() for i in range(h)]
ans = 0
y = []
for i in range(h):
    y.append(i)
x = []
for i in range(w):
    x.append(i)
for i in range(h+1):
    ty = list(combinations(y, i))
    for j in range(w+1):
        tx = list(combinations(x, j))
        for l in ty:
            for m in tx:
                cnt = 0
                for p in l:
                    for q in m:
                        if c[p][q] == '#':
                            cnt += 1
                if cnt == k:
                    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):

import itertools

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


n, m, q = map(int, input().split())
query = []
for i in range(q):
    query.append(list(map(int, input().split())))

choices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))
ans = -1
for choice in choices:
    score = 0
    for q in query:
        if choice[q[1]-1] - choice[q[0]-1] == q[2]:
            score += q[3]
    ans = max(ans, score)
print(ans)

Fixed submission:

import itertools


n, m, q = map(int, input().split())
query = []
for i in range(q):
    query.append(list(map(int, input().split())))

choices = list(itertools.combinations_with_replacement([i for i in range(1, m+1)], n))
ans = -1
for choice in choices:
    score = 0
    for q in query:
        if choice[q[1]-1] - choice[q[0]-1] == q[2]:
            score += q[3]
    ans = max(ans, score)
print(ans)
Buggy python submission (verdict: Runtime Error):
mport math
def check(lis,k,mid):
	for i in lis:
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)/2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-0.000001
	else:
		a=mid+0.000001
print(int(math.ceil(ans)))

Fixed submission:
def check(lis,k,mid):
	for i in lis:
		if(i%mid==0):
			k+=1
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)

Buggy python submission (verdict: Runtime Error):
def check(lis,k,mid):
	for i in lis:
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=0,max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)



Fixed submission:
def check(lis,k,mid):
	for i in lis:
		if(i%mid==0):
			k+=1
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,k=list(map(int,input().split()))
ans=0
curr=1
t=m-n+k+1
for i in range(n-k):
    curr=(curr*t)%998244353
    t+=1
t=m-n+k+1   
ans=max(0,curr)
for i in range(k+1):
    t-=1
    if t>0:
        curr=(curr*t)%998244353
    if curr>0:
        ans=(ans+curr)%998244353
print(ans)







Fixed submission:
b=input()
a=input()
# print(a[:-1])
if len(a)==(len(b)+1) and a[:-1]==b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=float(input())
print(int(a*b))


Fixed submission:
import decimal
a,b=input().split()
a=int(a)
b=decimal.Decimal(b)
print(int(a*b))
Buggy python submission (verdict: Runtime Error):
money=int(input())
if(ceil(money/1000.0)==floor(money/1000.0)):
  print("0")
elif(ceil(money/1000.0)>floor(money/1000.0)):
  print(money%1000)
else:
  print(1000-(money%1000))
  

Fixed submission:
import math as m
money=int(input())
if(m.ceil(money/1000.0)==m.floor(money/1000.0)):
  print("0")
elif(m.ceil(money/1000.0)<m.floor(money/1000.0)):
  print(money%1000)
else:
  print(1000-(money%1000))
Buggy python submission (verdict: Runtime Error):
xn = list(map(int, input().split()))
d={}
for i in range(101):
    d[str(i)]=0
for i in range(101):
    d[str(-i)]=0


if xn[1]!=0:
    p = list(map(int, input().split()))
    for i in range(xn[1]):
        d[str(p[i])]=1
    for i in range(101):
        if d[str(xn[0]-i)]==0:
            miflag=1
            mi=i
            print(xn[0]-mi)
            break
        if d[str(xn[0]+i)]==0:
            maflag=1
            ma=i
            print(xn[0]+ma)
            break
else:
    print(xn[0])

Fixed submission:
xn = list(map(int, input().split()))

d={}
for i in range(110):
    d[str(i)]=0
for i in range(110):
    d[str(-i)]=0
 
 
if xn[1]!=0:
    p = list(map(int, input().split()))
    
    for i in range(xn[1]):
        d[str(p[i])]=1
    for i in range(101):
        if d[str(xn[0]-i)]==0:
            miflag=1
            mi=i
            print(xn[0]-mi)
            break
        if d[str(xn[0]+i)]==0:
            maflag=1
            ma=i
            print(xn[0]+ma)
            break
else:
    print(xn[0])
Buggy python submission (verdict: Runtime Error):
n=input()
a = list(map(int, input().split()))
ans=1
az=a.index(0)

for i in range(len(a)):
    ans*= a[i]

    if az>0:
        ans=0
        break
    if ans>=1000000000000000001:
        ans=-1
        break

print(ans)


Fixed submission:
n=input()
a = list(map(int, input().split()))
ans=1
az=a.count(0)

if az>0:
    print(0)
else:
    for i in range(len(a)):
        ans*= a[i]
    
        if ans>=1000000000000000001:
            ans=-1
            break
    print(ans)

Buggy python submission (verdict: Runtime Error):
n=input()
a = list(map(int, input().split()))
ans=1
a0=a.index(0)

for i in range(len(a)):
    ans*= a[i]

    if a0>0:
        ans=0
        break
    if ans>=1000000000000000001:
        ans=-1
        break

print(ans)


Fixed submission:
n=input()
a = list(map(int, input().split()))
ans=1
az=a.count(0)

if az>0:
    print(0)
else:
    for i in range(len(a)):
        ans*= a[i]
    
        if ans>=1000000000000000001:
            ans=-1
            break
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
a = list(map(int, input().split()))
ans=1

for i in range(len(a)):
    ans*= a[i]

if ans<1000000000000000001:
    print(ans)
else:
    print(-1)


Fixed submission:
n=input()
a = list(map(int, input().split()))
ans=1
az=a.count(0)

if az>0:
    print(0)
else:
    for i in range(len(a)):
        ans*= a[i]
    
        if ans>=1000000000000000001:
            ans=-1
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
jousi={}
for i in range(N):
    itmp=str(i)
    jousi[itmp]=0
for i in range(N-1):
    atmp=str(a[i])
    jousi[atmp]+=1
for i in range(1,N+1):
    print(jousi[str(i)])


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
jousi={}
for i in range(N+1):
    jousi[str(i)]=0

for i in range(N-1):
    jousi[str(a[i])]+=1
    
for i in range(1,N+1):
    print(jousi[str(i)])
Buggy python submission (verdict: Runtime Error):
nm = list(map(int, input().split()))
a = list(map(int, input().split()))
Sum=0
flag=0

for i in range(len(a)):
    Sum+=a[i]

a.sort(reverse=True)

for i in range(nm[1]):
    if a[i]<sum/(4*nm[1]):
        flag=1
        break

if flag==1:
    print(No)
else:
    print(Yes)


Fixed submission:
nm = list(map(int, input().split()))
a = list(map(int, input().split()))
Sum=0
flag=0

for i in range(len(a)):
    Sum+=a[i]

a.sort(reverse=True)

for i in range(nm[1]):
    if a[i]<Sum/(4*nm[1]):
        flag=1
        break

if flag==1:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
su=0
a = list(map(int, input().split())) 
da={}
for i in range(len(a)):
    if a[i] in da:
        da[a[i]]+=1
    else:
        da[a[i]]=1

key=da.keys()
for k in range(len(a)):
    da[a[k]]-=1
    for p in da.keys():
        su+=da[p]*(da[p]-1)/2
    print(int(su))
    su=0
    da[a[k]]+=1




Fixed submission:
n=int(input())
su=0
a = list(map(int, input().split())) 
da={}
for i in range(len(a)):
    if a[i] in da:
        da[a[i]]+=1
    else:
        da[a[i]]=1
 
for p in da.keys():
    su+=da[p]*(da[p]-1)/2

for k in range(len(a)):
    sut=su-(da[a[k]]-1)
    print(int(sut))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = input().split()
flag = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]==A[j]:
            flag =1
            break
    if flag == 1:
        break

if flag == 1:
    print("NO")
else:
    print("YES")

Fixed submission:
N = int(input())

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

di={}


for i in range(N):
    di[A[i]] = i 

if len(di)<len(A):
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
i = list(map(int, input().split()))

if i[0] = i[1]:
  print('Yes')
else:
  print('No')

Fixed submission:
i = list(map(int, input().split()))

if i[0] == i[1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
X=int(input())
A=X//100
B=X%100

if B <= A *5:
    print(1)
else:
    print(0)


Fixed submission:
# coding: utf-8
# Your code here!

one = input().split()

two = input().split()

if one[0] != two[0]:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):

    N = int(input())
    flag = 0
    
    for i  in range(9):
        atai = N / (i + 1) 
        for j in range(9):
            if atai == j + 1:
                flag = 1
                break
        if flag == 1:
            break
    if flag == 1:
        print("Yes")
    else:
        print("No")


Fixed submission:
N = int(input())
flag = 0

for i  in range(9):
    atai = N / (i + 1) 
    for j in range(9):
        if atai == j + 1:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a = input()
if a >= 30:
    print('Yes')
else:
    print('No')

Fixed submission:

a = int(input())
if a >= 30:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n, k = inpl()
p = inpl()
p = sorted(p)
ans = 0
for i in range(n):
    ans += p[i]
    if i+1 == k:
        break
print(ans)

Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n, k = inpl()
p = inpl()
p = sorted(p)
ans = 0
for i in range(n):
    ans += p[i]
    if i+1 == k:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C, K = inpl()
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()
print(A-(K-A-B))

Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

A, B, C, K = inpl()
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()

print(A - (K-A-B))