Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = []
for i in range(n):
    S.append(input())
color = [-1]*n #0:黒, 1:白
color[0] = 0
stack = [0]
colored = [0]*n
colored[0] = 1
while len(stack) != 0:
    temp = stack.pop()
    col = color[temp]
    cur = S[temp]
    for j in range(n):
        if cur[j] == '1':
            if colored[j] != 0:
                if color[j] == col:
                    print(-1)
                    exit()
            else:
                if col == 1:
                    color[j] = 0
                else:
                    color[j] = 1
                colored[j] = 1
                stack.append(j)
maxdist = 0
dist = []
for i in range(n):
    d = [float('inf')]*n
    d[i] = 0
    dist.append(d)
for i in range(n):
    for j in range(n):
        if S[i][j] == '1':
            dist[i][j] = 1
for i in range(n):
    for k in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
for i in range(n):
    for j in range(n):
        if dist[i][j] != float('inf'):
            maxdist = max(maxdist, dist[i][j])
print(maxdist+1)


Fixed submission:
n = int(input())
S = []
for i in range(n):
    S.append(input())
color = [-1]*n #0:黒, 1:白
color[0] = 0
stack = [0]
colored = [0]*n
colored[0] = 1
while len(stack) != 0:
    temp = stack.pop()
    col = color[temp]
    cur = S[temp]
    for j in range(n):
        if cur[j] == '1':
            if colored[j] != 0:
                if color[j] == col:
                    print(-1)
                    exit()
            else:
                if col == 1:
                    color[j] = 0
                else:
                    color[j] = 1
                colored[j] = 1
                stack.append(j)
maxdist = 0
dist = []
for i in range(n):
    d = [10**10]*n
    d[i] = 0
    dist.append(d)
for i in range(n):
    for j in range(n):
        if S[i][j] == '1':
            dist[i][j] = 1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
for i in range(n):
    for j in range(n):
        maxdist = max(maxdist, dist[i][j])
print(maxdist+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int,input().split()))
S = []
for i in range(n):
  S.append([L[i],i+1])
S.sort()
for i in range(n):
  print(' '.join(S[i][1]))

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
S = []
K = []
for i in range(n):
  S.append([L[i],i+1])
S.sort()
for i in range(n):
  K.append(S[i][1])
print(' '.join(map(str,K)))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
dp = []
key = []
for i in range(m):
    d = [float('inf')]*(2**n)
    d[0] = 0
    dp.append(d)
for i in range(m):
    cost,num = map(int,input().split())
    if num == 1:
        t = int(input())
        key.append([cost,2**(t-1)])
    else:
        p = list(map(int,input().split()))
        cur = 0
        for i in range(len(p)):
            cur += 2**(p[i]-1)
        key.append([cost,cur])
for i in range(m):
    for j in range(2**n):
        if i != 0:
            dp[i][j] = min(dp[i][j],dp[i-1][j])
        dp[i][j|key[i][1]] = min(dp[i][j|key[i][1]],dp[i][j]+key[i][0])
if dp[m-1][2**n-1] != float('inf'):
    print(dp[m-1][2**n-1])
else:
    print(-1)


Fixed submission:
n,m = map(int,input().split())
dp = []
key = []
for i in range(m):
    d = [10**15]*(2**n)
    d[0] = 0
    dp.append(d)
for i in range(m):
    cost,num = map(int,input().split())
    if num == 1:
        t = int(input())
        key.append([cost,2**(t-1)])
    else:
        p = list(map(int,input().split()))
        cur = 0
        for i in range(len(p)):
            cur += 2**(p[i]-1)
        key.append([cost,cur])
for i in range(m):
    for j in range(2**n):
        if i != 0:
            dp[i][j] = min(dp[i][j],dp[i-1][j])
        dp[i][j|key[i][1]] = min(dp[i][j|key[i][1]],dp[i][j]+key[i][0])
if dp[m-1][2**n-1] != 10**15:
    print(dp[m-1][2**n-1])
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
dp = [0]*n
cnt = 0
L = []
flag = True
for i in range(n):
  T = []
  N = list(map(int,input().split()))
  for j in range(n-1):
    T.append((i+1,N[j]))
  L.append(T)
