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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

  
n = int(input())
if n == 1:
  print(0)
  sys.exit()

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

pow8 = [0]*(n+1)
pow8[0] = 1
for i in range(1,n+1):
  pow8[i] = (pow8[i-1]*8) % mod


ans = (10**n) % mod - pow8[n]
for i in range(1,n+1):
  ans = (ans - pow8[n-i]*2*cmb(n,i,mod)) % mod
               
print(ans)

Fixed submission:
import sys

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

n = int(input())
if n == 1:
  print(0)
  sys.exit()

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
pow8 = [0]*(n+1)
pow8[0] = 1
pow8[1] =8

pow10=10

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    pow8[i] = (pow8[i-1]*8) % mod  
    pow10 =(pow10*10) % mod
ans = pow10 - pow8[n]
for i in range(1,n+1):
  ans = (ans - pow8[n-i]*2*cmb(n,i,mod)) % mod
               
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = tuple(map(int,input().split()))

mod = 10**9 +7
ans = 0
for i in range(n):
  ans += (sum(a[i+1:]) % mod) *a[i]
print(ans % mod)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)

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

mod = 10**9 + 7
at = [a[i] % mod for i in range(n)]

ans = 0
for i in range(n):
  ans += (sum(at[i+1:]) % mod) *at[i]
print(ans % mod)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)

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

mod = 10**9 + 7
at = tuple([a[i] % mod for i in range(n)])

ans = 0
for i in range(n):
  ans += sum(at[i+1:])*at[i]
print(ans % mod)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)

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

mod = 10**9 + 7
at = tuple([a[i] % mod for i in range(n)])

ans = 0
for i in range(n):
  atemp = at[i]
  for j in range(i+1,n):
    ans += (atemp * (at[j])) % mod
    ans = ans % mod
print(ans % mod)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)

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

mod = 10**9 + 7
for i in range(n):
  a[i] = a[i] % mod

ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += (a[i]) * (a[j])
print(ans % mod)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)

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

mod = 10**9 + 7
ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += (a[i] * a[j])
    ans = ans % mod
    
print(ans)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

ans = 0
for i in range(n-1):
  ans += at[n-2-i] *a[i]
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
n, x, t = map(int, input())
ans = n//x 
if n%x != 0:
  ans += 1
print(int(ans)*t)

Fixed submission:
n, x, t = map(int, input().split())
ans = n//x 
if n%x != 0:
  ans += 1
print(int(ans)*t)
Buggy python submission (verdict: Runtime Error):
k = int(input())
if k % 2 == 0:
  print(-1)
nana = 0
ans = 0
print(len(k))
while True:
  nana += (10**ans) * 7
  #print(nana)
  if nana % k == 0:
    print(ans + 1)
    break
  ans += 1

Fixed submission:
k = int(input())
if k % 2 == 0:
    print(-1)
