Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    if i == 0:
      if data[i + 1] == "D" or data[i + 1] == "?":
        data[i] = "P"
      else:
        data[i] = "D"
    elif i == len(data) - 1:
      data[i] = "D"
    else:
      if data[i - 1] == "D" or data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
ans = "".join(data)
print(ans)

Fixed submission:
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    data[i] = "D"
ans = "".join(data)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    if i == 0:
      if data[i + 1] == "D" or data[i + 1] == "?":
        data[i] = "P"
      else:
        data[i] = "D"
    elif i == len(data) - 1:
      if data[i - 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    else:
      if data[i - 1] == "D" or data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
ans = "".join(data)
print(ans)

Fixed submission:
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    data[i] = "D"
ans = "".join(data)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    if i == 0:
      if data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    elif i == len(data) - 1:
      if data[i - 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    else:
      if data[i - 1] == "D" or data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
ans = "".join(data)
print(ans)

Fixed submission:
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    data[i] = "D"
ans = "".join(data)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    if i == 0:
      if data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    elif i == len(data) - 1:
      if data[i - 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    else:
      if data[i - 1] == "D" or data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
print(data)

Fixed submission:
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    data[i] = "D"
ans = "".join(data)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
num = sys.stdin

hon_num_list = ["2", "4", "5", "7", "9"]
pon_num_list = ["0", "1", "6", "8"]
bon_num_list = ["3"]


if num[-1] in hon_num_list:
  print("hon")
elif num[-1] in pon_num_list:
  print("pon")
elif num[-1] in bon_num_list:
  print("bon")

Fixed submission:
import sys
num = input()
 
hon_num_list = ["2", "4", "5", "7", "9"]
pon_num_list = ["0", "1", "6", "8"]
bon_num_list = ["3"]
 

if num[-1] in hon_num_list:
  print("hon")
elif num[-1] in pon_num_list:
  print("pon")
elif num[-1] in bon_num_list:
  print("bon")
Buggy python submission (verdict: Runtime Error):
A, B = input.split()
A = int(A)
B = int(B*100)
print(int(A*B/100))

Fixed submission:
A, B = map(int,input().split())
print(A*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = map(int,input().split())
ans = 1
for i in a:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
def aaa(a_list):
    ans = 1
    for i in a_list:
        ans = ans * i
        if ans > 10**18:
            return -1
    return ans

N = input()
a = input().split()
a = [int(i) for i in a]

if 0 in a:
    print(0)
else:
    print(aaa(a))

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = map(int,input().split())
ans = 1
for i in a:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
def aaa(a_list):
    ans = 1
    for i in a_list:
        ans = ans * i
        if ans > 10**18:
            return -1
    return ans

N = input()
a = input().split()
a = [int(i) for i in a]

if 0 in a:
    print(0)
else:
    print(aaa(a))

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = input().split()
ans = 1
for i in a:
    ans *= int(i)
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
def aaa(a_list):
    ans = 1
    for i in a_list:
        ans = ans * i
        if ans > 10**18:
            return -1
    return ans

N = input()
a = input().split()
a = [int(i) for i in a]

if 0 in a:
    print(0)
else:
    print(aaa(a))
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int,input().split())
ans = 2019
print(min([i*j%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Fixed submission:
L, R = map(int,input().split())
if R - L >= 2019:
    print(0)
else:
    ans = 2019
    print(min([i*j%2019 for i in range(L, R) for j in range(i+1, R+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int,input().split())
ans = 2019
for i in range(L, R):
    for j in range(i+1, R+1):
        if (ans > i*j % 2019):
            ans = i*j % 2019
print(ans)

Fixed submission:
L, R = map(int,input().split())
if R - L >= 2019:
    print(0)
else:
    ans = 2019
    print(min([i*j%2019 for i in range(L, R) for j in range(i+1, R+1)]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
job = []
for i in range(N):
    A,B = map(int,input().split())
    job.append([B,A])
job = sorted(job)time = 0
flag = 0
for i in job:
    time += i[1]
    if i[0] < time:
        print('No')
        flag = 1
        break
        
if flag == 0:
    print('Yes')

Fixed submission:
N = int(input())
job = []
for i in range(N):
    A,B = map(int,input().split())
    job.append([B,A])
job = sorted(job)
time = 0
flag = 0
for i in job:
    time += i[1]
    if i[0] < time:
        print('No')
        flag = 1
        break
        
if flag == 0:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
print(N-K)

Fixed submission:
N,K = map(int,input().split())
if K == 1:
    print(0)
else:
    print(N-K)
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
ball_location = []
for i in range(N):
    x,y = map(int, input().split())
    ball_location.append([x,y])

vector = []

for i in range(N):
    first_point = ball_location[i]
    
    for next_point in ball_location[0:i] + ball_location[i+1:]:
        p = next_point[0] - first_point[0]
        q = next_point[1] - first_point[1]
        vector.append(str(p) + "," + str(q))
        
print(N - collections.Counter(vector).most_common()[0][1])

Fixed submission:
import collections
N = int(input())
ball_location = []
for i in range(N):
    x,y = map(int, input().split())
    ball_location.append([x,y])

vector = []
if N <= 2:
    print(1)
else:
    for i in range(N):
        first_point = ball_location[i]
        
        for next_point in ball_location[0:i] + ball_location[i+1:]:
            p = next_point[0] - first_point[0]
            q = next_point[1] - first_point[1]
            vector.append(str(p) + "," + str(q))
            
    print(N - collections.Counter(vector).most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
def fibonacci(n):
    if n == 0:
        return 0 # F0
    elif n == 1:
        return 1 # F1
    return fibonacci_sub2(n-2, 1, 0) #F2以降

def fibonacci_sub2(n, fibo_minus1, fibo_minus2):
    return fibo_minus1 if n==0 else fibonacci_sub2(n-1, fibo_minus1+fibo_minus2, fibo_minus1)

N,M = map(int,input().split())
a = [int(input()) for i in range(M)]
a.append(N+1)
anser = 1
start = 0
for i in range(M+1):
    Bre = a.pop(0)
    if Bre == start:
        anser = 0
        break
    anser = anser * fibonacci(Bre - start + 1)
    start = Bre + 1

print(anser % 1000000007)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)  # RecursionError対策

def fibonacci(n):
    if n == 0:
        return 0 # F0
    elif n == 1:
        return 1 # F1
    return fibonacci_sub2(n-2, 1, 0) #F2以降

def fibonacci_sub2(n, fibo_minus1, fibo_minus2):
    return fibo_minus1 if n==0 else fibonacci_sub2(n-1, fibo_minus1+fibo_minus2, fibo_minus1)

N,M = map(int,input().split())
a = [int(input()) for i in range(M)]
a.append(N+1)
anser = 1
start = 0
for i in range(M+1):
    Bre = a.pop(0)
    if Bre == start:
        anser = 0
        break
    anser = anser * fibonacci(Bre - start + 1)
    start = Bre + 1

print(anser % 1000000007)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >= 13:
    print(B)
elif A <= 5:
    print(0)
else:
    print(B/2)

Fixed submission:
s = input().split()
A = int(s[0])
B = int(s[1])

if A >= 13:
    print(B)
elif A <= 5:
    print(0)
else:
    print(int(B/2))
Buggy python submission (verdict: Runtime Error):
s = input.split()
r = int(s[0])
D = int(s[1])
x = int(s[2])

for i in range(10):
    x = r * x - D
    print(x)

Fixed submission:
s = input().split()
r = int(s[0])
D = int(s[1])
x = int(s[2])

for i in range(10):
    x = r * x - D
    print(int(x))

Buggy python submission (verdict: Runtime Error):
r = int(input())
D = int(input())
x = int(input())

for i in range(10):
    x = r * x - D
    print(x)

Fixed submission:
s = input().split()
r = int(s[0])
D = int(s[1])
x = int(s[2])

for i in range(10):
    x = r * x - D
    print(int(x))
Buggy python submission (verdict: Runtime Error):
N = input()
V = input().split()
C = input().split()
ret_X_Y = 0

for i in range(len(V)):
    if (V[i] - C[i]) > 0:
        ret_X_Y += V[i] - C[i]
print(ret_X_Y)

Fixed submission:
N = input()
V = input().split()
C = input().split()
ret_X_Y = 0
V = [int(i) for i in V]
C = [int(i) for i in C]
for i in range(len(V)):
    if (V[i] - C[i]) > 0:
        ret_X_Y += V[i] - C[i]
print(ret_X_Y)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    Q = int(sys.stdin.readline())
    BC = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    C = Counter(A)
    '''
    L = [0 for _ in range(10**5+1)]
    for key, value in C.items():
        L[key] = value
    '''
        
        
    for bc in BC:
        C[bc[1]] += C[bc[0]]
        C[bc[0]]= 0
        ans = 0
        for key, value in C.items():
            ans += key*value
        print(ans)
        



if __name__=='__main__':
    main()


Fixed submission:
def main():
    import sys
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    Q = int(sys.stdin.readline())
    BC = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    C = Counter(A)
    '''
    L = [0 for _ in range(10**5+1)]
    for key, value in C.items():
        L[key] = value
    '''
        
    ans = 0
    for bc in BC:
        C[bc[1]] += C[bc[0]]
        tmp = C[bc[0]]
        C[bc[0]]= 0
        #print(C)
        if ans == 0:
            for key, value in C.items():
                ans += key*value
        else:
            ans +=(bc[1]-bc[0])*tmp
        print(ans)
        



if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    Q = int(sys.stdin.readline())
    BC = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    C = Counter(A)
    '''
    L = [0 for _ in range(10**5+1)]
    for key, value in C.items():
        L[key] = value
    '''
        
        
    for bc in BC:
        C[bc[1]] += C[bc[0]]
        C[bc[0]]= 0
        ans = 0
        for key, value in C.items():
            ans += key*value
        print(ans)
        



if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    Q = int(sys.stdin.readline())
    BC = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    C = Counter(A)
    '''
    L = [0 for _ in range(10**5+1)]
    for key, value in C.items():
        L[key] = value
    '''
        
    ans = 0
    for bc in BC:
        C[bc[1]] += C[bc[0]]
        tmp = C[bc[0]]
        C[bc[0]]= 0
        #print(C)
        if ans == 0:
            for key, value in C.items():
                ans += key*value
        else:
            ans +=(bc[1]-bc[0])*tmp
        print(ans)
        



if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    ans = []
    for i in range(0, 101):
        if X-i<0:
            break
        if not (X-i) in P:
            ans +=[i]
            break
    for i in range(0, 101):
        if X+i >100:
            break
        if not (X+i) in P:
            ans +=[i]
            break
    
    if ans[0]-ans[1] !=0:
        print(min(ans)+X)
    else:
        print(ans[0])



if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    
    i = 0
    while True:
        if X-i in P:
            pass
        else:
            print(X-i)
            break
        if X +i in P:
            pass
        else:
            print(X+i)
            break
        i+=1
    


if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#170D
def main():
    import sys, random
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    #print(random.randint(1, 10**6))
    #A = [random.randint(1, 10**6) for _ in range(2*(10**3))]
    B = Counter(A)
    #print(B)
    A = list(set(A))
    A.sort()
    #print(A)
    def era(A):
        for i in range(len(A)):
            for j in range(len(A)-1, i, -1):
                if A[j] % A[i] ==0:
                    A.pop(j)
    
    era(A)
    #print(A)
 
    
    for i in range(len(A)-1, -1, -1):
        if B[A[i]]>=2:
            A.pop(i)
    #print(dp)
    print(len(A))
    
 
 
if __name__=='__main__':
    main()

Fixed submission:
#170D
def main():
    import sys
    from collections import Counter
    import random
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    #A = [random.randint(1, 10**6+1) for _ in range(2*(10**5))]
    judge = [0 for _ in range(10**6+1)]
    A.sort()
    B = Counter(A)
    for a in A:
        judge[a] =1
    for a in A:
        if judge[a] ==1:
            if B[a] >=2:
                judge[a] = 0
            for i in range(2*a, 10**6+1, a):
                judge[i] = 0
                
    print(judge.count(1))

if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#170D
def main():
    import sys, random
    from collections import Counter
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    #print(random.randint(1, 10**6))
    #A = [random.randint(1, 10**6) for _ in range(2*(10**3))]
    B = Counter(A)
    #print(B)
    A = list(set(A))
    A.sort()
    #print(A)
    def era(A):
        for i in range(len(A)):
            for j in range(len(A)-1, i, -1):
                if A[j] % A[i] ==0:
                    A.pop(j)
    
    era(A)
    #print(A)

    
    for i in range(len(A)-1, -1, -1):
        if B[A[i]]>=2:
            A.pop(i)
    #print(dp)
    print(len(A))
    


if __name__=='__main__':
    main()

Fixed submission:
#170D
def main():
    import sys
    from collections import Counter
    import random
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    #A = [random.randint(1, 10**6+1) for _ in range(2*(10**5))]
    judge = [0 for _ in range(10**6+1)]
    A.sort()
    B = Counter(A)
    for a in A:
        judge[a] =1
    for a in A:
        if judge[a] ==1:
            if B[a] >=2:
                judge[a] = 0
            for i in range(2*a, 10**6+1, a):
                judge[i] = 0
                
    print(judge.count(1))

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys, math, bisect

N, M= map(int, sys.stdin.readline().split())
AB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]

edge =[[] for _ in range(N)]
for ab in AB:
    bisect.insort(edge[ab[0]-1], (ab[1]-1))
    bisect.insort(edge[ab[1]-1], (ab[0]-1))
    
#print(edge)
sys.setrecursionlimit(100000)


def dfs(now, cnt =1, before=-1):#before:一つ前に通ったノード
    #if before==-1:
        #print(now)
    for c in edge[now]: #c:子
        if not c ==before: #無限ループを防ぐ
            #print(c)
            if c==0:
                L.append(cnt)
                break
            else:
                dfs(c, cnt+1, now) #再帰

ans = []
for i in range(1, N):
    L = []
    dfs(i)
    ans.append(min(L))
print('Yes')
for a in ans:
    print(a)

Fixed submission:
#168D
def main():
    import sys
    
    N, M =map(int, sys.stdin.readline().split())
    AB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    
    edge = [[] for _ in range(N)]
    for ab in AB:
        edge[ab[0]-1] += [ab[1]-1]
        edge[ab[1]-1] += [ab[0]-1]
    
    #print(edge)
    
    L = [-1 for i in range(N)] #道標(親p)を調べる
    
    #p:親 c:子
    def bfs(p):
        from collections import deque
        queue = deque([p])
        L[p] =0
        while queue:
            p = queue.popleft()
            for c in edge[p]:
                if L[c]==-1: #-1のとき未開
                    #print(c)
                    L[c] = p+1 #道標(どこから来たか)
                    #L[c] = L[now]+1 #階層の深さ
                    queue.append(c)
        
    
    bfs(0)
    print('Yes')
    for i in L[1:]:
        print(i)


if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#ABC162A
import sys
N = sys.stdin.readline().rstrip()

if '7' in N:
    print('Yes')
else:
    print('No')

#ABC162B
import sys
N = int(sys.stdin.readline())
total=0
for i in range(1, N+1):
    if i%3 !=0 and i%5 !=0:
        total+=i
    
print(total)

Fixed submission:
#ABC162A
import sys
N = sys.stdin.readline().rstrip()
 
if '7' in N:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
def comb(n):
  return int(math.factorial(n)/(math.factorial(n-2)*2))
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)


Fixed submission:
#ABC159D
import sys, math
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))

Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
def comb(n):
  return int(math.factrial(n)/(math.factrial(n-2)*2))
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)


Fixed submission:
#ABC159D
import sys, math
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))

Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())
def comb(n):
  return int(math.factrial(n)/(math.factrial(n-2)*2))
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)


Fixed submission:
#ABC159D
import sys, math
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))

Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import Counter
n = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())
def comb(n):
  return math.factrial(n)/(math.factrial(n-2)*2)
