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

def count_factor(factor, factors):
    count = 0
#    print("factor: " + str(factor))
#    print(factors)

    for f in factors:
        if f == factor:
            count += 1

    return count

def divide_to_prime_factors(num):
    factor = 1
    factors = []

    while factor <= math.sqrt(num):
        if num % factor == 0:
            factors.append(factor)
            if factor * factor != num:
                factors.append(int(num / factor))

        factor += 1

    return factors

n_and_x = input().split(" ")
city_num = int(n_and_x[0])
start = int(n_and_x[1])

city_places = [int(n) for n in input().split(" ")]

city_distances = []
for place in city_places:
    city_distances.append(abs(place - start))

dist_factors = []
for dist in city_distances:
    dist_factors.extend(divide_to_prime_factors(dist))
#print(dist_factors)

step = 1
for factor in dist_factors:
    if factor > step:
        fact_count = count_factor(factor, dist_factors)
#        print(fact_count)
        if fact_count == city_num:
            step = factor

#step = int(max(city_distances) / 2)

#can_travel = False
#while can_travel == False:
#    can_travel = True
#    for city in city_places:
#        if abs(city - start) % step != 0:
#           can_travel = False
#    if can_travel == False:
#        step -= 1

print(step)

Fixed submission:
import math

def is_common(dists, factor):
    count = 0
#    print("factor: " + str(factor))
#    print(factors)
#    print(factor)
#    print(factors[1:]

    for dist in dists:
        if dist % factor != 0:
            return False
    
    return True

def divide_to_prime_factors(num):
    factor = 1
    factors = []

    while factor <= math.sqrt(num):
        if num % factor == 0:
            factors.append(factor)
            if factor * factor != num:
                factors.append(int(num / factor))

        factor += 1

    return factors

n_and_x = input().split(" ")
city_num = int(n_and_x[0])
start = int(n_and_x[1])

city_places = [int(n) for n in input().split(" ")]

city_distances = []
for place in city_places:
    city_distances.append(abs(place - start))

dist_factors = reversed(sorted(divide_to_prime_factors(city_distances[0])))

step = 1
for fact in dist_factors:
    if is_common(city_distances[1:], fact):
        step = fact
        break

#        print(fact_count)
#step = int(max(city_distances) / 2)

#can_travel = False
#while can_travel == False:
#    can_travel = True
#    for city in city_places:
#        if abs(city - start) % step != 0:
#           can_travel = False
#    if can_travel == False:
#        step -= 1

print(step)
Buggy python submission (verdict: Runtime Error):
l,r,d = map(int,input())
c = 0
for i in range(l,r+1):
  if i%d == 0:
    c += 1
print(c)

Fixed submission:
l,r,d = map(int,input().split())
c = 0
for i in range(l,r+1):
  if i%d == 0:
    c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        c2[si+int(s[j])*10+int(s[k])*100] = 1
print(sum(c2))
    
    

Fixed submission:
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
count = 0
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    c3 = [False for _ in range(10)]
    for j in range(i+1,n-1):
      sj = int(s[j])
      if c3[sj] != True:
        c3[sj] = True
        c4 = [False for _ in range(10)]
        for k in range(j+1,n):
          sk = int(s[k])
          if c4[sk] != True:
            c4[sk] = True
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 + = 1
  x = hen(x)
print(min(c1,c2))

Fixed submission:
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 += 1
  x = hen(x)
