Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x,y,a,b,c=MI()
rs=sorted(LI(),reverse=True)
gs=sorted(LI(),reverse=True)
ns=sorted(LI(),reverse=True)
rs=rs[0:x]
gs=gs[0:y]
#print(gs)
R=deque(rs)
G=deque(gs)
N=deque(ns)


u=R.popleft()
v=G.popleft()
w=N.popleft()
if x==1:
    s=u
else:
    s=R.pop()
if y==1:
    t=v
else:
    t=G.pop()
ans=0
while x>0 or y>0:
    if x==0:
        u=0
        s=inf
    if y==0:
        v=0
        t=inf
    if u>v and u>=w:
        #print(u)
        ans+=u
        x-=1
        if x==1:
            u=s
        elif x!=0:
            u=R.popleft()
        
    elif v>u and v>=w:
        #print(v)
        ans+=v
        y-=1
        if y==1:
            v=t
        elif y!=0:
            v=G.popleft()
        
    elif w>u and w>v:
        #print(w)
        ans+=w
        if s<=t:
            if x==1:
                s=u
                x-=1
            elif x!=0:
                s=R.pop()
                x-=1
        else:
            if y==1:
                t=v
                y-=1
            elif y!=0:
                t=G.pop()
                y-=1
print(ans)

Fixed submission:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x,y,a,b,c=MI()
ps=sorted(LI(),reverse=True)
qs=sorted(LI(),reverse=True)
rs=sorted(LI(),reverse=True)
ps=ps[0:x]
qs=qs[0:y]
u=rs+ps+qs
u.sort(reverse=True)
print(sum(u[0:x+y]))
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())

s = []

for i in range(H):

    S = list(input())
    s.append(S)

dis = [[float("inf")] * W for i in range(H)]

if s[0][0] == "#":
    dis[0][0] = 1
else:
    dis[0][0] = 0

for i in range(H):

    for j in range(W):

        if i != H-1:

            if s[i][j] == "." and s[i+1][j] == "#":

                dis[i+1][j] = min(dis[i][j] + 1,dis[i+1][j])

            else:
                dis[i+1][j] = min(dis[i][j],dis[i+1][j])

        if j != W-1:
            if s[i][j] == "." and s[i][j+1] == "#":

                dis[i][j+1] = min(dis[i][j] + 1,dis[i][j+1])

            else:
                dis[i][j+1] = min(dis[i][j],dis[i][j+1])

print (dis[-1][-1])


Fixed submission:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
s=list(map(int,SI()))
if n==1:
    print(s[0])
    sys.exit()

def divi2(x):
    if x%2==1:
        return 0
    else:
        count=0
        while x%2==0:
            x//=2
            count+=1
        return count
#print(divi2(24))
pw2=[0 for i in range(n-1)]
for i in range(n-1):
    if i%2==1:
        pw2[i]=divi2(i+1)
#print(pw2)
#print(s)
cmbnk2=[0 for i in range(n)]
for i in range(n-1):
    cmbnk2[i+1]=cmbnk2[i]+pw2[n-2-i]-pw2[i]
#print(cmbnk2)
ans=0
'''if (s.count(1)==1 and not 2 in s ) or (s.count(3)==1 and not 2 in s ):
    ans=2
    print(ans)
    sys.exit()'''
if not 2 in s:
    for i in range(n):
        s[i]=(s[i]-1)//2
    for i in range(n):
        if cmbnk2[i]==0:
            ans+=s[i]%2
    if ans%2==0:
        print(0)
    else:
        print(2)
    sys.exit()
    
        
else:
    for i in range(n):
        if cmbnk2[i]==0:
            ans+=s[i]%2
            #print(s[i]%2)
        #print(cmbnk2[i]%2+1)
        #print(s[i])
print(ans%2)
Buggy python submission (verdict: Runtime Error):
'''alpha10=["a","b","c","d","e","f","g","h","i","j"]
N=int(input())
answers=[[] for i in range(10)]
answers[0].append("0")
print(answers)
for i in range(9):
    for befans in answers[i]:
        answers[i+1].append("0"+befans)'''
