Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input.split())
print(max(a*b, c*d))

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*b, c*d))
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)

cs_plus = np.cumsum((a > 0) * a)
cs_plus = [0] + list(cs_plus)
plus = [v2 - v1 for v1, v2 in zip(cs_plus[:-k], cs_plus[k:])]

cs_minus = np.cumsum((a < 0) * a)
cs_minus = [0] + list(cs_minus)
minus = [v2 - v1 for v1, v2 in zip(cs_minus[:-k], cs_minus[k:])]

print(cs_plus[-1] - min(min(plus), -max(minus)))


Fixed submission:
x, y = map(int, input().split())

diff = abs(y) - abs(x)

if y == 0:
    if x <= 0:
        print(-x)
        exit()
    if x >= 0:
        print(x + 1)
        exit()

result = 0
if (x >= 0) == (y >= 0):
    if x < 0 and diff > 0:
        result = 2
    if x >= 0 and diff < 0:
        result = 2
else:
    result = 1
if diff < 0:
    diff *= -1
print(result + diff)
Buggy python submission (verdict: Runtime Error):
print(ord(input()) in "aiueo" and "vowel" or "consonant")

Fixed submission:
print(input() in "aiueo" and "vowel" or "consonant")
Buggy python submission (verdict: Time Limit Exceeded):
pattern = ["dream", "dreamer", "erase", "eraser"]
split_pattern = ["dream", "er", "ase", "r"]
grammer = {
        "ase": ["er"],
        "r": ["ase", "er"],
        "er": ["dream"],
        "dream": [],
        }
s = input()

splited = []
while s:
    for spl in split_pattern:
        if s.startswith(spl):
            splited.insert(0, spl)
            s = s[len(spl):]

pred = []
for word in splited:
    if not pred:
        pred = grammer[word][:]
    else:
        if word != pred[0]:
            print("NO")
            break
        else:
            del pred[0]
else:
    print("YES")


Fixed submission:
import sys
pattern = ["dream", "dreamer", "erase", "eraser"]
split_pattern = ["dream", "er", "ase", "r"]
grammer = {
        "ase": ["er"],
        "r": ["ase", "er"],
        "er": ["dream"],
        "dream": [],
        }
s = input()

splited = []
while s:
    for spl in split_pattern:
        if s.startswith(spl):
            splited.insert(0, spl)
            s = s[len(spl):]
            break
    else:
        print("NO")
        sys.exit()

pred = []
for word in splited:
    if not pred:
        pred = grammer[word][:]
    else:
        if word != pred[0]:
            print("NO")
            break
        else:
            del pred[0]
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
m = 2 * N - 1

if 2 <= K < m:
    mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
    a = list(set(range(1, m + 1)) - set(mid))
    print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
    print("No")


Fixed submission:
N = int(input())
a, b = input(), input()

result = 0
for i in range(N):
    if b.startswith(a[i:]):
        break
    result += 1
print(result + N)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
print("No" if K < N else "Yes\n" + "\n".join(map(str, range(1, K * 2))))

Fixed submission:
N = int(input())
a, b = input(), input()

result = 0
for i in range(N):
    if b.startswith(a[i:]):
        break
    result += 1
print(result + N)
Buggy python submission (verdict: Runtime Error):
print("No" if K < N else "Yes\n" + "\n".join(map(str, range(1, K * 2))))

Fixed submission:
N, K = map(int, input().split())
m = 2 * N - 1

if 2 <= K < m:
    mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
    a = list(set(range(1, m + 1)) - set(mid))
    print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
print len(set(input().split()))

Fixed submission:
print(len(set(input().split())))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = 1
    while True:
        ac = a * cnt
        bc = b * cnt
        if limit[0] <= ac and limit[1] <= bc:
            return ac, bc
        cnt += 1


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print(sum(now))


Fixed submission:
n = int(input())
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = (limit[0] + a - 1) // a
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc

    cnt = (limit[1] + b - 1) // b
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print(sum(now))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

def resolve(a):
    target = N
    result = 0
    for i in a:
        if target > i: target = i
        result += target
    return result

print(sum([resolve(a[x:]) for x in range(N)]))


Fixed submission:
s = raw_input()
T = S = 0
for i in s:
    if i == "T":
        if S: S -= 1
        else: T += 1
    elif i == "S":
        S += 1
