Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
facts = [1]
mod =  10**9 + 7
for i in range(1, 2010):
	facts.append((i*facts[-1])%mod)
modinv = []
for i in facts:
	modinv.append(pow(i, mod - 2, mod))

def choose(p, r):
	return (((facts[p]*modinv[r])%mod)*modinv[p-r])%mod

n, k = map(int, raw_input().split())
blue = k
red = n - k
for i in range(1, k+1):
	if i <= n - k + 1:
		print (choose(red + 1, i)*choose(k - 1, i - 1))%mod
	else:
		print 0

Fixed submission:
s = list(raw_input())
s.sort()
if s[0] == s[1] and s[2] == s[3] and s[1] != s[2]:
	print "Yes"
else:
	print "No"
Buggy python submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6 + 100:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
if p > 1:
    fac[p] = 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

Fixed submission:
print raw_input().count('2')

Buggy python submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6 + 100:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

Fixed submission:
print raw_input().count('2')

Buggy python submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

Fixed submission:
print raw_input().count('2')
Buggy python submission (verdict: Runtime Error):
n = input()
node = 0
tmp = n
while tmp:
	node += 1
	tmp >>= 1
edges = []
for i in range(node - 1):
	edges.append([i+1, i+2, 0])
	edges.append([i+1, i+2, 1<<i])
for i in range(node-2, -1, -1):
	if (1<<i)&n:
		edges.append([i+1, node, (n>>(i+1))<<(i+1)])
print node, len(edges)
for i in edges:
	print i[0], i[1], i[2]	

Fixed submission:
n, k = map(int, raw_input().split())
if k%2:
	print (n/k)**3
else:
	cnt1, cnt2 = 0, 0
	for i in range(1, n + 1):
		if i%k == 0:
			cnt1 += 1
		if i%k == k/2:
			cnt2 += 1
	print cnt1**3 + cnt2**3
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())
totallen = sum(l)
h = []
i = 0
j = n - 2
ans = []
while i <= j:
	if totallen < k:
		break
	else:
		if l[i] < l[j]:
			ans.append(i + 1)
			totallen -= l[i]
			i += 1
		else:
			ans.append(j + 1)
			totallen -= l[j+1]
			j -= 1
if len(ans) == n - 1:
	print "Possible"
	for i in ans:
		print i 
else:
	print "Impossible"

Fixed submission:
l, r = map(int, raw_input().split())
if l <= 0 <= r:
	print "Zero"
elif l > 0:
	print "Positive"
else:
	if (r - l)%2 == 0:
		print "Negative"
	else:
		print "Positive"
Buggy python submission (verdict: Time Limit Exceeded):
str = input()
while True:
       pos = str.find('ST')
       if pos != -1:
              str = str[0:pos]+str[pos+2:]
       else:
              break
print(len(str))


Fixed submission:

str = input()
res=0
s=0
for e in str:
       if e == 'S':
              s=s+1
       elif s>0:
              res=res+1
              s=s-1
print(len(str)-res*2)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
flag = True
went = {1}
go = [1]
i = 0
while flag:
  if a[i] not in went:
    go.append(a[i])
    went.add(a[i])
    i = a[i]-1
  else:
    flag = False
loop = go[go.index(a[i]):]
if len(go) >= k:
  print(go[k])
else:
  k -= len(go)-len(loop)
  ans = k % len(loop)
  print(loop[ans])

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
flag = True
went = {1}
go = [1]
i = 0
while flag:
  if a[i] not in went:
    go.append(a[i])
    went.add(a[i])
    i = a[i]-1
  else:
    flag = False
loop = go[go.index(a[i]):]
if len(go) > k:
  print(go[k])
else:
  k -= len(go)-len(loop)
  ans = k % len(loop)
  print(loop[ans])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
ans = []
abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(n):
  ans.append(abc[(abc.index(s[i])+n) % 26])
  print(s[i])
print("".join(ans))

Fixed submission:
n = int(input())
s = list(input())
x = len(s)
ans = []
abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(x):
  ans.append(abc[(abc.index(s[i])+n) % 26])
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
a.b = map(int,input().split())
if a<10 and b<10:
  print(a*b)
else:
  print(-1)

Fixed submission:
a,b = map(int,input().split())
if a<10 and b<10:
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(1,n+1):
  ans.append(str(a.index(i)+1))