elif k in [1,7]:
  	print(1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
if k % 2 == 0:
  print(-1)
nana = 0
ans = 0
while True:
  nana += (10**ans) * 7
  #print(nana)
  if nana % k == 0:
    print(ans + 1)
    break
  ans += 1

Fixed submission:
k = int(input())
if k % 2 == 0:
    print(-1)
elif k in [1,7]:
  	print(1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
h, w, k = map(int,input().split())
c = []
for i in range(h):
  c.append(input())
  
def countb(c):
  num = 0
  for i in range(h):
    num += c[i].count("#")
  return(num)

def printb(c, row, col):
  c = c[:]
  #print(row,col)
  cnt = 0
  while row != 0:
    if row  & 0b1:
     
      c[cnt] = "."*w
    cnt += 1
    row = row >> 1
  
  cnt = 0
  while col != 0:
    #print(col&0b1)
    if col & 0b1:
      for i in range(h):
        c[i] = c[i][:cnt]+"."+c[i][cnt+1:]
    cnt += 1
    col = col >> 1
    
  #print("\n".join(c))
  return countb(c)

if countb(c) == k:
  print(0)
else:
  ans = 0
  for i in range(2**h):
    for j in range(2**w):
      if printb(c,i,j) == k:
        ans += 1
        
  
print(ans)


Fixed submission:
h, w, k = map(int,input().split())
c = []
for i in range(h):
  c.append(input())
  
def countb(c):
  num = 0
  for i in range(h):
    num += c[i].count("#")
  return(num)

def printb(c, row, col):
  c = c[:]
  #print(row,col)
  cnt = 0
  while row != 0:
    if row  & 0b1:
     
      c[cnt] = "."*w
    cnt += 1
    row = row >> 1
  
  cnt = 0
  while col != 0:
    #print(col&0b1)
    if col & 0b1:
      for i in range(h):
        c[i] = c[i][:cnt]+"."+c[i][cnt+1:]
    cnt += 1
    col = col >> 1
    
  #print("\n".join(c))
  return countb(c)

ans = 0
for i in range(2**h):
  for j in range(2**w):
    if printb(c,i,j) == k:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
print(a+a**2+a***3)

Fixed submission:
a = int(input())
print(a+a**2+a**3)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
 
ans = 0:
for i in range(len(s)):
  if s[i] != t[i]:
    ans += 1
print(ans)

Fixed submission:
s = input()
t = input()
 
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

ans = 0:
for i in range(s):
  if s[i] != t[i]:
    ans += 1
print(ans)

Fixed submission:
s = input()
t = input()
 
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

num_dict = dict()
for i in a:
    if i in num_dict.keys():
        num_dict[i] += 1
    else:
        num_dict[i] = 1

for i in range(q):
    ans = 0
    if b[i] in num_dict:
        if c[i] in num_dict:
            num_dict[c[i]] += num_dict.pop(b[i])
        else:
            num_dict[c[i]] = num_dict.pop(b[i])
    for k, v in num_dict.items():
        ans += k*v
    print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

num_dict = dict()
for i in a:
    if i in num_dict.keys():
        num_dict[i] += 1
    else:
        num_dict[i] = 1

ans = 0       
for k, v in num_dict.items():
  ans += k*v
 
for i in range(q):
    if b[i] in num_dict:
        if c[i] in num_dict:
            ans += (c[i] - b[i]) * num_dict[b[i]]
            num_dict[c[i]] += num_dict.pop(b[i])
        else:
            ans += (c[i] - b[i]) * num_dict[b[i]]
            num_dict[c[i]] = num_dict.pop(b[i])
    #print(num_dict)
    print(ans)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  for i in range(-1, 100):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  for i in range(1, 100):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  p1 = {i for i in range(p[0],p[-1]+1)}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
      value = x - p2[i]
  print(x - value)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  p1 = {i for i in range(p[-1])}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
      value = x - p2[i]
  print(x - value)  

Fixed submission:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for i in A:
        ans *= i
if ans >10**18:
        print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
A = sorted(map(int,input().split()), reverse = True)

if 0 in A:
    print(0)
else:
    ans = 1
    for i in A:
        ans *= i
        if ans >10**18:
            print(-1)
            break
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

fact={}
i = 2
while n != 1:
    if n % i == 0:
        n = n/i
        if i in fact:
            fact[i] += 1
        else:
            fact[i] = 1
    else:
        i += 1
    if i > (n**(1/2)+1):
        fact[n] =1
        break

#print(fact)
if fact == {}:
    print(0)
else:
    ans = 0
    for v in fact.values():
        #print(v)
        for i in range(1,v+1):
            if v - i >= 0:
                ans +=1
                v = v-i
                
print(ans)

Fixed submission:
n = int(input())

fact={}
i = 2
while n != 1:
    if n % i == 0:
        n = n/i
        if i in fact:
            fact[i] += 1
        else:
            fact[i] = 1
    else:
        i += 1
    if i > (n**(1/2)+1):
        if n in fact:
            fact[n] += 1
        else:
            fact[n] = 1
        break

if fact == {}:
    print(0)
else:
    ans = 0
    for v in fact.values():
        #print(v)
        for i in range(1,v+1):
            if v - i >= 0:
                ans +=1
                v = v-i
    print(ans)
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
 
if A[0]>=A[3]:
  print(A[0])
else:
  if A[0]+A[1]>=A[3]:
    print(A[0])
  else:
    print(A[0]-A[3]+A[0]+A[1])

Fixed submission:
s = input()
t = input()


if s == t[:-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
 
if A[0]>=A[3]:
  print(A[0])
else:
  if A[0]+A[1]>=A[3]:
    print(A[0])
  else:
    print(A[0]-A[3]+A[0]+A[1])

Fixed submission:
s = input()
t = input()


if s == t[:-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split())) 

ans=0
if A[0]<A[3]:
  ans = A[0]
else:
  ans = A[3]
  print(ans)
  
print(ans-(A[3]-A[0]-A[1])

Fixed submission:
A = list(map(int, input().split()))
 
if A[0]>=A[3]:
  print(A[3])
else:
  if A[0]+A[1]>=A[3]:
    print(A[0])
  else:
    print(A[0]-A[3]+A[0]+A[1])
Buggy python submission (verdict: Runtime Error):
N, M = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
  a, b = (int(i) for i in input().split())
  if H[a-1] <= H[b-1]:
    ans[a-1] = 0
  elif H[a-1] > H[b-1]:
    ans[b-1] = 0
print(ans.count(1))

Fixed submission:
n = input()
if n == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
  a, b = (int(i) for i in input().split())
  if H[a-1] <= H[b-1]:
    ans[a-1] = 0
  elif H[a-1] > H[b-1]:
    ans[b-1] = 0
print(ans.count(1))

Fixed submission:
n = input()
if n == "ABC":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
  a, b = (int(i) for i in input().split())
  if H[a-1] < H[b-1]:
    ans[a-1] = 0
  elif H[a-1] > H[b-1]:
    ans[b-1] = 0
print(ans.count(1))

Fixed submission:
N, M = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
    a, b = (int(i) for i in input().split())
    if H[a-1] < H[b-1]:
        ans[a-1] = 0
    elif H[a-1] > H[b-1]:
        ans[b-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(ans.count(1))
Buggy python submission (verdict: Runtime Error):
s, w = map(int, input().split())
if s > w:
  print(safe)
else:
  print(unsafe)

Fixed submission:
s, w = map(int, input().split())
if s > w:
  print("safe")
else:
  print("unsafe")
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      ans += gcd(a,b,c)
print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
  for b in range(a, k+1):
    for c in range(b, k+1):
      t = len({a,b,c})
      if t == 3:
        ans += gcd(a,b,c) * 6
      elif t == 2:
        ans += gcd(a,b,c) * 3
      else:
        ans += gcd(a,b,c)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n
  while ans > abs(n-k):
    n = abs(n - k)
    ans = min(n, ans)
  print(ans)

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

if n % k == 0:
  print(0)
else: 
  ans = n % k
  #print(ans)
  while ans > k//2:
    n = abs(ans - k)
    ans = min(n, ans)
  print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input())
ans = n*(n-1)/2 + m*(m-1)/2
print(ans)

Fixed submission:
n, m = map(int, input().split())
ans = n*(n-1)/2 + m*(m-1)/2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
print("x"*len(input())

Fixed submission:
print("x"*len(input()))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, k = map(int, input().split())
p = list(map(int,input().split()))

kitai = [0]*1000
tmp = 0
for i in range(1000):
  tmp += i+1
  kitai[i] = tmp/(i+1)
#print(kitai)
  

window = deque([kitai[p[i]-1] for i in range(k)])
ans = sum(window)
for i in range(n-k+1):
  #print(window)
  window.popleft()
  window.append(kitai[p[i+k-1]-1])
  ans = max(sum(window),  ans)
print(ans)
         

Fixed submission:
from collections import deque
n, k = map(int, input().split())
p = list(map(int,input().split()))

kitai = [0]*1000
tmp = 0
for i in range(1000):
  tmp += i+1
  kitai[i] = tmp/(i+1)
#print(kitai)

total_kitai = [0]*(n+1)
tmp = 0
for i in range(n):
  tmp += kitai[p[i]-1]
  total_kitai[i+1] = tmp
#print(total_kitai)

ans = 0
for i in range(n-k+1):
  ans = max(total_kitai[i+k]-total_kitai[i],  ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
h,a = map(int,input().split())
ans = 0
for h >0:
  h -= a
  ans += 1
print(ans)

Fixed submission:
h,a = map(int,input().split())
ans = 0
while h >0:
  h -= a
  ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
c = input()
al = "abcdefghijklmnopqrstuvwxz"
print(al[al.index(c)+1])

Fixed submission:
c = input()
al = "abcdefghijklmnopqrstuvwxyz"
print(al[al.index(c)+1])
Buggy python submission (verdict: Runtime Error):
k, x = map(int, input())
if (500*k) >= x:
  print("Yes")
else:
  print("No")

Fixed submission:
k, x = map(int, input().split())
if (500*k) >= x:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
a = list(map(int,input().split()))

seta = set(a)
ans = 0
if 1 not in seta:
  print(-1)
  sys.exit()
for i in range(1,n+1):
  if i in seta:
    idx = a.index(i)
  else:
    ans += len(a) 
    break 
  ans += idx
  a = a[idx+1:]
  seta = set(a)
  
print(ans)


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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
  
index = 1
for i in a:
  if i != index:
    ans+=1
  else:
    index+=1
    
print(ans)

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

seta = set(a)
ans = 0
if 1 not in seta:
  print(-1)
  sys.exit()
for i in range(1,n+1):
  if i in seta:
    idx = a.index(i)
  else:
    ans += len(a) 
    break 
  ans += idx
  a = a[idx+1:]
  
print(ans)


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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
  
index = 1
for i in a:
  if i != index:
    ans+=1
  else:
    index+=1
    
print(ans)

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

seta = set(a)
ans = 0
if 1 not in seta:
  print(-1)
  sys.exit()
for i in range(1,n+1):
  if i in seta:
    idx = a.index(i)
  else:
    ans += len(a) 
    break 
  ans += idx
  a = a[idx+1:]
  
print(ans)


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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
  
index = 1
for i in a:
  if i != index:
    ans+=1
  else:
    index+=1
    
print(ans)

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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
for i in range(1,n+1):
  if i in a:
    idx = a.index(i)
  else:
    ans += len(a) 
    break 
  ans += idx
  a = a[idx+1:]
  
print(ans)


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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
  
index = 1
for i in a:
  if i != index:
    ans+=1
  else:
    index+=1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k  = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*(n+1)
dp[0] = 0

for i in range(1,n):
  dp[i] = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2,min(i+1,k+1)):
    dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))    
  #print(dp[i])
print(dp[n-1])

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

dp = [0]*(n+1)
dp[0] = 0

for i in range(1,n):
  dp[i] = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2,min(i+1,k+1)):
    dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))    
  #print(dp[i])
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
  w, v = map(int,input().split())
  for j in range(0,W+1):
    if (j-w) >=0:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
  #print(dp)
  
  