'''import sys
n=int(input())
points=[["0","0","0"]]
for i in range(n):
    points.append(input().rstrip().split(" "))
print(points)
for i in range(n):
    delx=int(points[i+1][1])-int(points[i][1])
    dely=int(points[i+1][2])-int(points[i][2])
    delt=int(points[i+1][0])-int(points[i][0])
    if delx+dely>delt or (delt-delx-dely)%2==1:
	    print("No")
    	sys.exit()
print("Yes")'''
import sys
n=int(input())
points=[["0","0","0"]]
for i in range(n):
    points.append(input().rstrip().split(" "))
#print(points)
for i in range(n):
    delx=int(points[i+1][1])-int(points[i][1])
    dely=int(points[i+1][2])-int(points[i][2])
    delt=int(points[i+1][0])-int(points[i][0])
    if abs(delx)+abs(dely)>delt or (delt-delx-dely)%2==1:
        print("No")
        sys.exit()
print("Yes")

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
lis=[[]for i in range(n)]
lis[0].append([1])
for i in range(n-1):
    for j in lis[i]:
        for m in range(max(j)+1):
            lis[i+1].append(j+[m+1])
        #print(max(j))
#print(lis[n-1])
alpha=["a","b","c","d","e","f","g","h","i","j"]
for u in lis[n-1]:
    ans=""
    for j in u:
        ans+=alpha[j-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
nm =input().rstrip().split(" ")
n =int(nm[0])
m =int(nm[1])
direcs=[]
for i in range(m):
    direcs.append(input().rstrip().split(" "))
#print(direcs)
trdirecs=list(map(list, set(map(tuple, direcs))))
#print(trdirecs)
first=[]
second=[]
third=[]
for j in trdirecs:
    if int(j[0])==1:
        first.append(int(j[1]))
    if int(j[0])==2:
        second.append(int(j[1]))
    if int(j[0])==3:
        third.append(int(j[1]))
if first[0]==0 and (n==2 or n==3):
    answer=-1
    print(answer)
    sys.exit()
    
'''print(first)
print(second)
print(third)'''
'''if len(first)>1 or len(second)>1 or len(third)>1:
    print(-1)'''
if len(first)==0:
    first.append(0)
if len(second)==0:
    second.append(0)
if len(third)==0:
    third.append(0)
#数字が条件を満たしているかどうか判定する
if n==1:
    for i in range(0,10):
        if i==first[0]:
            answer=i
elif n==2:
    for i in range(0,100):
        d1=int((i-i%10)/10)
        d2=i%10
        if d1==first[0] and d2 ==second[0]:
            answer=i
            if answer<=9:
                answer=10+i
elif n==3:
    for i in range(0,1000):
        d3=i%10
        a=int((i-d3)/10)
        d2=a%10
        d1=int((a-a%10)/10)
        #print(d1,d2,d3)
        if d1==first[0] and d2==second[0] and d3==third[0]:
            answer=i
            if answer<100:
                answer=100+i
if len(first)>1 or len(second)>1 or len(third)>1:
    answer=-1
print(answer)

Fixed submission:
import sys
nm =input().rstrip().split(" ")
n =int(nm[0])
m =int(nm[1])
direcs=[]
for i in range(m):
    direcs.append(input().rstrip().split(" "))
#print(direcs)
trdirecs=list(map(list, set(map(tuple, direcs))))
#print(trdirecs)
first=[]
second=[]
third=[]
for j in trdirecs:
    if int(j[0])==1:
        first.append(int(j[1]))
    if int(j[0])==2:
        second.append(int(j[1]))
    if int(j[0])==3:
        third.append(int(j[1]))
if len(first)!=0 and first[0]==0 and (n==2 or n==3):
    answer=-1
    print(answer)
    sys.exit()
    
'''print(first)
print(second)
print(third)'''
'''if len(first)>1 or len(second)>1 or len(third)>1:
    print(-1)'''
if len(first)==0:
    first.append(0)
if len(second)==0:
    second.append(0)
if len(third)==0:
    third.append(0)
#数字が条件を満たしているかどうか判定する
if n==1:
    for i in range(0,10):
        if i==first[0]:
            answer=i
elif n==2:
    for i in range(0,100):
        d1=int((i-i%10)/10)
        d2=i%10
        if d1==first[0] and d2 ==second[0]:
            answer=i
            if answer<=9:
                answer=10+i
elif n==3:
    for i in range(0,1000):
        d3=i%10
        a=int((i-d3)/10)
        d2=a%10
        d1=int((a-a%10)/10)
        #print(d1,d2,d3)
        if d1==first[0] and d2==second[0] and d3==third[0]:
            answer=i
            if answer<100:
                answer=100+i
if len(first)>1 or len(second)>1 or len(third)>1:
    answer=-1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
a=pow(2,10**7)
print(a)


Fixed submission:
def cmod(n, r, p):
    x,y  = 1, 1
    for i in range(r):
        x = x * (n - i) % p
        y = y * (r - i) % p
    return (x * pow(y, p - 2, p)) % p


n, a, b = map(int, (input().split()))
p = 10 ** 9 + 7
print((pow(2, n, p) - 1 - cmod(n, a, p) - cmod(n, b, p)) % p)

Buggy python submission (verdict: Time Limit Exceeded):
import math
numbers =input().rstrip().split(" ")
N =int(numbers[0])
a =int(numbers[1])
b =int(numbers[2])
Ya=math.factorial(a)
Yb=math.factorial(b)
Xa=1
Xb=1
for i in range(a):
    Xa=Xa*(N-i)
for i in range(b):
    Xb=Xb*(N-i)

d=1000000007
#answer is 2**N-nca-ncb-1 mod d
A=pow(2,N)
B=Xa*pow(Ya,d-2)
C=Xb*pow(Yb,d-2)
answer=(A+B+C-1)%d
print(answer)

Fixed submission:
def cmod(n, r, p):
    x,y  = 1, 1
    for i in range(r):
        x = x * (n - i) % p
        y = y * (r - i) % p
    return (x * pow(y, p - 2, p)) % p


n, a, b = map(int, (input().split()))
p = 10 ** 9 + 7
print((pow(2, n, p) - 1 - cmod(n, a, p) - cmod(n, b, p)) % p)

Buggy python submission (verdict: Time Limit Exceeded):
numbers =input().rstrip().split(" ")
N =int(numbers[0])
a =int(numbers[1])
b =int(numbers[2])
import math 

def comb(n,k):
    return math.factorial(n)/(math.factorial(k)*math.factorial(n-k))

c =int(2**N-comb(N,a)-comb(N,b)-1)
d =c%(1000000000+7)
print(d)


Fixed submission:
def cmod(n, r, p):
    x,y  = 1, 1
    for i in range(r):
        x = x * (n - i) % p
        y = y * (r - i) % p
    return (x * pow(y, p - 2, p)) % p


n, a, b = map(int, (input().split()))
p = 10 ** 9 + 7
print((pow(2, n, p) - 1 - cmod(n, a, p) - cmod(n, b, p)) % p)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n=int(stdin.readline().rstrip())
#print(n)
dic={}
for i in range(n):
    s=stdin.readline().rstrip()
    if s in dic.keys():
        dic[s] +=1
    else:
        dic[s]=1
#print(dic)
#print(dic.keys())
sup=0
suc=[]
for (i,number) in dic.items():
    if number>sup:
        suc=[]
        sup=number
        suc.append(i)
    elif number==sup:
        suc.append(i)
for k in (sorted(suc)):
    print(k)

Fixed submission:
from sys import stdin
n=int(stdin.readline().rstrip())
#print(n)
dic={}
for i in range(n):
    s=stdin.readline().rstrip()
    if s in dic.keys():
        dic[s] +=1
    else:
        dic[s]=1
#print(dic)
#print(dic.keys())
sup=0
suc=[]
for (i,number) in dic.items():
    if number>sup:
        suc=[]
        sup=number
        suc.append(i)
    elif number==sup:
        suc.append(i)
for k in (sorted(suc)):
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
N =int(input())
words=[]
for i in range(N):
    words.append(input().rstrip())
candidate=list(set(words))
standard=0
for i in range(len(candidate)):
    if words.count(candidate[i])>standard:
        standard=words.count(candidate[i])
        presidents=[]
        presidents.append(candidate[i])
    elif words.count(candidate[i])==standard:
        presidents.append(candidate[i])
answers=sorted(presidents)
for answer in answers:
    print(answer)

Fixed submission:
from sys import stdin
n=int(stdin.readline().rstrip())
#print(n)
dic={}
for i in range(n):
    s=stdin.readline().rstrip()
    if s in dic.keys():
        dic[s] +=1
    else:
        dic[s]=1
#print(dic)
#print(dic.keys())
sup=0
suc=[]
for (i,number) in dic.items():
    if number>sup:
        suc=[]
        sup=number
        suc.append(i)
    elif number==sup:
        suc.append(i)
for k in (sorted(suc)):
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
N =int(input())
words=[]
for i in range(N):
    words.append(input().rstrip())
candidate=list(set(words))
standard=0
for i in range(len(candidate)):
    if words.count(candidate[i])>standard:
        standard=words.count(candidate[i])
        presidents=[]
        presidents.append(candidate[i])
    elif words.count(candidate[i])==standard:
        presidents.append(candidate[i])
answers=sorted(presidents)
for answer in answers:
    print(answer)

Fixed submission:
from sys import stdin
n=int(stdin.readline().rstrip())
#print(n)
dic={}
for i in range(n):
    s=stdin.readline().rstrip()
    if s in dic.keys():
        dic[s] +=1
    else:
        dic[s]=1
#print(dic)
#print(dic.keys())
sup=0
suc=[]
for (i,number) in dic.items():
    if number>sup:
        suc=[]
        sup=number
        suc.append(i)
    elif number==sup:
        suc.append(i)
for k in (sorted(suc)):
    print(k)
Buggy python submission (verdict: Runtime Error):
straights=[]
nk =input().rstrip().split(" ")
n =int(nk[0])
k =int(nk[1])
numbers =input().rstrip().split(" ")
rank=sorted(numbers)
for i in range(k):
  answer=answer+rank[i]
trans=(answer+k)/2

Fixed submission:
nk=input().rstrip().split(" ")
n=int(nk[0])
k=int(nk[1])
numbers=input().rstrip().split(" ")
sigmas=[0]
sigma=0
for i in range(n):
    sigma=sigma+(int(numbers[i])+1)/2
    sigmas.append(sigma)
#print(sigmas)
deltas=[]
for i in range(n-k+1):
    delta=sigmas[k+i]-sigmas[i]
    deltas.append(delta)
#print(deltas)
answer=0
for delt in deltas:
    if delt>=answer:
        answer=delt
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
straights=[]
nk =input().rstrip().split(" ")
n =int(nk[0])
k =int(nk[1])
numbers =input().rstrip().split(" ")
for i in range(n-k+1):
    wa=0
    for j in range(k):
        wa =wa+int(numbers[i+j])
    straights.append(wa)
#print(straights)
straights2 =sorted(straights, reverse=True)
#print(straights2)
sigma=straights2[0]
answer =(sigma+k)/2
print(answer)

Fixed submission:
nk=input().rstrip().split(" ")
n=int(nk[0])
k=int(nk[1])
numbers=input().rstrip().split(" ")
sigmas=[0]
sigma=0
for i in range(n):
    sigma=sigma+(int(numbers[i])+1)/2
    sigmas.append(sigma)
#print(sigmas)
deltas=[]
for i in range(n-k+1):
    delta=sigmas[k+i]-sigmas[i]
    deltas.append(delta)
#print(deltas)
answer=0
for delt in deltas:
    if delt>=answer:
        answer=delt
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

h,n=MI()
lis=[LI() for i in range(n)]
mx=sorted(lis,reverse=True)[0][0]
#print(mx)
dp=[0 for i in range(h+mx)]
for i in range(1,h+mx):
    mn=inf
    #print(i,i)
    for j in range(n):
        u=dp[max(i-lis[j][0],0)]+lis[j][1]
        #print(u)
        if u<mn:
            mn=u
    dp[i]=mn
#print(dp)
z=[]
for i in range(mx):
    z.append(dp[h+i])
print(min(z))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

h,n=MI()
lis=[LI() for i in range(n)]
mx=sorted(lis,reverse=True)[0][0]
#print(mx)
dp=[0 for i in range(h+mx)]
for i in range(1,h+mx):
    mn=inf
    #print(i,i)
    for j in range(n):
        u=dp[max(i-lis[j][0],0)]+lis[j][1]
        #print(u)
        if u<mn:
            mn=u
    dp[i]=mn
#print(dp)
z=[]
for i in range(mx):
    z.append(dp[h+i])
print(min(z))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split()) 
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
  if L[i][1]=="AC":
    A[int(L[i][0])-1]=1
    
  elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
    W[int(L[i][0])-1]+=1