while dp != [n-1]*n:
  B = [0]*n
  act = 0
  for i in range(n):
    if B[i] == 0:
      B[i] = 1
      if dp[i] != n-1:
        miru = L[i][dp[i]][1]
        if dp[miru-1] == n-1:
          flag = False
          break
        else:
          if B[miru-1] != 1:
            if L[miru-1][dp[miru-1]][1] == i+1:
              dp[i] += 1
              dp[miru-1] += 1
              B[miru-1] = 1
              act += 1
  if act == 0:
    dp = [n-1]*n
    flag = False
  if cnt >= 100000:
      dp = [n-1]*n
  cnt += 1
if flag == False:
  print(-1)
else:
  print(cnt)

Fixed submission:
S = input()
T = input()
ans = 0
for i in range(3):
  if S[i] == T[i]:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
L = [0]*n
ans = [0]*n
par = [i for i in range(n)]
for i in range(n-1):
    s,t = map(int,input().split())
    par[t-1] = s-1
for i in range(q):
    s,t = map(int,input().split())
    L[s-1] += t
for i in range(n):
    x = n-i-1
    px = x
    while px != 0:
        ans[x] += L[px]
        px = par[px]
for i in range(n):
    ans[i] += L[0]
print(' '.join(map(str,ans)))

Fixed submission:
n,q = map(int,input().split())
L = [0]*(n+1)
graph = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
for i in range(q):
    a,b = map(int,input().split())
    L[a] += b
q = [(1,0)]
while len(q) > 0:
    c = q.pop()
    x, par = c[0], c[1]
    L[x] += L[par]
    for child in graph[x]:
        if par == child:
            continue
        q.append((child,x))