print(" ".join(ans))

Fixed submission:
from operator import itemgetter
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(0,n):
  ans.append([a[i],i+1])
ans= sorted(ans,key = itemgetter(0))
for j in range(n):
  print(ans[j][1],end = " ")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(1,n+1):
  ans.append(str(a.index(i)+1))
print(" ".join(ans))

Fixed submission:
from operator import itemgetter
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(0,n):
  ans.append([a[i],i+1])
ans= sorted(ans,key = itemgetter(0))
for j in range(n):
  print(ans[j][1],end = " ")
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
m = [k]*n 
for i in range(q):
  m = list(map(lambda x: x-1,m))
  m[a[i]-1] += 1
for j in range(n):
  if m[j] > 0:
    print("Yes")
  else:
    print("No")

Fixed submission:
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
m = [k-q]*n 
for i in range(q):
  m[a[i]-1] += 1
for j in range(n):
  if m[j] > 0:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  a_min = heapq.heappop(a)
  heap.heappush(a,(-1)*(-a_min // 2))
print(-sum(a))

Fixed submission:
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  a_min = heapq.heappop(a)
  heapq.heappush(a,(-1)*(-a_min // 2))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(m):
  a.sort()
  a[-1] //= 2
print(sum(a))

Fixed submission:
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  a_min = heapq.heappop(a)
  heapq.heappush(a,(-1)*(-a_min // 2))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
n_list = [i for i in range(1,n)]
print(sum(n_list))

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
n_list = [i for i in range(1,n)]
print(sum(n))

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
  s_val = list(input())
  s_val.sort()
  s.append(s_val)
ans = 0
while s != []:
  for k in range(1,len(s)):
    if s[0] == s[k]:
      ans += 1
  s.remove(s[0])
print(ans)

Fixed submission:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  s = "".join(sorted(input()))
  a = dic.get(s)
  if a is None:
    dic[s] = 1
  else:
    ans += a
    dic[s] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for i in range(n):
  s[i] = list(s[i])
  s[i].sort()
for j in range(n):
  for k in range(n):
    if j<k and s[j] == s[k]:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  s = "".join(sorted(input()))
  a = dic.get(s)
  if a is None:
    dic[s] = 1
  else:
    ans += a
    dic[s] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = [0]*m
flag = 0
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] > i:
      flag = j
      break
    queue.append(ab[j][1])
  k = heapq.nlargest(1,queue)
  ans += k[0]
  queue.remove(k[0])
print(ans)

Fixed submission:
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = []
flag = 0
heapq.heapify(queue)
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] <= i:
      heapq.heappush(queue,-ab[j][1])
      flag += 1
    else:
      break
  if queue != []:
    k = heapq.heappop(queue)
    ans += k
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
a = []
heapq.heapify(a)
for i in range(1,m+1):
  for j in range(len(ab)):
    if ab[j][0] == i:
      heapq.heappush(a,(-1)*ab[j][1])
  if a == []:
    continue
  else:
    x = heapq.heappop(a)
  ans += x
print(-ans)

Fixed submission:
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = []
flag = 0
heapq.heapify(queue)
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] <= i:
      heapq.heappush(queue,-ab[j][1])
      flag += 1
    else:
      break
  if queue != []:
    k = heapq.heappop(queue)
    ans += k
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
a = []
for i in range(1,m+1):
  for j in range(len(ab)):
    if ab[j][0] <= i:
      a.append(ab[j])
  a.sort(key=lambda x:x[1])
  if a == []:
    continue
  else:
    x = a.pop()
  ab.remove(x)
  ans += x[1]
  a = []
print(ans)

Fixed submission:
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = []
flag = 0
heapq.heapify(queue)
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] <= i:
      heapq.heappush(queue,-ab[j][1])
      flag += 1
    else:
      break
  if queue != []:
    k = heapq.heappop(queue)
    ans += k
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
a = []
for i in range(1,m+1):
  for j in range(len(ab)):
    if ab[j][0] <= i:
      a.append(ab[j])
  a.sort(key=lambda x:x[1])
  if a == []:
    continue
  else:
    x = a.pop()
  ab.remove(x)
  ans += x[1]
  a = []
print(ans)

Fixed submission:
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = []
flag = 0
heapq.heapify(queue)
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] <= i:
      heapq.heappush(queue,-ab[j][1])
      flag += 1
    else:
      break
  if queue != []:
    k = heapq.heappop(queue)
    ans += k
print(-ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
flag = 0
for i in range(n-2):
  if h[i] - h[i+2] >= 2:
    flag += 1
if h[-2]-h[-1] >= 2:
  flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
flag = 0
for i in range(n-1,1,-1):
  if h[i] - h[i-1] == -1:
    h[i-1] -= 1
  elif h[i] - h[i-1] >= 0:
    continue
  else:
    flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(1,n):
  ans += p[i]-int_queue[i]
if ans == 0:
  print("YES")
else:
  print("NO")

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(0,n):
  if p[j]-int_queue[j] == 0:
    continue
  else:
    ans += 1
if ans == 2 or ans == 0:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b = a
b.remove(max(b))
b_max = max(b)
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
a_copy = a
for j in range(0,n):
  if max(a) = a[j]:
    a_copy.remove(a_copy[j])
    print(max(a_copy))
  else:
    print(max(a))

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)
Buggy python submission (verdict: Runtime Error):
n = int(input().split())
a = list(map(int,input().split()))
ans = []
for i in range(n,0,-1):
  if sum(a[::i]) % 2 == 1:
    ans.append(i)
ans.reverse()
print(len(ans))
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
key = [0]*n
ans = []
for i in range(n-1,-1,-1):
  if sum(key[i::i+1]) % 2 != a[i]:
    ans.append(i+1)
    key[i] = 1
ans.reverse()
print(len(ans))
print(" ".join(list(map(str,ans))))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = []
R = []
for i in range(1,M+1):
  x,y = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
for i in range(1,M+1):
  L_val,R_val = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = []
R = []
for i in range(M+1):
  L_val,R_val = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
for i in range(1,M+1):
  L_val,R_val = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
B = []
C = []
A = list(map(int,input().split()))
for j in range(1,M+1):
  B_val,C_val = map(int,input().split())
  B.append(B_val)
  C.append(C_val)
A.sort()
for k in range(0,M):
  for l in range(0,B[k]):
    if A[0] <= C[k]:
      A[0] = C[k]
      A.sort()
    else:
      continue
print(sum(A))

Fixed submission:
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())))
bc = sorted([list(map(int,input().split())) for _ in range(m)],key = lambda x:-x[1])
flag = 0
flag_2 = 0
#print(a,bc)
for i in range(n):
  if a[i] < bc[flag_2][1]:
    a[i] = bc[flag_2][1]
  else:
    break
  flag += 1
  if flag == bc[flag_2][0]:
    flag_2 += 1
    flag = 0
  if flag_2 == m:
    break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if int(Y) * 10 % 10 !== 0:
        Y_int = int(Y) + 1
      else:
        Y_int = int(Y)
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)