#for i in A:
  #a+=i
#for i in W:
  #w+=i
for i in range(n):
  if A[i]>0:
    a+=1
    w+=W[i]
print(a,w)



Fixed submission:
import sys
nm=input().rstrip().split(" ")
n=int(nm[0])
m=int(nm[1])
answers=[[] for i in range(n)]
for i in range(m):
    line=input().rstrip().split(" ")
    if line[1]=="AC":
        answers[int(line[0])-1].append(1)
    if line[1]=="WA":
        answers[int(line[0])-1].append(0)
#print(answers)
ac=0
i=0
was=[]
while i<n:
    sums=0
    j=0
    while j<len(answers[i]):
        sums=sums+answers[i][j]
        if sums>0:
            ac+=1
            was.append(j)
            break
        j=j+1
    i=i+1
print(ac,end=" ")
#print(was)
wacount=0
for j in was:
    wacount=wacount+j
print(wacount)
Buggy python submission (verdict: Runtime Error):
import sympy
x=int(input())
ans=sympy.nextprime(x)
print(ans)

Fixed submission:
x=int(input())
i=2
cond="notyet"
while cond=="notyet":
    count=0
    for i in range(2,x):
        ex=x%i
        if  ex!=0:
            count+=1
    if count==x-2:
        ans=x
        cond="discovered"
    else:
        x=x+1