print T + S

Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
while 1:
    result = s.replace("ST", "")
    if result == s:
        s = result
        break
    else: s = result
print len(s)


Fixed submission:
s = raw_input()
T = S = 0
for i in s:
    if i == "T":
        if S: S -= 1
        else: T += 1
    elif i == "S":
        S += 1
print T + S

Buggy python submission (verdict: Runtime Error):
s = input()
while 1:
    result = s.replace("ST", "")
    if result != s:
        s = result
        break
    else: s = result
print len(s)


Fixed submission:
s = raw_input()
T = S = 0
for i in s:
    if i == "T":
        if S: S -= 1
        else: T += 1
    elif i == "S":
        S += 1
print T + S
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

def resolve(a):
    target = N
    result = 0
    for i in a:
        if target > i:
            target = i
            result += i
        else:
            result += target
    return result

print(sum([resolve(a[x:]) for x in range(N)]))


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

index = [-1] * (n + 1)
for i, v in enumerate(a):
    index[v] = i

area = [[i, i] for i in range(n + 1)]
result = 0
for i in range(n, 0, -1):
    position = index[i]
    l, r = area[position]
    area[r + 1][0] = l # right
    area[l - 1][1] = r # left
    result += (position - l + 1) * (r - position + 1) * i
print(result)

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

def resolve(a):
    target = N
    result = 0
    for i in a:
        if target > i: target = i
        result += target
    return result

print(sum([resolve(a[x:]) for x in range(N)]))


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

index = [-1] * (n + 1)
for i, v in enumerate(a):
    index[v] = i

area = [[i, i] for i in range(n + 1)]
result = 0
for i in range(n, 0, -1):
    position = index[i]
    l, r = area[position]
    area[r + 1][0] = l # right
    area[l - 1][1] = r # left
    result += (position - l + 1) * (r - position + 1) * i
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, input().split())
x = list(map(int, input().split()))

# import numpy as np
# dp = np.full((n + 1, n + 1, n * max(x + [a]) + 1), None).tolist()
#
def full(shape, value):
    if not shape:
        return value
    return [full(shape[1:], value) for _ in range(shape[0])]
dp = full((n + 1, n + 1, n * max(x + [a]) + 1), None)

def dfs(j=n, k=n, s=n * max(x)):
    if dp[j][k][s] is not None:
        return dp[j][k][s]
    if j == k == s == 0:
        dp[0][0][0] = 1
        return 1
    result = 0
    if j >= 1:
        if x[j - 1] > s:
            result = dfs(j - 1, k, s)
        elif k >= 1:
            result = dfs(j - 1, k, s) + dfs(j - 1, k - 1, s - x[j - 1])
    dp[j][k][s] = result
    return result

print(sum(dfs(n, k, k * a) for k in range(1, n + 1)))


Fixed submission:
n, a = map(int, input().split())
x = list(map(int, input().split()))

for i in range(n):
    x[i] -= a


def full(shape, value):
    if not shape:
        return value
    return [full(shape[1:], value) for _ in range(shape[0])]

minus_cnt = 0
plus_cnt = 0
for v in x:
    if v < 0:
        minus_cnt -= v
    elif v > 0:
        plus_cnt += v

dp = full((n + 1, minus_cnt + plus_cnt + 5, n + 1), None)
def dfs(k, s=0, depth=n - 1): # ret -> pattern count
    if dp[k][s][depth] is not None:
        return dp[k][s][depth]
    if k == 0:
        if s == 0:
            result = 1
        else:
            result = 0
        dp[k][s][depth] = result
        return result
    if depth == -1:
        dp[k][s][depth] = 0
        return 0
    result = dfs(k - 1, s + x[depth], depth - 1) + dfs(k, s, depth - 1)
    dp[k][s][depth] = result
    return result

result = 0
for i in range(1, n + 1):
    result += dfs(i)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 1
for i in range(n):
  ans *= a[i]
if ans > 10**18:
  print(-1)
else:
  print(ans)

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

if 0 in a:
    print(0)
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            break
    else:
      print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
roots = []
next_room = []
out = [0]*n
out[0] = 'Yes'
for _ in range(m):
    root = list(map(int, input().split()))
    if 1 in root:
        if root[0]==1:
            out[root[1]-1]=1
        else:
            out[root[0]-1]=1
    else:
        roots.append(root)
