Harryxun/stf_run huggingface dataset:
import bisect

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

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        if S[a-1]!=b:
            a=int(a)
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt)

### FIXED CODE ###

import bisect

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

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt)
n,m=map(int,input().split())
ls=[int(input()) for i in range(m)]

if 1 in ls:
    steps=[1,0]
else:
    steps=[1,1]

for this_step in range(2,n+1):
    if this_step in ls:
        ap=0
    else:
        ap=steps[-1]+steps[-2]
    steps.append(ap)
    print(steps)

print(steps[-1]%1000000007)

### FIXED CODE ###

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
a = set(a)
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1
for i in range(2,n+1):
    if i not in a:
        dp[i] = dp[i-1]+dp[i-2]
print(dp[-1]%mod)
stack = [[] for i in xrange(int(raw_input())]
while True:
	s = map(str,raw_input().split())
	if s[0] == 'quit':
		break
	elif s[0] == 'push':
		stack[int(s[1])-1].append(s[2])
	elif s[0] == 'pop':
		print stack[int(s[i])-1].pop()
	elif s[0] == 'move':
		stack[int(s[2])-1].append(stack[int(s[1])-1].pop())

### FIXED CODE ###

n = int(raw_input())
stack = [[] for i in xrange(n)]
while True:
	s = map(str,raw_input().split())
	if s[0] == 'quit':
		break
	elif s[0] == 'push':
		stack[int(s[1])-1].append(s[2])
	elif s[0] == 'pop':
		print stack[int(s[1])-1].pop()
	elif s[0] == 'move':
		stack[int(s[2])-1].append(stack[int(s[1])-1].pop())
nk = input(' ')
n = int(nk.split()[0])
k = int(nk.split()[1])
alist = list(map(int,input('').split()))

loop_start=0
loop_end=0
root = []
next=1
for i in range(k):
    a = next
    next = alist[a-1]
    root.append(a)
    #print("{}: {}->{} [{}]".format(i,a,next,root))
    if next in root:
        loop_start=root.index(next)
        loop_end=len(root)
        break

#print("{} {}->{}".format(root,loop_start,loop_end))

step=(k-loop_start)%(loop_end-loop_start)
#print("step:({}-{})%({} - {})={}".format(k,loop_start,loop_end,loop_start,step))
#print("root[{}+{}]={}".format(loop_start,step,root[loop_start+step]))
if k < loop_start:
    print(root[k])
else:
    print(root[loop_start+step])

### FIXED CODE ###

nk = input(' ')
n = int(nk.split()[0])
k = int(nk.split()[1])
alist = list(map(int,input('').split()))

loop_start=0
loop_end=0
root = [1]
next_val=1
flag=[True]*n
flag[0]=False # 踏んだかどうか判定機
a=1
for i in range(k):
    a = alist[a-1]
    if flag[a-1]: # 踏んでたらそこでブレイク
        root.append(a)
        flag[a-1]=False # 踏んだらFalseに
    else:
        break

#print("{} {}->{}".format(root,loop_start,loop_end))

loop_start=root.index(a)
loop_end=len(root)
step=(k-loop_start)%(len(root)-loop_start)
#print("step:({}-{})%({} - {})={}".format(k,loop_start,loop_end,loop_start,step))
#print("root[{}+{}]={}".format(loop_start,step,root[loop_start+step]))
print(root[loop_start+step])
n, m = list(map(int, input().split()))

# initialize the cards array. True if the card shows Back side. False if the card shows Top side
arr = [ [False] * m ] * n

for i in range(n):
    for j in range(m):
        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if (i-b >=0 and j-a >= 0) and (i-b < n and j-a < m):
                    arr[i-b][j-a] = not arr[i-b][j-a]

print(sum(sum(l) for l in arr))

### FIXED CODE ###

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

if n == 1 and m == 1:
    print(1)
elif n == 1 and m > 1:
    print(m - 2)
elif n > 1 and m == 1:
    print(n - 2)
else:
    print((n-2)*(m-2))
n,m=map(int,input().split())
mod=10**9+7
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0 for i in range(n+1)] for i in range(m+1)]
sum=[[0 for i in range(n+1)] for i in range(m+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod
print(sum[-1][-1]%mod)

### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0 for i in range(m+1)] for i in range(n+1)]
sum=[[0 for i in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod
print((sum[-1][-1]+1)%mod)
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    idx = bisect_left(X, 0)
    #print("idx={}".format(idx))
    ans = 10**10
    if 0 == X[idx]:
        for i in range(idx + 1):
            num = idx - i + 1
            if num > K: continue
            elif num == K: ans = min(ans, -X[i])
            elif idx - (K - num) < N: ans = min(ans, -2 * X[i] + X[idx + (K - num)])
        for i in range(idx + 1, N):
            num = i - idx + 1
            if num > K: continue
            elif num == K: ans = min(ans, X[i])
            elif idx - (K - num) < N: ans = min(ans, 2 * X[i] - X[idx - (K - num)])
    else:
        for i in range(idx):
            num = idx - i
            if num > K: continue
            elif num == K: ans = min(ans, -X[i])
            elif 0 < idx - (K - num) - 1 < N: ans = min(ans, -2 * X[i] + X[idx + (K - num) - 1])
            #print("i={}, ans={}".format(i, ans))
        for i in range(idx, N):
            num = i - idx + 1
            if num > K: continue
            elif num == K: ans = min(ans, X[i])
            elif 0 < idx - (K - num) < N: ans = min(ans, 2 * X[i] - X[idx - (K - num)])
            #print("i={}, ans={}".format(i, ans))
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    idx = bisect_left(X, 0)
    #print("idx={}".format(idx))
    ans = 10**10
    if idx == N:
        print(-X[-K])
        return
    elif 0 == X[idx]:
        for i in range(idx + 1):
            num = idx - i + 1
            if num > K: continue
            elif num == K: ans = min(ans, -X[i])
            elif 0 <= idx + (K - num) and idx + (K - num) < N:
                ans = min(ans, -2 * X[i] + X[idx + (K - num)])
        for i in range(idx + 1, N):
            num = i - idx + 1
            if num > K: continue
            elif num == K: ans = min(ans, X[i])
            elif 0 <= idx - (K - num) and idx - (K - num) < N:
                ans = min(ans, 2 * X[i] - X[idx - (K - num)])
    else:
        for i in range(idx):
            num = idx - i
            if num > K: continue
            elif num == K: ans = min(ans, -X[i])
            elif 0 <= idx + (K - num) - 1 and idx + (K - num) - 1 < N:
                ans = min(ans, -2 * X[i] + X[idx + (K - num) - 1])
            #print("i={}, num={}, cand={}, ans={}".format(i, idx - (K - num) - 1, -2 * X[i] + X[idx + (K - num) - 1], ans))
        for i in range(idx, N):
            num = i - idx + 1
            if num > K: continue
            elif num == K: ans = min(ans, X[i])
            elif 0 <= idx - (K - num) and idx - (K - num) < N:
                ans = min(ans, 2 * X[i] - X[idx - (K - num)])
            #print("i={}, ans={}".format(i, ans))
    print(ans)

if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))
c = {}
#for i in range(n):
 # c[a[i]] = c.get(a[i], 0) + 1

prime_bool = [True]*(max(a)+1)
prime_bool[0] = False
count = 0
for p in sorted(a):
  if prime_bool[p]:
    if c[p] == 1:
      count += 1
    #print(p)
    for j in range(2*p, max(a)+1, p):
      prime_bool[j] = False

print(count)



### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
c = collections.Counter(a)
data = sorted(list(set(a)))
max_ = max(a)+1
prime_bool = [True]*max_
prime_bool[0] = False

for i in range(len(data)):
  p = data[i]
  if prime_bool[p]:
    #print(p)
    k = 2
    while k*p < max_:
      prime_bool[k*p] = False
      k += 1

count = 0
for i in range(len(prime_bool)):
  if prime_bool[i]:
    if c[i] == 1:
      count += 1
print(count)
#print(prime_bool)
h, w = map(int, input().split())
mat = []
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])