print(ans)

Buggy python submission (verdict: Runtime Error):
x=int(input())
from sympy import nextprime
print(nextprime(x))

Fixed submission:
x=int(input())
i=2
cond="notyet"
while cond=="notyet":
    count=0
    for i in range(2,x):
        ex=x%i
        if  ex!=0:
            count+=1
    if count==x-2:
        ans=x
        cond="discovered"
    else:
        x=x+1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
nums=input().rstrip().split(" ")
#print(nums)
count=0
for num in nums:
    if num!="1":
        count+=1
if count==n:
    print("-1")
i=1
while nums!=[]:
    for j in range(len(nums)):
        if int(nums[j])!=i:
            nums[j]="0"
            #print(nums)
        else:
            nums=[i for i in nums if i!="0"]
            if nums.count(str(i))>=1:
                nums.remove(str(i))
                i=i+1
                #print(nums)
                #print(i)
            break
        
'''nums=[i for i in nums if i!="0"]
if nums.count(str(i))>=1: nums.remove(str(i))
    i=i+1'''
#print(nums)
#print(i)
ans=n-i+1
print(ans)

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 1
    for i in range(n):
        if a[i] == k:
            k += 1
    k -= 1
    print(n - k) if k else print(-1)

main()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
nums=input().rstrip().split(" ")
#print(nums)
count=0
for num in nums:
    if num!="1":
        count+=1