ans = dp[N][W]
print(ans)

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

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
  w, v = map(int,input().split())
  for j in range(0,W+1):
    if (j-w) >=0:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
  #print(dp)
  
  
ans = dp[N][W]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    x,y = map(int,input().split())
    edges[y-1].append(x-1)
    
used = [0 for _ in range(N)]
dp = [0 for _ in range(N)]

def dfs(pos):
    if not edges[pos]:
        dp[pos] = 0
        return
    for n_pos in edges[pos]:
        if not used[n_pos]:
            dfs(n_pos)
        used[n_pos] = 1
        dp[pos] = max(dp[pos],dp[n_pos]+1)
    print(dp)
    
for i in range(N):
    if used[i]:
        continue
    used[i] = True
    dfs(i)

print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

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

edges = [[] for _ in range(N)]
for _ in range(M):
    x,y = map(int,input().split())
    edges[y-1].append(x-1)
    
used = [0 for _ in range(N)]
dp = [0 for _ in range(N)]

def dfs(pos):
    if not edges[pos]:
        dp[pos] = 0
        return
    for n_pos in edges[pos]:
        if not used[n_pos]:
            dfs(n_pos)
        used[n_pos] = 1
        dp[pos] = max(dp[pos],dp[n_pos]+1)

    
for i in range(N):
    if used[i]:
        continue
    used[i] = True
    dfs(i)

print(max(dp))