dp = [[80*80*80]*w for i in range(h)]
for y in range(h):
  for x in range(w):
    if x > 0:
      dp[y][x] = min(dp[y][x], abs(dp[y][x-1]-mat[y][x]))
    if y > 0:
      dp[y][x] = min(dp[y][x], abs(dp[y-1][x]-mat[y][x]))
print(dp[h][w])

### FIXED CODE ###

h, w = map(int, input().split())
mat = []
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])
m = max(map(max, mat))
dp = [[0b0 for i in range(w)] for k in range(h)]
dp[0][0] |= 0b1 << mat[0][0]
for y in range(h):
  for x in range(w):
        if x > 0:
          dp[y][x] |= dp[y][x-1] << mat[y][x]
          dp[y][x] |= dp[y][x-1] >> mat[y][x]
          anded = dp[y][x-1] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        if y > 0:
          dp[y][x] |= dp[y-1][x] << mat[y][x]
          dp[y][x] |= dp[y-1][x] >> mat[y][x]
          anded = dp[y-1][x] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        #print(bin(dp[y][x]))

keta = 0
while dp[h-1][w-1] % 2 == 0:
  keta += 1
  dp[h-1][w-1] //= 2
print(keta)
import sys
lw = sys.argv[1]
retrun lw == "ABC" ? "ARC" : "ABC"