while True:
    out_tmp = out.copy()
    for root in roots:
        if out[root[0]-1] != 0 and out[root[1]-1] == 0:
            out_tmp[root[1]-1] = root[0]
        elif out[root[1]-1] != 0 and out[root[0]-1] == 0:
            out_tmp[root[0]-1] = root[1]
    out = out_tmp
    if out.count(0)==0:
        break
for o in out:
    print(o)

Fixed submission:
n, m = [int(x) for x in input().split()] # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].append(b)
    g[b-1].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u-1] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v-1]:
            if d[i-1] is None:
                d[i-1] = d[v-1] + 1
                queue.append(i)
    return d

d = bfs(1)
for i in range(n):
    if d[i] == 0:
        print('Yes')
    else:
        for j in g[i]:
            if d[i]-1==d[j-1]:
                print(j)
                break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
l = [i+1 + a[i] for i in range(n)]
r = [i+1 - a[i] for i in range(n)]
c = 0
for i in range(2, n):
    c += l.count(i)*r.count(i)
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
l = {}
r = {}
for i in range(n):
    if i+1+a[i] in l:
        l[i+1+a[i]] += 1
    else:
        l[i+1+a[i]] = 1
        
    if i+1-a[i] in r:
        r[i+1-a[i]] += 1
    else:
        r[i+1-a[i]] = 1

c = 0
for i in range(2, n):
    if i in l and i in r:
        c += l[i]*r[i]
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
c = 0
for i in range(1, n-2*mi+1):
    st = max(i+a[i-1], i+2*mi)
    for j in range(st, min(n+1, st+2*ma)):
        if j-i == a[i-1]+a[j-1]:
            c += 1
            
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
l = {}
r = {}
for i in range(n):
    if i+1+a[i] in l:
        l[i+1+a[i]] += 1
    else:
        l[i+1+a[i]] = 1
        
    if i+1-a[i] in r:
        r[i+1-a[i]] += 1
    else:
        r[i+1-a[i]] = 1

c = 0
for i in range(2, n):
    if i in l and i in r:
        c += l[i]*r[i]
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(1, n):
    for j in range(i+a[i-1], n+1):
        if j-i == a[i-1]+a[j-1]:
            c += 1
            
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
l = {}
r = {}
for i in range(n):
    if i+1+a[i] in l:
        l[i+1+a[i]] += 1
    else:
        l[i+1+a[i]] = 1
        
    if i+1-a[i] in r:
        r[i+1-a[i]] += 1
    else:
        r[i+1-a[i]] = 1

c = 0
for i in range(2, n):
    if i in l and i in r:
        c += l[i]*r[i]
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []

for i in range(n):
    w = input()
    if w not in l:
        l.append(w)

print(len(l))

Fixed submission:
n = int(input())
l = []
 
for i in range(n):
    l.append(input())
 