Fixed submission:
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if Y * 10 % 10 == 0.0:
        Y_int = int(Y)
      else:
        Y_int = int(Y) + 1
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans + = (v[i]-c[i])
  else:
    continue
print(ans)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans += (v[i]-c[i])
  else:
    continue
print(ans)

Buggy python submission (verdict: Runtime Error):
N = input()
V = list(map(int,input(),split()))
C = list(map(int,input(),split()))
for i in range(N+1):
  val= []
  a = V[i] - C[i]
  val.append(a)
val_int = [b for b in val if b > 0]
print(sum(val_int))

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans += (v[i]-c[i])
  else:
    continue
print(ans)

Buggy python submission (verdict: Runtime Error):
N = input()
V = list(map(int,input(),split()))
C = list(map(int,input(),split()))
for i in range(N+1):
  val= []
  a = V[i] - C[i]
  val.append(a)
val_int = [b for b in val if b > 0]
print(sum(val_int))

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans += (v[i]-c[i])
  else:
    continue
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd_list = []
ans = 0
for i in range(1,n):
  gcd_list.append(fractions.gcd(a[0],a[i]))
gcd_list.sort()
gcd_list.remove(gcd_list[0])
for j in range(1,n-2):
  ans = max(ans,fractions.gcd(gcd_list[0],gcd_list[i]))
print(ans)

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
m = []
l = [0]
r = [0]
for i in range(n):
  l.append(fractions.gcd(l[i],a[i]))
  r.append(fractions.gcd(r[i],a[-i-1]))