if count==n:
    print("-1")
i=1
while nums!=[]:
    for j in range(len(nums)):
        if int(nums[j])!=i:
            nums[j]="0"
            #print(nums)
        else:
            nums=[i for i in nums if i!="0"]
            if nums.count(str(i))>=1:
                nums.remove(str(i))
                i=i+1
                #print(nums)
                #print(i)
            break
        
'''nums=[i for i in nums if i!="0"]
if nums.count(str(i))>=1: nums.remove(str(i))
    i=i+1'''
#print(nums)
#print(i)
ans=n-i+1
print(ans)

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 1
    for i in range(n):
        if a[i] == k:
            k += 1
    k -= 1
    print(n - k) if k else print(-1)

main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
numbers=input().split()
nums=list(map(int,numbers))
#print(nums)
mx=0
for num in nums:
    if num>mx:
        mx=num
#print(mx)
j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1
#print(ans)
print(ans%1000000007)

Fixed submission:
n=int(input())
numbers=input().split()
nums=list(map(int,numbers))
#print(nums)
mx=0
for num in nums:
    if num>mx:
        mx=num
#print(mx)
j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1
#print(ans)
print(ans%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
numbers=input().split()
nm=list(map(int,numbers))
#print(nm)
sums=0
for i in range(0,n-1):
    for j in range(i+1,n):
        #print(nm[i],end=" ")
        #print(nm[j])
        sums+=nm[i]^nm[j]
#print(sums)
print(sums%1000000007)

Fixed submission:
n=int(input())
numbers=input().split()
nums=list(map(int,numbers))
#print(nums)
mx=0
for num in nums:
    if num>mx:
        mx=num
#print(mx)
j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1
#print(ans)
print(ans%1000000007)