print(len(set(l)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

count = 0
for i in range(1, 10):
    for j in range(1, 10):
        cij = 0
        cji = 0
        
        for k in range(1, n+1):
            if str(k)[0] == str(i) and str(k)[-1] == str(j):
                cij += 1
                
            if str(k)[0] == str(j) and str(k)[-1] == str(i):
                cji += 1
        
        count += cij * cji

print(count)

Fixed submission:
n = input()
digit_num = len(n)
if digit_num == 1:
    print(n)

else:
    first_digit = int(n[0])
    last_digit = int(n[-1])
    n = int(n)
    count = 0
    
    for i in range(1, 10):
        for j in range(i, 10):
            ci = 0
            cj = 0
            
            if i == j:
                if i < first_digit:
                    for k in range(digit_num - 1):
                        ci += 10 ** k
                    ci += 1
                
                elif i == first_digit:
                    for k in range(digit_num - 2):
                        ci += 10 ** k
                    ci += 1
                    ci += (n % (10 ** (digit_num-1))) // 10
                    if last_digit >= i:
                        ci += 1
                
                else:
                    for k in range(digit_num - 2):
                        ci += 10 ** k
                    ci += 1
            
                count += ci ** 2
            
            else:
                if j < first_digit:
                    for k in range(digit_num - 1):
                        ci += 10 ** k
                    cj = ci
                
                elif j == first_digit:
                    for k in range(digit_num - 1):
                        ci += 10 ** k
                    for k in range(digit_num - 2):
                        cj += 10 ** k
                    cj += (n % (10 ** (digit_num-1))) // 10
                    if last_digit >= i:
                        cj += 1
                
                elif i < first_digit and j > first_digit:
                    for k in range(digit_num - 1):
                        ci += 10 ** k
                    for k in range(digit_num - 2):
                        cj += 10 ** k
                
                elif i == first_digit:
                    for k in range(digit_num - 2):
                        ci += 10 ** k
                    ci += (n % (10 ** (digit_num-1))) // 10
                    if last_digit >= j:
                        ci += 1
                    
                    for k in range(digit_num - 2):
                        cj += 10 ** k
                    
                else:
                    for k in range(digit_num - 2):
                        ci += 10 ** k
                    cj = ci
                    
                count += ci * cj * 2

    print(count)
Buggy python submission (verdict: Runtime Error):
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def combinations_count(n, r, factorials, invs):
    return (factorials[n] * invs[n-r] * invs[r]) % (10 ** 9 + 7)
 
f = open("151_E_max01", "r")
n, k = map(int, f.readline().split())
a = sorted(list(map(int, f.readline().split())))

factorials, invs = prepare(n, 10 ** 9 + 7)

ans = 0
for i in range(n):
    if i <= n - k:
        ans -= a[i] * combinations_count(n-i-1, k-1, factorials, invs)
    
    if i >= k - 1:
        ans += a[i] * combinations_count(i, k-1, factorials, invs)
    
    ans = ans % (10 ** 9 + 7)
 
print(ans)

Fixed submission:
import string

key = input()
alphabet = string.ascii_lowercase
print(alphabet[alphabet.index(key) + 1])
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions

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

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / fractions.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)

Fixed submission:
# coding: utf-8
# Your code here!
 
import fractions
 
n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))
 
for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = (lcm * numbers[i]) // fractions.gcd(lcm, numbers[i])
 
if (lcm//gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm // 2
    print((m - init_num) // lcm + 1)

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

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

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = math.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / math.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)
    

Fixed submission:
# coding: utf-8
# Your code here!
 
import fractions
 
n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))
 
for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = (lcm * numbers[i]) // fractions.gcd(lcm, numbers[i])
 
if (lcm//gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm // 2
    print((m - init_num) // lcm + 1)

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

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

for i in range(len(numbers)):
    if i == 0:
        a = numbers[i]
    else:
        a = fractions.gcd(a, numbers[i])

lcm = a
for i in range(len(numbers)):
    lcm *= int(numbers[i] / a)

if int(lcm/a) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int((m - init_num) // lcm) + 1)

Fixed submission:
# coding: utf-8
# Your code here!
 
import fractions
 
n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))
 
for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = (lcm * numbers[i]) // fractions.gcd(lcm, numbers[i])
 
if (lcm//gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm // 2
    print((m - init_num) // lcm + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

num = int(input())
l = list(map(int, input().split()))

total = 0
for i in range(1, num+1):
    for diff_num in itertools.combinations(l, i):
        diff_num = sorted(list(diff_num))
        for j in range(len(diff_num)):
            total += diff_num[j] * (len(diff_num) - j)

total *= 2 ** num
ans = total % (10 ** 9 + 7)
print(ans)

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

num = int(input())
costs = sorted(list(map(int, input().split())), reverse = True)

total = 0
for i in range(1, num+1):
    total += (i + 1) * costs[i-1]
ans = (total * (4 ** (num - 1))) % (10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
c = math.gcd(a, b)
print(a * b // c)

Fixed submission:
import fractions

a, b = map(int, input().split())
c = fractions.gcd(a, b)
print(a * b // c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

	print(n - cnt + 1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

	print(n - cnt + 1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

print(n - cnt + 1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)

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

if a.count(1) == 0:
    print(-1)
else:
    i = 1
    idx = 0
    while idx < n:
        if i in a[idx:]:
            idx += a[idx:].index(i) + 1
            i += 1
        else:
            break

    print(n-i+1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)

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

i = 0
while i < len(a):
    if a[i] != i+1:
        a.remove(a[i])
        continue
    
    i += 1

if len(a) == 0:
    print(-1)
else:
    print(n-len(a))

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)