### FIXED CODE ###

tw ="ABC" if input().startswith("ARC") else "ARC"
print(tw)
#coding:utf-8

import sys
import numpy as np

a = int(sys.argv[1])
b = int(sys.argv[2])

max_number = np.array([a+b,2*a-1,2*b-1]).max()
print(max_number)


### FIXED CODE ###

import numpy as np
a,b= map(int,input().split())
max_number = np.array([a+b,2*a-1,2*b-1]).max()
print(max_number)
mx, h = [], []
for ch in input():
    if ch in ['A', 'C', 'G', 'T']:
        h += ch
    else:
        mx += [h]
        h = []
else:
    print(len(max(mx)))

### FIXED CODE ###

mx, h = [], []
for ch in str(input()):
    if ch in ['A', 'C', 'G', 'T']:
        h += ch
    else:
        mx += [h]
        h = []
else:
    mx += [h]
    print(max([len(l) for l in mx]))
a. b = map(int, input().split())
print(a*b, 2*(a+b))

### FIXED CODE ###

a, b = map(int, input().split())
print(a*b, 2*(a+b))
import sys
input = sys.stdin.readline
h,w,N = map(int,input().split())
sx,sy = map(int,input().split())
S = input().rstrip()
T = input().rstrip()
L = 0
R = 0
U = 0
D = 0
for i in range(n):
    if S[i] == "L":
        L+=1
    if S[i] == "R":
        R+=1
    if S[i] == "U":
        U+=1
    if S[i] == "D":
        D+=1
    if L>=sy or R >= w-sy+1 or U>=sx or D >= h-sx+1:
        print("NO")
        exit()
    if T[i] == "L":
        R = max(,)
    if T[i] == "R":
        R+=1
    if T[i] == "U":
        U+=1
    if T[i] == "D":
        D+=1

### FIXED CODE ###

h,w,n = map(int,input().split())
sx,sy = map(int,input().split())
S = input()
T = input()
S = list(S[::-1])
T = list(T[::-1])
area = [1,h,1,w]
#上下左右
for s,t in zip(S,T):
  if t == "R":
    area[2] = max(1,area[2]-1)
  if t == "L":
    area[3] = min(w,area[3]+1)
  if t == "D":
    area[0] = max(1,area[0]-1)
  if t == "U":
    area[1] = min(h,area[1]+1)
  if s == "L":
    area[2] = min(w+1,area[2]+1)
  if s == "R":
    area[3] = max(0,area[3]-1)
  if s == "U":
    area[0] = min(h+1,area[0]+1)
  if s == "D":
    area[1] = max(0,area[1]-1)
  if area[0] > area[1] or area[2] > area[3]:
    print("NO")
    exit()
if area[0] <= sx <= area[1] and area[2] <= sy <= area[3]:
  print("YES")
else:
  print("NO")
n , k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
  a_i = (1+p[i])/2
def sigma(a, b):
    s = 0
    for i in range(a, b+1):
        s += a_i
    return s
  
for i in range(n-k+1):
  r_i = sigma(i, i+k-1)
  
M = max(r_i) for i in range(n-k+1)
print(M)



### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [0]
for p in P:
    Q.append(Q[-1] + (p+1)/2)

print(max([Q[i+K]-Q[i] for i in range(N-K+1)]))
N,M=map(int,input().split())
li=[0]*N
for i in range(M):
    si,ci=map(int,input().split())
    if li[si-1] != 0 and li[si-1] !=ci:
        print(-1)
        exit(0)
    if si==1 and ci==0:
        if N>1:
            print(-1)
            exit(0)
    li[si-1]=ci
if N>1 and li[0]==0:
    li[0]=1
for i in range(N):
    print(li[i],end="")


### FIXED CODE ###

