Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
  
def set_list(es):
  return len(list(set(es))) == 1
  
n = int(input())
n_list = [int(i) for i in input().split()] 

np_list = np.array(n_list)
min1_idx = np.argmin(np_list)
min1 = min(np_list)
np_list[min1_idx] = 10000000001
min2_idx = np.argmin(np_list)
min2 = min(np_list)

div_list = make_divisors(min1) + make_divisors(min2)
div_set = set(div_list)

for s in reversed(sorted(list(div_set))):
  if set_list(n_list):
    print(n_list[0])
    break  
  count = 0
  j = 0
  for x in n_list:
    if n_list[j] % s == 0:
      #print(s)
      #print(n_list[j] % s)
      count += 1
    j += 1
  if count >= n - 1:
    print(s)
    break
  
      

      
  






Fixed submission:
import math
import numpy as np

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
  
def set_list(es):
  return len(list(set(es))) == 1
  
n = int(input())
n_list = [int(i) for i in input().split()] 

if set_list(n_list):
    print(n_list[0])
else:
  min1 = min(n_list)
  n_list.remove(min1)
  min2 = min(n_list)
  n_list.append(min1)

  div_list = make_divisors(min1) + make_divisors(min2)
  div_set = set(div_list)
  div_list = sorted(list(div_set))

  k = 0
  length = len(div_set)
  while k < length: 
    s = div_list[length - k - 1]
    count = 0
    j = 0
    for x in n_list:
      if n_list[j] % s == 0:
        count += 1
      j += 1
    if count >= n - 1:
      print(s)
      break
      
    k += 1
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
i = 0

while i < q:
  l, r = map(int, input().split())
  print(s.count("AC", l-1, r))
  i += 1

Fixed submission:
n, q = (int(i) for i in input().split())  
s = input()

count_list = []
bef_str = ''
bef_count = 0

for x in s:
  if bef_str == 'A' and x == 'C':
    bef_count += 1
    
  count_list.append(bef_count)
  bef_str = x
    