r.reverse()
for i in range(n):
  m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print(max(a*2-1,b*2-1,a+b))

Fixed submission:
a,b=map(int,input().split())
print(max(a*2-1,b*2-1,a+b))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for _ in range(q)]
for i in range(q):
  x = [s[j] for j in range(n) if (lr[i][0]-1) <= j <= (lr[i][1]-1)]
  print("".join(x).count("AC"))

Fixed submission:
import sys
import bisect
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for _ in range(q)]
ac = []
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    ac.append(i)
for i in range(q):
  print(bisect.bisect_left(ac,lr[i][1]-1)-bisect.bisect_left(ac,lr[i][0]-1))
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Fixed submission:
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    key = 0
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
if b[0] != 1:
  flag = 1
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int,input().split()))
gcd_a = fractions.gcd(a[0],[1])
for i in range(2,n):
  gcd_a = fractions.gcd(gcd_a,gcd[i])
  if gcd_a == 1:
    break
print(gcd_a)

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
gcd_a = fractions.gcd(a[0],a[1])
for i in range(2,n):
  gcd_a = fractions.gcd(gcd_a,a[i])
  if gcd_a == 1:
    break
print(gcd_a)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_diff = [x[i]-x[i-1] for i in range(1,m)]
x_diff.sort(reverse == True)
if n >= m:
  print(0)
else:
  del x_diff[:n-1]
  print(sum(x_diff))

Fixed submission:
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_diff = [x[i]-x[i-1] for i in range(1,m)]
x_diff.sort(reverse = True)
if n >= m:
  print(0)
else:
  del x_diff[:n-1]
  print(sum(x_diff))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_diff = []
for i in range(1,m):
  x_diff.append(x[i]-x[i-1])
x_diff.sort()
if n >= m:
  print(0)
else:
  for j in range(1,n):
    x_diff.remove(x_diff[-1])
  print(sum(x_diff))

Fixed submission:
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_diff = [x[i]-x[i-1] for i in range(1,m)]
x_diff.sort(reverse = True)
if n >= m:
  print(0)
else:
  del x_diff[:n-1]
  print(sum(x_diff))
Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
#dp[i][j]はi番目まででj(j<=w)になるもの
dp = [[0]*(w+1) for i in range(n)]
for k in range(w+1):
  if k >= wv[0][0]:
    dp[0][k] = wv[0][1]
  else:
    continue
for i in range(n-1):
  for j in range(w+1):
    if j >= wv[i+1][0]:
      dp[i+1][j] = max(dp[i][j-wv[i+1][0]]+wv[i+1][1],dp[i][j])
    else:
      dp[i+1][j] = dp[i][j]
print(dp[n-1][w])


Fixed submission:
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
#dp[i][j]はi番目まででj(価値の合計)になる重さの最小値
sum_value = 0
for i in range(n):
  sum_value += wv[i][1]
dp = [[float("inf")]*(sum_value+1) for j in range(n)]
for k in range(sum_value+1):
  if k == wv[0][1]:
    dp[0][k] = wv[0][0]
for a in range(n-1):
  for b in range(sum_value+1):
    if dp[a][b-wv[a+1][1]] != float("inf"):
      dp[a+1][b] = min(dp[a][b-wv[a+1][1]]+wv[a+1][0],dp[a][b])
    elif b == wv[a+1][1]:
      dp[a+1][b] = min(wv[a+1][0],dp[a][b])
    else:
      dp[a+1][b] = dp[a][b]
ans = 0
for c in range(sum_value+1):
  if dp[-1][c] != float("inf") and w >= dp[-1][c]:
    ans = c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())
a = len(s)
b = len(t)
dp = [[""]*(b+1) for _ in range(a+1)]
#dp[i][j]はi文字目までのsとtのj文字目までの共通部分
for i in range(a):
  for j in range(b):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j]+s[i]
    else:
      dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],key = len)
print(dp[-1][-1])

Fixed submission:
s = list(input())
t = list(input())
a = len(s)
b = len(t)
dp = [[0]*(b+1) for _ in range(a+1)]
ans = ""
#dp[i][j]はi文字目までのsとtのj文字目までの共通部分
for i in range(a):
  for j in range(b):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j]+1
    else:
      dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
i = a
j = b
while(i>=0 and j>=0):
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    ans = t[j-1]+ans
    i -= 1
    j -= 1
print(ans)