for k in range(n):
  ans =0
  L=A[:k]+A[k+1:]
  for v in Counter(L).values():
    if v>=2:
      ans +=comb(v)
  print(ans)

Fixed submission:
#ABC159D
import sys, math
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))
Buggy python submission (verdict: Runtime Error):
#ABC154A
import sys
from collections import OrderedDict
d = OrderedDict()
s,t = sys.stdin.readline().split()
n1, n2 = map(int, sys.stdin.readline().split())
d[s] = n1
d[t] = n2

d[sys.stdin.readline()] -=1

print(*d.values())

Fixed submission:
#ABC154A
import sys
from collections import OrderedDict
d = OrderedDict()
s,t = sys.stdin.readline().split()
n1, n2 = map(int, sys.stdin.readline().split())
d[s] = n1
d[t] = n2

d[sys.stdin.readline().rstrip()] -=1

print(*d.values())
Buggy python submission (verdict: Runtime Error):
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
while True:
    for i, a in enumerate(A):
        if a > i+1:
            A.pop(i)
            cnt+=1
        if A[i] != i+1:
            A.pop(i)
            cnt+=1
            break
    else:
        break

if len(A)==0:
    print(-1)
else:
    print(cnt)

Fixed submission:
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
i=1
for a in A:
    if a ==i:
        i+=1
 
ans =n-i+1
if ans ==n:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
while True:
    for i, a in enumerate(A):
        if A[i] != i+1:
            A.pop(i)
            cnt+=1
            break
    else:
        break

if len(A)==0:
    print(-1)
else:
    print(cnt)

Fixed submission:
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
i=1
for a in A:
    if a ==i:
        i+=1
 
ans =n-i+1
if ans ==n:
    print(-1)
else:
    print(ans)