for i in range(q):
  l, r = (int(i) for i in input().split())
  print(count_list[r-1] - count_list[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
i = 0

while i < q:
  l, r = map(int, input().split())
  print(s[l - 1: r].count("AC"))
  i += 1

Fixed submission:
n, q = (int(i) for i in input().split())  
s = input()

count_list = []
bef_str = ''
bef_count = 0

for x in s:
  if bef_str == 'A' and x == 'C':
    bef_count += 1
    
  count_list.append(bef_count)
  bef_str = x
    
for i in range(q):
  l, r = (int(i) for i in input().split())
  print(count_list[r-1] - count_list[l-1])
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from operator import xor
a, b = (int(i) for i in input().split())  
print(reduce(xor, list(range(a, b+1))))

Fixed submission:
A, B = map(int, input().split())
 
def xor(A):
  ans = ((A+1)//2)%2
  if A%2==0:
    ans ^= A
  return ans
 
print(xor(B)^xor(A-1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A = set(A)
 
min1 = min(A)
A.remove(min1)
min2 = min(A)
if len(A) == 1:
  print(A.pop())
  exit()
 
is_all_even = True
 
for x in A:
  if x % 2 == 1:
    is_all_even = False
    break
    
if is_all_even or min2 % min1 == 0:
  print(min(A))
else:
  print(1)

Fixed submission:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
gcd = A[0]
for i in range(N-1):
  gcd = fractions.gcd(gcd, A[i+1])
  
print(gcd)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A = set(A)

if len(A) == 1:
  print(A.pop())
  exit()

min1 = min(A)
A.remove(min1)
min2 = min(A)

while True:
  min3 = min(A)
  A.remove(min3)
  if min3 % 2 == 1:
    break 
  
while True:
  tmp1 = min1
  min1 = min2 % min1
  min2 = tmp1
  
  tmp2 = min3
  min3 = min2 % min3
  min2 = tmp2
  if min1 == 0:
    min1 = tmp1
    min3 = tmp2
    break
  if min1 == 1:
    break
    
print(min(min1, min3))
  
  

Fixed submission:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
gcd = A[0]
for i in range(N-1):
  gcd = fractions.gcd(gcd, A[i+1])
  
print(gcd)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
h = np.array([int(i) for i in input().split()])
flag = [0] * N

thrs = 0

i = 0
ans = 0
l, r = (0, 0)
while sum(flag) != N:
  j = 0
  while j < l:
    if h[j] == 0:
      flag[j] = 1
    j += 1
  
  if h[l] == 0:
    l += 1
    flag[l] = 1
  
  i = 0
  i += l
  r = i
  while h[i] > thrs:
    r += 1
    i += 1
    if i == N:
      break
  
  if l == r:
    continue
  ans += min(h[l:r])
  h[l:r] = h[l:r] - min(h[l:r])
print(ans)
  

Fixed submission:
import numpy as np

N = int(input())
h = np.array([int(i) for i in input().split()])
flag = [0] * N

thrs = 0

if N == 1:
  print(h[0])
  exit()

i = 0
ans = 0
l, r = (0, 0)
while sum(flag) != N:
  j = 0
  while j < l:
    if h[j] == 0:
      flag[j] = 1
    j += 1
  
  if h[l] == 0:
    l += 1
    flag[l] = 1
  
  i = 0
  i += l
  r = i
  while h[i] > thrs:
    r += 1
    i += 1
    if i == N:
      break
  
  if l == r:
    continue
  ans += min(h[l:r])
  h[l:r] = h[l:r] - min(h[l:r])
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for i in range(M):
  p, y = [int(i) for i in input().split()]
  if p not in d:
    d[p] = [y]
  else:
    #d[p] = (d[p] + [y])
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

 #for x in d:
 # d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))9

Fixed submission:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
D = [[] for _ in range(N)]

for i, (p, y) in enumerate(PY):
  D[p-1].append((y, i))

ans = [None] * M
output = [[] for _ in range(M)]
for i, d in enumerate(D):
  d.sort()
  for k, (y, j) in enumerate(d):
    ans[j] = (i, k)

for i, k in ans:
  print('{}{}'.format(str(i+1).zfill(6), str(k+1).zfill(6)))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    #d[p] = (d[p] + [y])
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

#for x in d:
 # d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

Fixed submission:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
D = [[] for _ in range(N)]

for i, (p, y) in enumerate(PY):
  D[p-1].append((y, i))

ans = [None] * M
output = [[] for _ in range(M)]
for i, d in enumerate(D):
  d.sort()
  for k, (y, j) in enumerate(d):
    ans[j] = (i, k)

for i, k in ans:
  print('{}{}'.format(str(i+1).zfill(6), str(k+1).zfill(6)))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    d[p] = (d[p] + [y])

for x in d:
  d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

Fixed submission:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
D = [[] for _ in range(N)]

for i, (p, y) in enumerate(PY):
  D[p-1].append((y, i))

ans = [None] * M
output = [[] for _ in range(M)]
for i, d in enumerate(D):
  d.sort()
  for k, (y, j) in enumerate(d):
    ans[j] = (i, k)

for i, k in ans:
  print('{}{}'.format(str(i+1).zfill(6), str(k+1).zfill(6)))
Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())  

def dfs(a, b, c):
  lis = [''.join([str(a), str(b), str(c)])]
  if max(a, b, c) > N:
    return []
  
  lis += dfs(a + K, b, c)
  lis += dfs(a, b + K, c)
  lis += dfs(a, b, c + K)
  return lis

ans = 0
l = []
if K % 2 == 0:
  l += dfs(K//2, K//2, K//2)
  l += dfs(K, K, K)
else:
  l += dfs(K, K, K)

print(len(set(l)))

Fixed submission:
N, K = (int(i) for i in input().split())  
ans = 0
if K % 2 == 0:
  ans += (N//(K//2) - N//K) ** 3
  ans += (N//K) ** 3
else:
  ans += (N//K) ** 3

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

if S[0] == '1':
  print(S[1])
else:
  print(S[0])

Fixed submission:
S = input()
K = int(input())
not_one = '1'
count = 0
for s in S:
  if s != '1':
    not_one = s
    break
  count += 1

if K <= count:
  print('1')
else:
  print(not_one)
Buggy python submission (verdict: Runtime Error):
D, G = (int(i) for i in input().split())  
PC = [[int(i) for i in input().split()] for i in range(D)] 

max_atmpt = G // (D * 100)
total = 0
ans = 0
count = 0
pc_gain_sorted = []
idx_list = []
for i, (p, c) in enumerate(PC):
  pc_gain_sorted.append((p * (i + 1) * 100 + c, i + 1, p))
pc_gain_sorted.reverse()

for gain, idx, _ in pc_gain_sorted:
  if total + gain <= G:
    total += gain
    idx_list.append(idx) # start from 1
    count += PC[idx - 1][0]
    
for gain, idx, p in pc_gain_sorted:
  if idx not in idx_list:
    break

for i in range(10):
  tmp = []
  for j, (p, c) in enumerate(PC):
    if i + 1 
  	tmp.append((j + 1) * 100 * (i + 1)
  

print(ans + count)

Fixed submission:
D, G = (int(i) for i in input().split())  
PC = [[int(i) for i in input().split()] for i in range(D)] 

s = 0
Q = []
for i, (p, c) in enumerate(PC):
    s += p
    Q.append((i+1, p, c))
    
dp = [-10**18]*(s+1)
dp[0] = 0

for i, p, c in Q:
  for j in range(s, -1, -1): # 解きうる問題総数をイテレート
    for k in range(1, p+1): # 解く問題数をイテレート
      if k == p:
        cc = 100*i*k + c
      else:
        cc = 100*i*k
      if j - k >= 0:
        dp[j] = max(dp[j], dp[j - k] + cc)

for i, total in enumerate(dp):
  if total >= G:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
l = [int(i) for i in input().split()] 
l_sort = np.sort(l)
l_diff = np.diff(l_sort)
 
print(np.sum(l_diff))

Fixed submission:
l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
l = [int(i) for i in input().split()] 
ans = 0
 
for i in range(len(l) - 1):
	if l[i+1] < l[i]:
      tmp = l[i+1]
      l[i+1] = l[i]
      l[i] = tmp

for i in range(len(l) - 1):
	ans += l[i+1] - l[i]

print(ans)

Fixed submission:
l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
l = [int(i) for i in input().split()] 
ans = 0
 
for i in range(len(l) - 1):
	if l[i+1] < l[i]:
	tmp = l[i+1]
	l[i+1] = l[i]
	l[i] = tmp
    
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)

Fixed submission:
l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
l = [int(i) for i in input().split()] 
ans = 0

for i in range(len(l) - 1):
	if l[i+1] < l[i]:
	tmp = l[i+1]
	l[i+1] = l[i]
	l[i] = tmp

for i in range(len(l) - 1):
	ans += l[i+1] - l[i]

print(ans)

Fixed submission:
l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()] 

print(max(a) - min(a))

Fixed submission:
n = int(input())

if n % 2 == 0:
  print(n)
else:
  print(n * 2)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])

min_num = 100000000000

for x in range(-(max(a)), max(a) + 1):
  min_sum = sum(abs(a - np.ones(len(a)) * x - np.array(range(1, n + 1))))
  #print(abs(a - np.array(range(1, n + 1))))
  if min_sum < min_num:
    min_num = min_sum

print(int(min_num))

Fixed submission:
import numpy as np
import statistics

n = int(input())
inputs = [int(i) for i in input().split()]
a = np.array(inputs)

z = a - np.array(range(1, n + 1))
nums = list(set(inputs))

print(int(sum(abs(z - np.ones(len(a)) * statistics.median(z)))))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from copy import deepcopy
def resolve():
    H,W,K=pin()
    maze=[list(input()) for a in range(H)]
#    print(maze)

    #double bit full search
    ans=0
    for i in range(2**H):
        for j in range(2**W):
            #i,j is a set such that not colored red
            notred=[]
            numh=[0]*W
            #Height
            for ci in range(H):
                check=1<<ci
                if i & check:
                    #nukiidasi
                    for k in range(W):
                        if maze[ci][k]=="#":
                            numh[k]+=1

            cal=0
            for cj in range(W):
                check=1<<cj
                if j & check:
                    cal+=numh[cj]
            if cal==K:ans+=1
    print(ans)

#%%submit!
resolve()


Fixed submission:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    print ((-N)%1000)
#%%submit!
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from random import randrange
from itertools import accumulate
from bisect import bisect_left
import time
#%%code

def calc(LIST):
    ans=0
    last=[0]*26
    for i in range(len(LIST)):
        a=i+1 #day a0
        x=LIST[i]-1
        #increase
        ans+=S[i][x]
        #decrease
        last[x]=a#update
        temp=0
        for j in range(26):
            temp+=C[j]*(a-last[j])
        #print(ans,temp,"deb")
        ans-=temp
        #print(ans)

    return ans

def answerer(c):
    """
    #方針その2
    最初にですが乱択をします。ただし、CとDの積に応じてあたりやすさをでかくします
    """
    acc=list(accumulate(c))
    ret=[]
    for d in range(D):
        acc=list(accumulate(c))
        miru=[]
        for i in range(len(c)):
            miru.append(acc[i]*S[d][i])
        temp=randrange(miru[-1])
        s=bisect_left(miru,temp)
        if s<1:s+=1
        elif s>=len(miru):s=len(miru)
        ret.append(s+1)
        
        #print(s+1)
    return ret

def resolve():
    global D,C,S
    #input of prob.A
    D,=pin()
    C=[*pin()]#0-indexed
    S=[[*pin()]for i in range(D)]
    answerer(C)

    
    ##print(acc)
    start=time.time()
    king=[1]*365
    max_score=calc(king)
    #print(max_score)
    
    while(time.time()-start<1.9):
        temp=answerer(C)
        challenge=calc(temp)
        if challenge>max_score:
            max_score=challenge
            king=temp[:]
        ##print(king,max_score)
    
    #assert len(king)==D
    print(*king,sep="\n")
    #print(max_score)
#%%submit!
resolve()

Fixed submission:
print(*[(i%26)+1 for i in range(365)],sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    # 愚直解
    N,K=pin()
    A=lispin()
    B=[0]*N
    B[0]=A[0]
    for j in range(1,N):
        B[j]=A[j]-A[j-1]
    #print(B)
    
    for k in range(K):
        temp=0
        C=[0]*N
        for i in range(N):
            temp+=B[i]
            #print(temp)
            if i-temp<0:

                C[0]+=1
            else:C[i-temp]+=1

            if i+temp+1<N:
                C[i+temp+1]-=1
        B=C[:]
    ans=[]
    x=0
    for c in C:
        x+=c
        ans.append(x)
    print(*ans)
#%%submit!
resolve()

Fixed submission:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    # 愚直解
    N,K=pin()
    A=lispin()
    B=[0]*N
    B[0]=A[0]
    for j in range(1,N):
        B[j]=A[j]-A[j-1]
    #print(B)

    for k in range(K):
        temp=0
        C=[0]*N
        for i in range(N):
            temp+=B[i]
            #print(temp)
            if i-temp<0:

                C[0]+=1
            else:C[i-temp]+=1

            if i+temp+1<N:
                C[i+temp+1]-=1
        B=C[:]
        if B[0]==N and sum(B)==N:
            break
    ans=[]
    x=0
    for c in C:
        x+=c
        ans.append(x)
    print(*ans)
    #after contest
    
#%%submit!
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
import random
def resolve():
    A,B,N=pin()
    def f(A,B,x):
        t=(A*x)//B
        s=x//B
        return t-A*s
    ans=0
    for i in range(10**7):
        k=random.randint(0,N)
        ans=max(ans,f(A,B,k))
    print(ans)
#%%submit!
resolve()

Fixed submission:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
import random
def resolve():
    A,B,N=pin()
    def f(A,B,x):
        t=(A*x)//B
        s=x//B
        return t-A*s
    ans=0
    for i in range(10**6):
        k=random.randint(0,N)
        ans=max(ans,f(A,B,k))
    print(ans)
#%%submit!
resolve()
Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)
#s_cu = [] 
counter = [0] * 2019

counter[0] += 1
temp=""
for i in range(1, n+1):
    c=s.pop()
    temp = c + (temp if i != 1 else "")
    #s_cu.append(temp)
    counter[int(temp) % 2019] += 1

ans = 0
for i in counter:
    ans += (i * (i - 1)) // 2

print(ans)

Fixed submission:
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,M=pin()
    cond=M<N
    print(["unsafe","safe"][cond])
#%%submit!
resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
#my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
from math import gcd

#your code here!
def resolve():
    N,M=pin()
    A=(pin())
    t=(N)-sum(A)
    #print(t)
    ans=t if t>-1 else -1
    print(ans)

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()

"""
    I wrote my code above!
"""
    resolve()#and submit 2 atcoder!



Fixed submission:
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
#my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
from math import gcd

#your code here!
def resolve():
    N,M=pin()
    A=(pin())
    t=(N)-sum(A)
    #print(t)
    ans=t if t>-1 else -1
    print(ans)

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()


    resolve()