print(min(c1,c2))
Buggy python submission (verdict: Runtime Error):
class UnionFind:
  def __init__(self, N):
    self.r = [-1]*(N+1)
  
  def root(self, x):
    if self.r[x] < 0:
      return x
    else:
      self.r[x] = self.root(self.r[x])
      return self.r[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x == y:
      return False
    else:
      self.r[x] += self.r[y]
      self.r[y] = x
      return True
    
  def size(self, x):
    return -1*self.r[self.root(x)]
  
  def print(self):
    print(self.r)


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

UF = UnionFind(N)

for _ in range(M):
  a, b = map(int, input().split())
  UF.unite(a-1, b-1)

ans = 0
for i in range(N):
  ans = max(ans, UF.size(i))

print(ans)

Fixed submission:
class UnionFind:
  def __init__(self, N):
    self.r = [-1]*N
  
  def root(self, x):
    if self.r[x] < 0:
      return x
    else:
      self.r[x] = self.root(self.r[x])
      return self.r[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x == y:
      return False
    else:
      if self.r[x] > self.r[y]:
        x, y = y, x
      self.r[x] += self.r[y]
      self.r[y] = x
      return True
    
  def size(self, x):
    return -1*self.r[self.root(x)]
  
  def print(self):
    print(self.r)


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

UF = UnionFind(N)

for _ in range(M):
  a, b = map(int, input().split())
  UF.unite(a-1, b-1)

ans = 0
for i in range(N):
  ans = max(ans, UF.size(i))

print(ans)

Buggy python submission (verdict: Runtime Error):
class UnionFind:
  def __init__(self, N):
    self.r = [-1]*N
  
  def root(self, x):
    if self.r[x] < 0:
      return x
    else:
      self.r[x] = self.root(self.r[x])
      return self.r[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x == y:
      return False
    else:
      self.r[x] += self.r[y]
      self.r[y] = x
      return True
    
  def size(self, x):
    return -1*self.r[self.root(x)]
  
  def print(self):
    print(self.r)


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

UF = UnionFind(N)

for _ in range(M):
  a, b = map(int, input().split())
  UF.unite(a-1, b-1)

ans = 0
for i in range(N):
  ans = max(ans, UF.size(i))

print(ans)

Fixed submission:
class UnionFind:
  def __init__(self, N):
    self.r = [-1]*N
  
  def root(self, x):
    if self.r[x] < 0:
      return x
    else:
      self.r[x] = self.root(self.r[x])
      return self.r[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x == y:
      return False
    else:
      if self.r[x] > self.r[y]:
        x, y = y, x
      self.r[x] += self.r[y]
      self.r[y] = x
      return True
    
  def size(self, x):
    return -1*self.r[self.root(x)]
  
  def print(self):
    print(self.r)


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

UF = UnionFind(N)

for _ in range(M):
  a, b = map(int, input().split())
  UF.unite(a-1, b-1)

ans = 0
for i in range(N):
  ans = max(ans, UF.size(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
C = list(map(int, input().split()))

R_cnt = C.count('R')
x = C[:R_cnt].count('R')

print(R_cnt-x)

Fixed submission:
N = int(input())
C = input()
 
R_cnt = C.count('R')
x = C[:R_cnt].count('R')
 
print(R_cnt-x)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
K = int(input())

for i in range(K):
  if A >= B:
    B = B*2
  elif B >= C:
    C = C*2
  else:
    break

if A<B<C:
  print(Yes)
else:
  print(No)

Fixed submission:
A, B, C = map(int, input().split())
K = int(input())
 
for i in range(K):
  if A >= B:
    B = B*2
  elif B >= C:
    C = C*2
  else:
    break

if A<B<C:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split())).sorted()
 
len_A = len(A)
ans = 0
for i in range(1, len_A-1):
  ans += A[len_A-1-int(i/2)]

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()

len_A = len(A)
ans = 0
for i in range(1, len_A):
  ans += A[len_A-1-int(i/2)]

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split())).sort()

len_A = len(A)
ans = 0
for i in range(1, len_A-1):
  ans += A[len_A-1-int(i/2)]

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()

len_A = len(A)
ans = 0
for i in range(1, len_A):
  ans += A[len_A-1-int(i/2)]

print(ans)
Buggy python submission (verdict: Runtime Error):
S, T = map(int, input().split())

cnt = 0
for s, t in zip(S, T):
  if s != t:
    cnt += 1

print(cnt)

Fixed submission:
S = input()
T = input()

cnt = 0
for s, t in zip(S, T):
  if s != t:
    cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
ps = list(map(int, input().split()))

for i in range(50):
  if X-i not in ps:
    print(X-i)
    break
  elif X+i not in ps:
    print(X+i)
    break

Fixed submission:
X = list(map(int, input().split()))
for i in range(len(X)):
  if X[i] == 0:
    print(i+1)
    break

Buggy python submission (verdict: Runtime Error):
X = map(int, input().split())
for i in range(len(X)):
  if X[i] == 0:
    print(i+1)
    break

Fixed submission:
X = list(map(int, input().split()))
for i in range(len(X)):
  if X[i] == 0:
    print(i+1)
    break
Buggy python submission (verdict: Runtime Error):
str_n = input()
str_an = input()

n = int(str_n)
an = [int(ai) for ai in str_an.split()]

ans = 1
for ai in an:
  ans *= ai

if ans > 1e8:
  ans = -1
  
print(ans)


Fixed submission:
def main():
  l = input().split()
  A, B = int(l[0]), float(l[1])
  B100 = int(B*1000)
  ans = int((A*B100)/1000)
  print(ans)
  return

main()
Buggy python submission (verdict: Runtime Error):
import math
from decimal import Decimal
a, b = input().split()
//a = decimal.Decimal(a)
//b = decimal.Decimal(b)
print(math.floor(Decimal(a) * Decimal(b)))


Fixed submission:
import math
import decimal
a, b = input().split()
a = decimal.Decimal(a)
b = decimal.Decimal(b)
print(math.floor(a * b))

Buggy python submission (verdict: Runtime Error):
def main():
  l = input().split()
  A, B = int(l[0]), int(l[1])
  print(int((A*(B*100))/100))

main()


Fixed submission:
import math
import decimal
a, b = input().split()
a = decimal.Decimal(a)
b = decimal.Decimal(b)
print(math.floor(a * b))

Buggy python submission (verdict: Runtime Error):
def main():
  l = input().split()
  A, B = int(l[0]), int(l[1])
  print(int(A*(B*100)/100))

main()

Fixed submission:
import math
import decimal
a, b = input().split()
a = decimal.Decimal(a)
b = decimal.Decimal(b)
print(math.floor(a * b))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
if S == T[:-1] and len(len(S)==len(T)+1):
  print('Yes')
else:
  print('No')

Fixed submission:
S = input()
T = input()
if S == T[:-1] and (len(S)+1)==len(T):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N, M, X = map(int, input().split())
book = [[map(int, input().split())] for i in range(N)]

min_value = -1
for i in range(2**N):
  sum = [0 for k in range(M+1)]
  for j in range(N):
    if (i >> j) & 1:
      sum = [x+y for x, y in zip(sum, book[N+1])]
  if min(sum[1:]) >= X and min_value > sum[0]:
    min_value = sum[0]

print(min_value)

Fixed submission:
N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for i in range(N)]

min_value = -1
for i in range(2**N):
    sum = [0 for k in range(M+1)]
    for j in range(N):
        if (i >> j) & 1:
            sum = [x+y for x, y in zip(sum, book[j])]
    if min(sum[1:]) >= X and (min_value > sum[0] or min_value == -1):
        min_value = sum[0]

print(min_value)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
sweet = [0 for i in range(N)]
for i in range(K):
  input()
  for j in map(int, input().split()):
    sweet[j] = 1
cnt = 0
for k in sweet:
  if k == 0:
    cnt += 1
print(cnt)

Fixed submission:
N, K = map(int, input().split())
sweet = [0 for i in range(N)]
for i in range(K):
  s = input()
  for j in map(int, input().split()):
    sweet[j-1] = 1
cnt = 0
for k in sweet:
  if k == 0:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A, B = map(int, input().split())

for i in range(A, B):
  if i % K == 0:
    print('OK')
    sys.exit()
print('NG')

Fixed submission:
import sys
K = int(input())
A, B = map(int, input().split())

for i in range(A, B+1):
  if i % K == 0:
    print('OK')
    sys.exit()
print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
 
now = 0
cnt = 0
while now < X:
  cnt += 1
  now + int(now*0.01)
print(cnt)

Fixed submission:
X = int(input())
 
now = 100
cnt = 0
while now < X:
  cnt += 1
  now += int(now*0.01)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

now = 0
cnt = 0
while now < X:
  cnt += 1
  now = int(now*1.01)
print(cnt)

Fixed submission:
X = int(input())
 
now = 100
cnt = 0
while now < X:
  cnt += 1
  now += int(now*0.01)
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
reqs = [list(map(int, input().split())) for _ in range(Q)]

As = []

def make(A):
  global As, N, M
  if len(A) == N+1:
    As.append(A)
  elif:
    for i in range(A[len(A)-1], M+1):
      A.append(i)

make([1])

max = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  max = max(score, max)

print(max)

Fixed submission:
N, M, Q = map(int, input().split())
reqs = [list(map(int, input().split())) for _ in range(Q)]

As = []

def make(A):
  global As, N, M
  # print(A)
  if len(A) == N+1:
    As.append(A)
  else:
    for i in range(A[len(A)-1], M+1):
      make(A+[i])

make([1])

maxs = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  maxs = max(score, maxs)

print(maxs)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
 
while true:
  if C - B <= 0:
    print('Yes')
    break
  else:
    C = C - B
  if A - D <= 0:
    print('No')
    break
  else:
    A = A - D

Fixed submission:
A, B, C, D = map(int, input().split())
 
while True:
  if C - B <= 0:
    print('Yes')
    break
  else:
    C = C - B
  if A - D <= 0:
    print('No')
    break
  else:
    A = A - D

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())
 