print(' '.join(map(str,L[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
L = [0]*n
ans = [0]*n
par = [i for i in range(n)]
for i in range(n-1):
    s,t = map(int,input().split())
    par[t-1] = s-1
for i in range(q):
    s,t = map(int,input().split())
    L[s-1] += t
for i in range(n):
    x = n-i-1
    px = x
    while px != 0:
        ans[x] += L[px]
        px = par[px]
for i in range(n):
    ans[i] += L[0]
print(' '.join(map(str,ans)))

Fixed submission:
n,q = map(int,input().split())
L = [0]*(n+1)
graph = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
for i in range(q):
    a,b = map(int,input().split())
    L[a] += b
q = [(1,0)]
while len(q) > 0:
    c = q.pop()
    x, par = c[0], c[1]
    L[x] += L[par]
    for child in graph[x]:
        if par == child:
            continue
        q.append((child,x))
print(' '.join(map(str,L[1:])))
Buggy python submission (verdict: Runtime Error):
import bisect
s = input()
t = input()
sub = s+s
dp = []
for i in range(len(s)):
    d = [10**15]*26
    dp.append(d)
index = [[] for i in range(26)]
for i in range(len(sub)):
    index[ord(sub[i])-97].append(i)
for i in range(len(s)):
    cur = s[i]
    for j in range(26):
        if len(index[j]) != 0:
            k = bisect.bisect_left(index[j], i)
            dp[i][j] = index[j][k]-i
ans = dp[0][ord(t[0])-97]+1
next = dp[0][ord(t[0])-97]
flag = True
for i in range(1,len(t)):
    cur = next
    if dp[cur][ord(t[i])-97] == 10**15:
        flag = False
        break
    else:
        ans += dp[cur][ord(t[i])-97]
        if cur + dp[cur][ord(t[i])-97] >= len(s):
            next = cur + dp[cur][ord(t[i])-97] - len(s)
        else:
            next = cur + dp[cur][ord(t[i])-97]
if flag:
    print(ans)
else:
    print(-1)


Fixed submission:
import bisect
s = input()
t = input()
sub = s+s
dp = []
for i in range(len(s)):
    d = [10**15]*26
    dp.append(d)
index = [[] for i in range(26)]
for i in range(len(sub)):
    index[ord(sub[i])-97].append(i)
for i in range(len(s)):
    cur = s[i]
    for j in range(26):
        if len(index[j]) != 0:
            k = bisect.bisect_right(index[j], i)
            dp[i][j] = index[j][k]-i
if s[0] == t[0]:
    ans = 1
else:
    ans = dp[0][ord(t[0])-97]+1
if dp[0][ord(t[0])-97] != 10**15 and dp[0][ord(t[0])-97] >= len(s):
    next = dp[0][ord(t[0])-97]-len(s)
else:
    next = dp[0][ord(t[0])-97]
if next == 10**15:
    print(-1)
    exit()
else:
    flag = True
for i in range(1,len(t)):
    cur = next
    if dp[cur][ord(t[i])-97] == 10**15:
        flag = False
        break
    else:
        ans += dp[cur][ord(t[i])-97]
        if cur + dp[cur][ord(t[i])-97] >= len(s):
            next = cur + dp[cur][ord(t[i])-97] - len(s)
        else:
            next = cur + dp[cur][ord(t[i])-97]
if flag:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
mod = 10**9+7
dp = [[0]*13 for i in range(len(s))]
if s[0] != '?':
  dp[0][int(s[0])] = 1
else:
  for i in range(10):
    dp[0][i] = 1
for i in range(1,len(s)):
  if s[i] != '?':
    for j in range(13):
      t = (j*10+int(s[i]))%13
      dp[i][t] += dp[i-1][j]
      dp[i][t] = dp[i][t]%mod
  else:
    for k in range(10):
      for j in range(13):
        t = (j*10+k)%13
        dp[i][t] += dp[i-1][j]
        dp[i][t] = dp[i][t]%mod
print(dp[len(s)-1][5]%mod)

Fixed submission:
s = input()
mod = 10**9+7
dp = [[0]*13 for i in range(len(s))]
if s[0] != '?':
  dp[0][int(s[0])] = 1
else:
  for i in range(10):
    dp[0][i] = 1
for i in range(1,len(s)):
  if s[i] != '?':
    for j in range(13):
      t = (j*10+int(s[i]))%13
      dp[i][t] += dp[i-1][j]
      dp[i][t] = dp[i][t]%mod
  else:
    for k in range(10):
      for j in range(13):
        t = (j*10+k)%13
        dp[i][t] += dp[i-1][j]
        dp[i][t] = dp[i][t]%mod
print(dp[len(s)-1][5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
L = [int(input())]
ans = 0
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.append(t)
        L.sort()
    else:
        L[k-1] = t
print(len(L))


Fixed submission:
from collections import deque
import bisect
n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.appendleft(t)
    else:
        L[k-1] = t
print(len(L))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
L = [int(input())]
ans = 0
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.append(t)
    else:
        L[k-1] = t
    L.sort()
print(len(L))


Fixed submission:
from collections import deque
import bisect
n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.appendleft(t)
    else:
        L[k-1] = t
print(len(L))
Buggy python submission (verdict: Runtime Error):
import collections
n,k = map(int,input().split())
if k > n+1 and k != (n-1)*(n-2)//2:
    print(-1)
elif k == 0:
    if n == 2:
        print(1,2)
    else:
        print(-1)  
else:
    if k == (n-1)*(n-2)//2:
        print(n-1)
        for i in range(2,n+1):
            print(1,i)
    else:
        L = collections.deque()
        for i in range(3,n):
            L.append([1,i])
        for i in range(2,n-1):
            for j in range(i+2,n+1):
                L.append([i,j])
        for i in range(k):
            L.popleft()
        if k != n+1:
            print(len(L)+n)
            for i in range(len(L)):
                print(L[i][0],L[i][1])
            for i in range(n-1):
                print(i+1,i+2)
            for i in range(1):
                print(n,1)

Fixed submission:
n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
    print(-1)
else:
    ans = []
    for i in range(1,n):
        ans.append([1,i+1])
    L = []
    for i in range(2,n+1):
        for j in range(i+1, n+1):
            L.append([i,j])
    for i in range((n-1)*(n-2)//2-k):
        ans.append(L[i])
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i][0], ans[i][1])
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w-1,-1,-1):
        if M[i][j] == '#':
            None
        else:
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
for i in range(h):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
for i in range(h-1,-1,-1):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
for i in range(h):
    for j in range(w):
        Total[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        if Total[i][j] > ans:
            ans = Total[i][j]
print(ans)

Fixed submission:
h,w = map(int,input().split())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w-1,-1,-1):
        if M[i][j] == '#':
            None
        else:
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
for i in range(h):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
for i in range(h-1,-1,-1):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
for i in range(h):
    for j in range(w):
        Total[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        if Total[i][j] > ans:
            ans = Total[i][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
T = []
for i in range(k+1):
    if i <= n:
        for a in range(i+1):
            L = V[0:a]+V[n-i+a:n]
            L.sort()
            cur = sum(L)
            for b in range(k-i):
                if b < len(L):
                    if L[b] < 0:
                        cur -= L[b]
            if cur > ans:
                ans = cur
    else:
        L = V
        L.sort()
        cur = sum(L)
        for b in range(k-n):
            if L[b] < 0:
                cur -= L[b]
        if cur > ans:
            ans = cur
print(ans)

Fixed submission:
n,k = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
T = []
for i in range(k+1):
    if i <= n:
        for a in range(i+1):
            L = V[0:a]+V[n-i+a:n]
            L.sort()
            cur = sum(L)
            for b in range(k-i):
                if b < len(L):
                    if L[b] < 0:
                        cur -= L[b]
            if cur > ans:
                ans = cur
    else:
        L = V
        L.sort()
        cur = sum(L)
        for b in range(k-i):
            if b < len(L):
                if L[b] < 0:
                    cur -= L[b]
        if cur > ans:
            ans = cur
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
L = []
for i in range(m):
    L.append(list(map(int,input().split())))
for i in range(m):
    b = L[i][0]
    c = L[i][1]
    for j in range(b):
        heapq.heappush(A,c)
    for j in range(b):
        heapq.heappop(A)
print(sum(A))

Fixed submission:
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(n):
  L.append([A[i],1])
for i in range(m):
  a,b = map(int,input().split())
  L.append([b,a])
L.sort()
L.reverse()
s = 0
t = 0
ans = 0
while s < n:
  if L[t][1]+s <= n:
    ans += L[t][1]*L[t][0]
    s += L[t][1]
    t += 1
  else:
    ans += L[t][0]*(n-s)
    s = n
    t += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
A.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
ans = 1
for i in range(N):
  flag = True
  if i == 0:
    p = A[1]
    for j in range(2,N):
      p = gcd(A[j],p)
      if ans >= p:
        flag = False
        break
    if flag:
      ans = p
  else:
    p = A[0]
    if p != 1:
      for j in range(1,N):
        if j != i:
          p = gcd(A[j],p)
        if ans >= p:
          flag = False
          break
      if flag:
        ans = p
    else:
      p = A[1]
      for j in range(2,N):
        if j != i:
          p = gcd(A[i],p)
        if ans >= p:
          flag = False
          break
      if flag:
        ans = p
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
L = [0]*(N+2)
R = [0]*(N+2)
for i in range(N):
  if L[i] == 0:
    L[i+1] = A[i]
  else:
    L[i+1] = gcd(max(L[i],A[i]),min(L[i],A[i]))
for i in range(N,-1,-1):
  if i == N:
    R[i+1] = 0
  elif i == N-1:
    R[i+1] = A[N-1] 
  else:
    R[i+1] = gcd(max(R[i+2],A[i]),min(R[i+2],A[i]))
ans = 1
for i in range(N):
  if L[i] == 0 or R[i+2] == 0:
    k = max(L[i],R[i+2])
    ans = max(ans,k)
  else:
    ans = max(ans,gcd(max(L[i],R[i+2]),min(L[i],R[i+2])))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
L = [A,B,C]
M = list(itertools.product(*L))
T = []
for i in range(len(M)):
  T.append(sum(M[i]))
T.sort()
for i in range(len(T)-1,len(T)-K-1,-1):
  print(T[i])

Fixed submission:
import itertools
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
L = [A,B,C]
if X*Y*Z <= 3000:
  M = list(itertools.product(*L))
  T = []
  for i in range(len(M)):
    T.append(sum(M[i]))
  T.sort()
  for i in range(len(T)-1,len(T)-K-1,-1):
    print(T[i])
else:
  T = []
  for i in range(X):
    for j in range(Y):
      T.append(A[i]+B[j])
  T.sort()
  T.reverse()
  U = []
  for i in range(K):
    U.append(T[i])
  V = []
  for i in range(K):
    for j in range(Z):
      V.append(U[i]+C[j])
  V.sort()
  V.reverse()
  for i in range(K):
    print(V[i])
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
s = input()
L = []
for i in range(Q):
  L.append(list(input().split()))
def judge_left(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return True
    if x == N:
      return False
  return False
def judge_right(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return False
    if x == N:
      return True
  return False
ok = -1
ng = N
while ng-ok > 1:
  mid = (ng+ok)//2
  if judge_left(mid):
    ok = mid
  else:
    ng = mid
left = ok+1

ok = N
ng = -1
while ok-ng > 1:
  mid = (ng+ok)//2
  if judge_right(mid):
    ok = mid
  else:
    ng = mid
right = N-ok
print(max(N-left-right,0))

Fixed submission:
N,Q = map(int,input().split())
s = input()
L = []
for i in range(Q):
  L.append(list(input().split()))
def judge_left(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return True
    if x == N:
      return False
  return False
def judge_right(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return False
    if x == N:
      return True
  return False
ok = -1
ng = N
while ng-ok > 1:
  mid = (ng+ok)//2
  if judge_left(mid):
    ok = mid
  else:
    ng = mid
left = ok+1

ok = N
ng = -1
while ok-ng > 1:
  mid = (ng+ok)//2
  if judge_right(mid):
    ok = mid
  else:
    ng = mid
right = N-ok
print(max(N-left-right,0))
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split()))
TF = [False]*N
L = []
s = 0
lenstr = N-1
for i in range(N):
  cnt = 0
  tr = 0
  for j in range(N-1,-1,-1):
    if TF[j] == False:
      if B[lenstr-cnt-tr+i] == lenstr-cnt+1:
        TF[lenstr-cnt-tr+i] = True
        L.append(lenstr-cnt+1)
        lenstr -= 1
        break
      else:
        cnt += 1
    else:
      tr += 1
if len(L) == N:
  for i in range(N):
    print(L[N-i-1])
else:
  print(-1)

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
TF = [False]*N
L = []
s = 0
lenstr = N-1
for i in range(N):
  cnt = 0
  tr = 0
  for j in range(N-1,-1,-1):
    if TF[j] == False:
      if lenstr-cnt-tr+i <= N-1:
        if B[lenstr-cnt-tr+i] == lenstr-cnt+1:
          TF[lenstr-cnt-tr+i] = True
          L.append(lenstr-cnt+1)
          lenstr -= 1
          break
        else:
          cnt += 1
      else:
          print(-1)
          exit()
    else:
      tr += 1
if len(L) == N:
  for i in range(N):
    print(L[N-i-1])
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
import bisect
import math
A,B,Q = map(int,input().split())
a = []
b = []
x = []
for i in range(A):
  a.append(int(input()))
for j in range(B):
  b.append(int(input()))
for k in range(Q):
  x.append(int(input()))
a.insert(0,-(10**15))
a.append(10**15)
b.insert(0,-(10**15))
b.append(10**15)
for k in range(Q):  
  terafirst = 0
  jinjyafirst = 0
  p = bisect.bisect_left(a,x[k])
  q = bisect.bisect_left(b,x[k])
  terafirst = min(abs(x[k]-a[p-1]),abs(x[k]-a[p]))
  if abs(x[k]-a[p-1])<abs(x[k]-a[p]):
    r = bisect.bisect_left(b,a[p-1])
    terafirst += min(abs(b[r-1]-a[p-1]),abs(b[r]-a[p-1]))
  else:
    s = bisect.bisect_left(b,a[p])
    terafirst += min(abs(b[s-1]-a[p]),abs(b[s]-a[p]))
      
  jinjyafirst = min(abs(x[k]-b[q-1]),abs(x[k]-b[q]))
  if abs(x[k]-b[q-1])<abs(x[k]-b[q]):
    t = bisect.bisect_left(a,b[p-1])
    jinjyafirst += min(abs(a[t-1]-b[q-1]),abs(a[t]-b[q-1]))
  else:
    u = bisect.bisect_left(a,b[q])
    jinjyafirst += min(abs(a[u-1]-b[q]),abs(a[u]-b[q]))
  print(min(terafirst,jinjyafirst))

Fixed submission:
import bisect
A,B,Q = map(int,input().split())
a = []
b = []
x = []
for i in range(A):
  a.append(int(input()))
for j in range(B):
  b.append(int(input()))
for k in range(Q):
  x.append(int(input()))
a.insert(0,-(10**15))
a.append(10**15)
b.insert(0,-(10**15))
b.append(10**15)
for k in range(Q):  
  p = bisect.bisect_left(a,x[k])
  q = bisect.bisect_left(b,x[k])
  teraleft_right = [a[p-1],a[p]]
  jinjyaleft_right = [b[q-1],b[q]]
  minlist = []
  for i in range(2):
    for j in range(2):
      minlist.append(abs(x[k]-teraleft_right[i])+abs(teraleft_right[i]-jinjyaleft_right[j]))
      minlist.append(abs(x[k]-jinjyaleft_right[i])+abs(jinjyaleft_right[i]-teraleft_right[j]))
  minlist.sort() 
  print(minlist[0])