N = int(input())
print( -(-N // 2))
def rightMinNumber(L):
    min = L[len(L)-1]
    min_index = len(L) - 1
    for i in range(len(L)-2,-1,-1):
        if L[i] < min:
            min = L[i]
            min_index = i
    a.append(min)
    if min_index+1 == len(L)-1 and min_index > 0:
        lL = L[:min_index]
        rightMinNumber(lL)
    elif min_index + 1 < len(L)-1:
        rL = L[min_index+1:]
        rightMinNumber(rL)

N = int(input())
B = [int(_) for _ in input().split()]
#出力
a = []
#Bのエンコーダを作る
x = 0

#Bの正当性を調べる。
for i in range(N):
    if B[i] > i+1:
        x = -1
        break
if x == -1:
    print(x)
else :
    rightMinNumber(B)
    for i in range(N):
        print(a[i])


### FIXED CODE ###

def main():
    N = int(input())
    B = [int(_) for _ in input().split()]

    #出力用
    outs = []

    for i in range(N):
        for k in range(N-1-i,-1,-1):
            if B[k] == k+1:
                del B[k]
                outs.insert(0,k+1)
                break
        else:
            print(-1)
            return

    for out in outs:
        print(out)

if __name__ == '__main__':
    main()
A=int(input())
B=int(input())
C=int(input())
K=int(input())
j=0
if A>=(2**K)*B :
    print('No')
else :
    while A>=(2**j)*B :
        j+=1
    if (2**j)*B>=(2**(K-j))*C :
        print('No')
    else:
        print('Yes')
        print((2**(K-j))*C)

### FIXED CODE ###

x=3
A,B,C=(int(x) for x in input().split())
K=int(input())
j=0
if A>=(2**K)*B :
    print('No')
else :
    while A>=(2**j)*B :
        j+=1
    if (2**j)*B>=(2**(K-j))*C :
        print('No')
    else:
        print('Yes')
#ABC117 A
T, X = map(int, input().split())
print(T/X)


### FIXED CODE ###

#ABC116 A
AB, BC, CA = list(map(int, input().split()))
print(AB*BC//2)
n,k = map(str, input().split())
k = int(k)
num = 0

for i in range(0, len(n)):
  sum += int(n[i]) * k^(len(n)-i)
  
print(len(str(sum)))

### FIXED CODE ###

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

ans = 0

while n > 0:
  n /= k
  n = int(n)
  ans += 1
  
print(ans)
n = int(input())
str = input()
k = int(input())

c = str[k-1]
str2 = ""
for char in str:
  if char == c:
    s += c
  else:
    s += *
    
print(s)

### FIXED CODE ###

n = int(input())
str = input()
k = int(input())

c = str[k-1]
str2 = ""
for char in str:
  if char == c:
    str2 += c
  else:
    str2 += "*"
    
print(str2)
from collections import deque

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

graph = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

print(graph)

dist = [-1] * (n + 1)
dist[0] = 0
dist[1] = 0

d=deque()
d.append(1)

while d:
    print(d)
    print(dist)
    v = d.popleft()
    
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)
        
ans = dist[2:]
print('Yes')
print(*ans,sep='\n')



### FIXED CODE ###

from collections import deque

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

graph = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [0] * (n + 1)

d=deque()
d.append(1)

while d:
    v = d.popleft()
    
    for i in graph[v]:
        if not dist[i]:
            dist[i] = v
            d.append(i)

ans = dist[2:]
print('Yes')
print(*ans,sep='\n')
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

### FIXED CODE ###

d = int(input())

if d == 25:
  print("Christmas")
elif d == 24:
  print("Christmas Eve")
elif d == 23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")
x,y = map(int,raw_input().split())
cd = 1

while True:
    a = x
    for i in range(2,int(min(x,y)) + 1):
        if x%i == 0:
            if y%i == 0:
                x /= i
                y /= i
                cd *= i
                break
    if a == x:
        break
print(cd)
		

### FIXED CODE ###

def lcd(a,b): ##return least common multiple of a and b
    if a > b:
        return lcd(a-b,b)
    elif a < b:
        return lcd(b-a,a)
    elif a == b:
        return a

a,b = map(int,input().split())
print(lcd(a,b))
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
C=[1]
for i in range(1,N+1):
  if C.count(A[C[i]-1])==0:
    C.append(A[C[i]-1])
  else:
    l=C.index(A[C[i]-1])+1
    break
if K+1<=l:
  print(C[K])
else:
  print(C[l-1+(K+1-l)%(len(C)-l+1)])
print(C)

### FIXED CODE ###

import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
C=[1]
s=set([1])
for i in range(N):
  if A[C[i]-1] in s:
    l=C.index(A[C[i]-1])+1
    break
  else:
    C.append(A[C[i]-1])
    s.add(A[C[i]-1])
if K+1<=l:
  print(C[K])
else:
  print(C[l-1+(K+1-l)%(len(C)-l+1)])
K = int(input())
target = S[K-1]
result = []
result2 = ''
for i in S:
    if i is target:
        result.append(i)
    else:
        result.append('*')
for i in result:
    result2 += i

print(result2)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
target = S[K-1]
result = []
result2 = ''
for i in S:
    if i is target:
        result.append(i)
    else:
        result.append('*')
for i in result:
    result2 += i

print(result2)
n=int(input())
s=list(input())
d=0
for i in range(n):
  if n-1-i>=2:
    
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      d+=1
  
print(c)    


### FIXED CODE ###

n=int(input())
s=list(input())
d=0
for i in range(n):
  if n-(i+1)>=2:
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      d+=1
  else:
    pass
print(d)
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.insert(0,x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
print(sum(list(Ld))+sum(list(Ad)))

### FIXED CODE ###

n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))
N,M = map(int,input().split())
A = [int(x) for x in input().split()]

if N - sum(A) >= 0:
    print(N - A.sum())
else:
    print(-1)
    

### FIXED CODE ###

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

if N - sum(A) >= 0:
    print(N - sum(A))
else:
    print(-1)
n = int(input())
m = []
for i in n:
  for j in n:
    if i*j==n:
      m.append(i+j-2)
print(min(m))

### FIXED CODE ###

n = int(input())
 
b = 10**12
a = int((n**0.5)//1)
for i in range(1,a+1):
  if n%i==0:
    b = min(b,int(i+(n//i)-2))
print(b)
def digit_sum(x):
    sum = 0
    while x :
        sum += x % 10
        x = int(x / 10)
    return sum

N = int(input())
l = [ digit_sum(x) for x in range(1, N+1)]

sum_a_b = []

for i in range(1, int(N/2)):
    sum_a_b.append(l[i-1] + l[N-i-1])

print(min(sum_a_b))


### FIXED CODE ###

def digit_sum(x):
    sum = 0
    while x :
        sum += x % 10
        x = int(x / 10)
    return sum

N = int(input())
l = [ digit_sum(x) for x in range(1, N+1)]

sum_a_b = []
if N % 2 == 0:
    sum_a_b.append(l[int(N/2)-1]*2)

for i in range(1, int(N/2)):
    sum_a_b.append(l[i-1] + l[N-i-1])

print(min(sum_a_b))
n = int(input())
tmp = 0
for i in range(len(str(n))):
  tmp += str(n)[i]
if n % tmp == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
tmp = 0
for i in range(len(str(n))):
  tmp += int(str(n)[i])
if n % tmp == 0:
  print('Yes')
else:
  print('No')
L,R=map(int,input().split())
m=(L*(L+1))%2019
for i in range(L,R):
  for j in rang(i+1,R+1):
    s=(i*j)%2019
    m=min(m,s)
print(m)


### FIXED CODE ###

L,R=map(int,input().split())
if L%2019==0 or R%2019==0:
  print(0)
else:
  start=L%2019
  end=R%2019
  if start>=end or R-L>=2018: #中に2019の倍数が含まれるとき
    print(0)
  else:
    m=(L*(L+1))%2019
    for i in range(L,R):
      for j in range(i+1,R+1):
        s=(i*j)%2019
        m=min(m,s)
    print(m)
n, m = map(int, input().split())
info = sorted([list(map(int, input().split())) for _ in range(m)])

q = []
for i in range(m):
	if info[i][0] == 1:
		q.append(info[i][1])
	else:
		t = i
		break

for j in range(t, m):
	if info[j][0] in q:
		if info[j][1] == n:
			print("POSSIBLE")
			break
else:
	print("IMPOSSIBLE")

### FIXED CODE ###

n, m = map(int, input().split())
side1 = set()
side2 = set()

for i in range(m):
	a, b = map(int, input().split())

	if a == 1:
		side1.add(b)
	
	elif b == n:
		side2.add(a)

print(("" if side1 & side2 else "IM") + "POSSIBLE")
N = int(input())
Alist = [int(input()) for i in range(N)]
Alist.sort()
Alist.append('END')
counter = 1
ans = 0

for i in range(1, len(alist)):
    if Alist[i - 1] == Alist[i]:
        counter += 1
    else:
        if counter % 2 == 1:
            ans += 1
        counter = 1

print(ans)


### FIXED CODE ###

N = int(input())
Alist = [int(input()) for i in range(N)]
Alist.sort()
Alist.append('END')
counter = 1
ans = 0

for i in range(1, len(Alist)):
    if Alist[i - 1] == Alist[i]:
        counter += 1
    else:
        if counter % 2 == 1:
            ans += 1
        counter = 1

print(ans)