while True:
  if C - B <= 0:
    print('Yes')
  else:
    C = C - B
  if A - D <= 0:
    print('No')
  else:
    A = A - D

Fixed submission:
A, B, C, D = map(int, input().split())
 
while True:
  if C - B <= 0:
    print('Yes')
    break
  else:
    C = C - B
  if A - D <= 0:
    print('No')
    break
  else:
    A = A - D

Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

while true:
  if C - B <= 0:
    print('Yes')
  else:
    C = C - B
  if A - D <= 0:
    print('No')
  else:
    A = A - D

Fixed submission:
A, B, C, D = map(int, input().split())
 
while True:
  if C - B <= 0:
    print('Yes')
    break
  else:
    C = C - B
  if A - D <= 0:
    print('No')
    break
  else:
    A = A - D
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

mmin = sum(A) * (4*M)
A.sort()

if A[m-1] < mmin:
  print('No')
else:
  print('Yes')

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
mmin = sum(A) / (4*M)
A.sort(reverse=True)
 
if A[M-1] < mmin:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
import math
 
N, M = map(int, input().split())

ans1 = 0
if N > 1:
  ans1 = math.factorial(N)/math.factorial(N-2)/2
ans2 = 0
if N > 1:
  ans2 = math.factorial(M)/math.factorial(M-2)/2
print(int(ans1 + ans2))

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)

Buggy python submission (verdict: Runtime Error):
import math
 
N, M = map(int, input().split())

ans1 = 0
if N != 0:
  ans1 = math.factorial(N)/math.factorial(N-2)/2
ans2 = 0
if N != 0:
  ans2 = math.factorial(M)/math.factorial(M-2)/2
print(int(ans1 + ans2))

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)

Buggy python submission (verdict: Runtime Error):
import math
 
N, M = map(int, input().split())

ans1 = math.factorial(N)/math.factorial(N-2)/2
ans2 = math.factorial(M)/math.factorial(M-2)/2
print(int(ans1 + ans2))

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)

Buggy python submission (verdict: Runtime Error):
import math
 
N, M = map(int, input().split())

ans1 = math.factorial(N)/math.factorial(N-2)/2
ans2 = math.factorial(M)/math.factorial(M-2)/2
print(int(ans1 + ans2))

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)

Buggy python submission (verdict: Runtime Error):
import math
 
N, M = map(int, input().split())

ans1 = math.factorial(N)//math.factorial(N-2)//2
ans2 = math.factorial(M)//math.factorial(M-2)//2
print(ans1 + ans2)

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)

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

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

print(math.factrial(N)//2 + math.factrial(M)//2)

Fixed submission:
N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)
Buggy python submission (verdict: Runtime Error):
def is_kaibun(st):
  f = True
  for x,y in zip(st, st[::-1]):
    if x != y:
      f = False
      break
  return f

S = input()
ans = False
if is_kaibun(S):
  if is_kaibun(S[:(len(S)-1)/2+1]):
    ans = is_kaibun(S[(len(S)+3)/2+1])
if ans:
  print('Yes')
else:
  print('No')
  

Fixed submission:
def is_kaibun(st):
  f = True
  for x,y in zip(st, st[::-1]):
    if x != y:
      f = False
      break
  return f
 
S = input()
ans = False
if is_kaibun(S):
  if is_kaibun(S[:(len(S)-1)//2]):
    ans = is_kaibun(S[(len(S)+3)//2-1:])
if ans:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
 
ans = 1
while 1:
  if N >= K ** ans:
    ans += 1
    continue
  else:
    print(ans)

Fixed submission:
N, K = map(int, input().split())
 
ans = 1
while 1:
  if N >= K ** ans:
    ans += 1
    continue
  else:
    print(ans)
    break

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())

ans = 1
while 1:
  if N >= K ** ans:
    ans += 1
    continue
  else:
    print(ans)

Fixed submission:
N, K = map(int, input().split())
 
ans = 1
while 1:
  if N >= K ** ans:
    ans += 1
    continue
  else:
    print(ans)
    break
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

mmax = 0
idx = 0
for i in range(N-K+1):
  score = sum(P[i:i+K])
  if score > mmax:
    mmax = score
    idx = i
  else:
    continue

print((K+mmax)/2)

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))

score = sum(P[:K])
mmax = score
idx = 0
for i in range(1, N-K+1):
  score = score - P[i-1] + P[i+K-1]
  if score > mmax:
    mmax = score
    idx = i
  else:
    continue

print((K+mmax)/2)
Buggy python submission (verdict: Time Limit Exceeded):
H = [int(input())]
 
ans = 0
while len(H):
  ans += 1
  m = H.pop(0)
  if m == 1:
    continue
  else:
    H = H + [m//2, m//2]
print(ans)

Fixed submission:
H = int(input())

def f(H):
  if H == 1:
    return 1
  else:
    return 2*f(H//2)+1

print(f(H))

Buggy python submission (verdict: Runtime Error):
H = [int(input().split())]

ans = 0
while len(H) == 0:
  ans += 1
  m = H.pop(0)
  if m == 1:
    continue
  else:
    H = H + [m//2, m//2]
print(ans)

Fixed submission:
H = int(input())

def f(H):
  if H == 1:
    return 1
  else:
    return 2*f(H//2)+1

print(f(H))
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

mmin = P[0]
ans = 0
for i in range(N):
  if mmin < P[i]:
    continue
  else:
    mmin >= P[i]:
      mmin = P[i]
      ans += 1

print(ans)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
 
mmin = P[0]
ans = 0
for i in range(N):
  if mmin < P[i]:
    continue
  else:
    mmin = P[i]
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

l = permutations(range(1,N+1))

print(abs(l.index(P)-l.index(Q)))

Fixed submission:
from itertools import permutations
 
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
 
l = list(permutations(range(1,N+1)))
 
print(abs(l.index(P)-l.index(Q)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

cnt = 0
idx = 0
while 1:
  if (cnt+1) in A[idx:]:
    cnt += 1
    idx = A.index(cnt)

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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

k = 1
ans = 0

if 1 not in A:
  print(-1)
  exit()

for a in A:
  if a == k:
    k += 1
  else:
    ans += 1

print(ans)

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

idx = 0
ans = 0
while 1:
  if idx >= len(A):
    break
  elif A[idx] == idx+1:
    idx += 1
  else:
    A.pop(idx)
    ans += 1

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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

k = 1
ans = 0

if 1 not in A:
  print(-1)
  exit()

for a in A:
  if a == k:
    k += 1
  else:
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
idx = 0
ans = 0
while 1:
  if idx >= len(A):
    break
  elif A[idx] == idx+1:
    idx += 1
  else:
    A.pop(idx)
    ans += 1

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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

k = 1
ans = 0

if 1 not in A:
  print(-1)
  exit()

for a in A:
  if a == k:
    k += 1
  else:
    ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input()))

idx = 0
ans = 0
while 1:
  if idx >= len(A):
    exit()
  elif A[idx] == idx+1:
    idx += 1
  else:
    A.pop(idx)
    ans += 1

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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

k = 1
ans = 0

if 1 not in A:
  print(-1)
  exit()

for a in A:
  if a == k:
    k += 1
  else:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import math

N = int(input())
X = [list(map(int, input().split)) for _ in range(N)]

l = [i for i in range(N)]
ssum = 0
for v in itertools.permutations(l):
  distance = 0
  pre = [0, 0]
  for n in v:
    distance += math.sqrt((pre[0]-X[n][0])**2+(pre[1]-X[n][1])**2)
    pre = X[n]
  ssum += distance

print(ssum/math.factorial(N))

Fixed submission:
import itertools
import math
 
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

l = [i for i in range(N)]
ssum = 0
for v in itertools.permutations(l):
  distance = 0
  pre = X[v[0]]
  for n in v:
    distance += math.sqrt((pre[0]-X[n][0])**2+(pre[1]-X[n][1])**2)
    pre = X[n]
  ssum += distance

print(ssum/math.factorial(N))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

for i in reverse(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break

Fixed submission:
import math
 
N = int(input())
 
for i in reversed(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break