Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    P = []
    for i in range(25,-1,-1):
      if s[i] > s[i-1]:
        break
      else:
        P.append(s[i-1])
        P.append(s[i])
    P.sort()
    print(s[0:i-1]+P[0])

Fixed submission:
import sys
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  right = s[-1]
  for i in reversed(range(len(s))):
    k = s[i]
    if k < right:
      for j in range(ord(k),ord(k)+26):
        if chr(j) in s[i+1:]:
          print(s[:i]+chr(j))
          break
      sys.exit()
    else:
      right = max(k,right)
  print(-1)

Buggy python submission (verdict: Runtime Error):
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    for i in range(25):
      if ord(s[i+1])-ord(s[i]) != 1:
        break
    print(s[0:i]+alp[ord(s[i])-97+1])

Fixed submission:
import sys
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  right = s[-1]
  for i in reversed(range(len(s))):
    k = s[i]
    if k < right:
      for j in range(ord(k),ord(k)+26):
        if chr(j) in s[i+1:]:
          print(s[:i]+chr(j))
          break
      sys.exit()
    else:
      right = max(k,right)
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
L = []
A.insert(0,0)
A.insert(N+1,0)
for i in range(1,N+1):
  k = 0
  L.append(A[i])
  del (A[i])
  for j in range(N):
    k += abs(A[j]-A[j+1])
  A.insert(i,L[i-1])
  print(k)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.insert(N+1,0)
S = 0
for i in range(N+1):
  S += abs(A[i]-A[i+1])
for i in range(1,N+1):
  print(S-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
Buggy python submission (verdict: Runtime Error):
from collections import deque
R,C = map(int,input().split())
sy,sx = 1,1  #スタートの座標
gy,gx = R,C  #ゴールの座標
L = []
for i in range(R):
  L.append(list(input()))   #迷路の情報を受け取る
dy_dx = [[1,0],[-1,0],[0,1],[0,-1]]   #移動
que = deque([[sy-1,sx-1]])   #queには次に見るべき座標が入る。括弧が二重になっていることに留意
L[sy-1][sx-1] = 0  #スタートの座標（迷路上）の情報を0に
while len(que) > 0:  #queが空でないときは
  cur = que.popleft()   #queの一番左を見る
  for i in range(4):  #現在見ているマスの上下左右をチェック
    if 0 <= cur[0]+dy_dx[i][0] <= R-1 and 0 <= cur[1]+dy_dx[i][1] <= C-1:  #移動した後も迷路内にあるかの確認
      if L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]] == '.':  #まだ見ていない通路であれば
        L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]] = L[cur[0]][cur[1]]+1  #現在見ているマスの手数+1を入れる
        que.append([cur[0]+dy_dx[i][0],cur[1]+dy_dx[i][1]])   #queの末尾に今チェックした座標を入れる
black = 0
for i in range(R):
  for j in range(C):
    if L[i][j] == '#':
      black += 1
print(R*C-L[gy-1][gx-1]-1-black)

Fixed submission:
from collections import deque
R,C = map(int,input().split())
sy,sx = 1,1  #スタートの座標
gy,gx = R,C  #ゴールの座標
L = []
for i in range(R):
  L.append(list(input()))   #迷路の情報を受け取る
dy_dx = [[1,0],[-1,0],[0,1],[0,-1]]   #移動
black = 0
for i in range(R):
  for j in range(C):
    if L[i][j] == '#':
      black += 1
que = deque([[sy-1,sx-1]])   #queには次に見るべき座標が入る。括弧が二重になっていることに留意
L[sy-1][sx-1] = 0  #スタートの座標（迷路上）の情報を0に
while len(que) > 0:  #queが空でないときは
  cur = que.popleft()   #queの一番左を見る
  for i in range(4):  #現在見ているマスの上下左右をチェック
    if 0 <= cur[0]+dy_dx[i][0] <= R-1 and 0 <= cur[1]+dy_dx[i][1] <= C-1:  #移動した後も迷路内にあるかの確認
      if L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]] == '.':  #まだ見ていない通路であれば
        L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]] = L[cur[0]][cur[1]]+1  #現在見ているマスの手数+1を入れる
        que.append([cur[0]+dy_dx[i][0],cur[1]+dy_dx[i][1]])   #queの末尾に今チェックした座標を入れる
if L[gy-1][gx-1] == '#':
  print(-1)
elif L[gy-1][gx-1] == '.':
  print(-1)
else:
  print(R*C-L[gy-1][gx-1]-1-black)
Buggy python submission (verdict: Runtime Error):
M = int(input())
print(48-N)

Fixed submission:
M = int(input())
print(48-M)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
S = input()
L = [0,1,2,3,4,5,6,7,8,9]
for i in (range(A) and range(A+1,A+B+1)):
  if (S[i] in L):
    if (S[A] == '-'):
      print('Yes')
  else:
    print('No')

Fixed submission:
N,A,B = map(int,input().split())
L = []
for i in range(1,N+1):
  k = str(i)
  s = 0
  for j in range(len(k)):
    s += int(k[j])
  if (A <= s <= B):
    L.append(i)
print(sum(L))

Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
L = []
for i in range(1,N+1):
  k = str(i)
  for j in range(len(k)):
    S = sum(int(k[j]))
    if (A <= S <= B):
      L.append(i)
print(sum(S))

Fixed submission:
N,A,B = map(int,input().split())
L = []
for i in range(1,N+1):
  k = str(i)
  s = 0
  for j in range(len(k)):
    s += int(k[j])
  if (A <= s <= B):
    L.append(i)
print(sum(L))
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
 
p = s.sort()
q = t.sort()
r = q.reverse()
 
if (p < r):
  print('Yes')
else:
  print('No')

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

s.sort()
t.sort()
t.reverse()

if (s < t):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = []
M = []
for i in range(len(A)):
  if (A[i] not in L):
    L.append(A[i])
for j in range(len(L)):
  M.append(A.count(L[j]))
M.sort()
if (len(M) <= K):
  print(0)
else:
  print(sum(M[:len(M)-K]))

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A.insert(len(A),0)
L = []
k = 1
for i in range(len(A)-1):
  if (A[i] == A[i+1]):
    k += 1
    i += 1
  else:
    L.append(k)
    k = 1
    i += 1  
L.sort()
if (len(L) <= K):
  print(0)
else:
  print(sum(L[:len(L)-K]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
S = 0
k = 0
l = 0
for i in range(N):
  for p in range(N):
    if K[i] > J[p]:
      k += 1
  for q in range(N):
    if K[i] < L[q]:
      l += 1
  S += k*l
  k = 0
  l = 0
print(S)

Fixed submission:
import bisect
N = int(input())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
J.sort()
K.sort()
L.sort()
S = 0
for i in range(N):
  k = bisect.bisect_left(J,K[i])
  l = N - bisect.bisect_right(L,K[i])  
  S += k*l
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
J.sort()
K.sort()
L.sort()
S = 0
k = 0
l = 0
for i in range(N):
  for p in range(N):
    if K[i] > J[p]:
      k += 1
    else:
      break
  for q in range(N):
    if K[i] < L[N-q-1]:
      l += 1
    else:
      break
  S += k*l
  k = 0
  l = 0
print(S)

Fixed submission:
import bisect
N = int(input())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
J.sort()
K.sort()
L.sort()
S = 0
for i in range(N):
  k = bisect.bisect_left(J,K[i])
  l = N - bisect.bisect_right(L,K[i])  
  S += k*l
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N,K = map(int,input().split())
zahyou = []
for i in range(N):
  zahyou.append(list(map(int,input().split())))
ans = float('inf')
X = []
Y = []
for i in range(N):
  X.append(zahyou[i][0])
  Y.append(zahyou[i][1])
P = list(itertools.combinations(X,2))
Q = list(itertools.combinations(Y,2))
for i in range(len(P)):
  for j in range(len(Q)):
    x1 = min(P[i][0],P[i][1])
    x2 = max(P[i][0],P[i][1])
    y1 = min(Q[j][0],Q[j][1])
    y2 = max(Q[j][0],Q[j][1])
    cnt = 0
    for k in range(N):
      if x1 <= zahyou[k][0] <= x2 and y1 <= zahyou[k][1] <= y2:
        cnt += 1
    if cnt >= K:
      if ans >= (x2-x1)*(y2-y1):
        ans = (x2-x1)*(y2-y1)
print(ans)

Fixed submission:
import itertools
N,K = map(int,input().split())
zahyou = []
for i in range(N):
  zahyou.append(list(map(int,input().split())))
ans = float('inf')
X = []
Y = []
for i in range(N):
  X.append(zahyou[i][0])
  Y.append(zahyou[i][1])
P = list(itertools.combinations(X,2))
Q = list(itertools.combinations(Y,2))
for i in range(len(P)):
  for j in range(len(Q)):
    x1 = min(P[i][0],P[i][1])
    x2 = max(P[i][0],P[i][1])
    y1 = min(Q[j][0],Q[j][1])
    y2 = max(Q[j][0],Q[j][1])
    cnt = 0
    for k in range(N):
      if x1 <= zahyou[k][0] <= x2 and y1 <= zahyou[k][1] <= y2:
        cnt += 1
    if cnt >= K:
      if ans >= (x2-x1)*(y2-y1):
        ans = (x2-x1)*(y2-y1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
if N < 1800:
  for n in range(1,3501):
    for w in range(n,3501):
      if (4*n*w-w*N-n*N) != 0:
        h = n*w*N/(4*n*w-w*N-n*N)
        if h == h//1 and h > 0:
          print(int(h),n,w)
          exit()
else:
  for n in range(3500,0,-1):
    for w in range(3500,n,-1):
      if (4*n*w-w*N-n*N) != 0:
        h = n*w*N/(4*n*w-w*N-n*N)
        if h == h//1 and h > 0:
          print(int(h),n,w)
          exit()

Fixed submission:
N = int(input())
for n in range(1,3501):
  for w in range(n,3501):
    if (4*n*w-w*N-n*N) > 0:
      h = n*w*N/(4*n*w-w*N-n*N)
      if h == int(h) and h > 0:
        print(int(h),n,w)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
n = int(input())
d = [[10**14]*n for i in range(n)]
L = []
dist = []
for i in range(n):
    d[i][i] = 0
for i in range(n):
    L = list(map(int,input().split()))
    dist.append(L)
    for j in range(n):
        d[i][j] = L[j]
        d[j][i] = L[j]
d = floyd_warshall(d)
flag = True
for i in range(n):
  for j in range(n):
    if d[i][j] < dist[i][j]:
      flag = False
      break
if not flag:
  print(-1)
else:
  ans = 0
  for i in range(n):
    for k in range(n):
      for j in range(n):
        if i != k and k != j:
          if d[i][j] == d[i][k]+d[k][j]:
            ans += d[i][j]
  print(int((sum(sum(d))-ans)//2))

Fixed submission:
n = int(input())
d = [[10**16]*n for i in range(n)]
L = []
ans = 0
for i in range(n):
    d[i][i] = 0
for i in range(n):
    L = list(map(int,input().split()))
    for j in range(i+1):
        d[i][j] = L[j]
        d[j][i] = L[j]
        ans += L[j]
flag = True
for i in range(n):
  for j in range(i+1):
    for k in range(n):
      if d[i][j] > d[i][k]+d[k][j]:
        print(-1)
        exit()
      else:
        if d[i][j] == d[i][k]+d[k][j] and i != k and k != j:
          ans -= d[i][j]
          break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
A.append(-1)
j = 1
J = 1
ans = 0
while (1 <= j <= len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      j += J
      J = 1
    else:
      j += J
      J = 1
print(ans)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
P = []
for i in range(len(A)):
  if (A[i] not in P):
    P.append(A[i])
c = 0
for i in range(len(P)):
  if (A.count(P[i])%2 == 1):
    c += 1
print(c)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
L = [0 for i in range(10*9)]
for j in range(N):
  L[A[j]] += 1
ans = 0
for k in range(len(L)):
  if (L[k] == 0):
    None
  elif (L[k]%2 == 0):
    None
  else:
    ans += 1
print(ans)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]
L.sort()
k = 1
for i in range(len(L)):
  if (L[i] == L[i+1]):
    k -= 1
  else:
    k += 1
print(k)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(input()) for i in range(N)]
A = []
for i in range(len(L)):
  if (L[i] not in A):
    A.append(L[i])
k = 0
for j in range(len(A)):
  s = L.count(A[j])
  if (s%2 != 0):
    k += 1
print(k)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
L = []
ans = float('inf')
for i in range(M):
    L.append(list(map(int,input().split())))
cost = []
for i in range(N):
    T = [float('inf') for j in range(N)]
    cost.append(T)
for i in range(M):
    cost[L[i][0]-1][L[i][1]-1] = L[i][2]
    cost[L[i][1]-1][L[i][0]-1] = L[i][2]
for l in range(N):
    for k in range(N):
        for m in range(N):
            cost[k][m] = min(cost[k][l]+cost[l][m], cost[k][m])

junretu = list(itertools.permutations(r))
for i in range(len(junretu)):
    temp = 0
    for j in range(len(r)-1):
        c = junretu[i][j]
        d = junretu[i][j+1]
        temp += cost[c-1][d-1]
    ans = min(ans,temp)
print(ans)

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
import itertools
n,m,r = map(int,input().split())
L = list(map(int,input().split()))
d = [[float("inf")]*n for i in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(m):
    a,b,l = map(int,input().split())
    d[a-1][b-1] = l
    d[b-1][a-1] = l
d = floyd_warshall(d)
ans = float('inf')
seq = []
for i in range(r):
  seq.append(i)
K = list(itertools.permutations(seq))
for i in range(len(K)):
  cur = 0
  for j in range(1,r):
    p = L[K[i][j-1]]-1
    q = L[K[i][j]]-1
    cur += d[p][q]
  if cur != float('inf'):
    if cur <= ans:
      ans = cur
print(int(ans))
Buggy python submission (verdict: Runtime Error):
X,t = map(int,input().split())
if (x >= t):
  print(x-t)
else:
  print(0)

Fixed submission:
x,t = map(int,input().split())
if (x >= t):
  print(x-t)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
L = list(map(int,input().split()))
A = []
for a in L:
  if (a not in A):
    A.append(a)
J = [1]
for i in range(len(A)):
  p = L.count(A[i]-1)+L.count(A[i])+L.count(A[i]+1)
  if (J[0] < p):
    del J[0]
    J.append(p)
print(J[0])

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
L = list(map(int,input().split()))
A = []
for a in L:
  if (a not in A):
    A.append(a)
J = []
for i in range(len(A)):
  J.append(L.count(A[i]-1)+L.count(A[i])+L.count(A[i]+1))
print(max(J))

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
L = list(map(int,input().split()))
L.sort()
J = []
for i in range(len(L)):
  J.append(L.count(L[i]-1)+L.count(L[i])+L.count(L[i]+1))
print(max(J))

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N = int(input())
graph = [[] for _ in range(N+1)] #木構造を入れておく
long = [0] * (N+1) #Kから任意のノードまでの距離

for i in range(N-1):
  x, y, z = map(int, input().split())
  graph[x].append([y, z])
  graph[y].append([x, z])
  
Q, K = map(int, input().split())
x = list()
y = list()
  
for i in range(1,N+1): #Kから任意のノードまでの距離を求める
  q = deque([K])
  while q:
    t = q.popleft()
    for i in range(len(graph[t])):
      next_t = graph[t][i][0]
      if(long[next_t] > 0):
        continue
        
      else:
        q.append(next_t)
        long[next_t] = long[t] + graph[t][i][1]
        

for i in range(Q):
  x_i, y_i = map(int, input().split())
  ans = long[x_i] + long[y_i]
  print(ans)


Fixed submission:
import heapq
def dijkstra_heap(s):
    d = [float("inf")]*n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
Q,K = map(int,input().split())
L = dijkstra_heap(K-1)
query = []
for i in range(Q):
  query.append(list(map(int,input().split())))
for i in range(Q):
  print(L[query[i][0]-1]+L[query[i][1]-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
flag = False
j = 0
while (0 <= j <= len(L)-1):
  k = L[j][1]
  if ([1,k] in L):
    if ([k,N] in L):
      flag = True
      break
    else:
      j += 1
  else:
    j += 1
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
J = [False]*(N+1)
K = [False]*(N+1)
J[0] = False
K[N] = False
J[1] = False
K[1] = False
for j in range(M):
  if L[j][0] == 1:
    J[L[j][1]] = True
for k in range(M):
  if L[k][1] == N:
    K[L[k][0]] = True
flag = False
for l in range(N+1):
  if J[l] and K[l]:
    flag = True
    break
if flag:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
A = []
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
  A.append(p)
print(min(A))


Fixed submission:
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
k = 0
ans = abs(2*sum(L[0:1])-S)
for i in range(0,N-1):
  k += L[i]
  ans = min(ans,abs(2*k-S))
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
A = []
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
    A.append(p)
print(min(A))

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
k = 0
ans = abs(2*sum(L[0:1])-S)
for i in range(0,N-1):
  k += L[i]
  ans = min(ans,abs(2*k-S))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
A = [abs(2*sum(L[0:1])-S)]
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
  if (p <= A[0]):
    del A[0]
    A.append(p)
print(A[0])

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
k = 0
ans = abs(2*sum(L[0:1])-S)
for i in range(0,N-1):
  k += L[i]
  ans = min(ans,abs(2*k-S))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
L = []
for i in range(n):
  L.append(A[i])
  L.reverse()
for j in range(n):
  print(L[j],end = ' ')

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
if n%2 == 0:
  for i in range(n//2):
    print(L[2*(n//2-i-1)+1],end = ' ')
  for j in range(n//2):  
    print(L[2*j],end = ' ')
else:
  for k in range(n//2+1):
    print(L[2*(n//2-k)],end = ' ')
  for l in range(n//2):
    print(L[2*(l+1)-1],end = ' ')
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int.input().split())
if (b-a == c-b):
  print('YES')
else:
  print('NO')

Fixed submission:
a,b,c = map(int,input().split())
if (b-a == c-b):
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
n,ma,mb = map(int,input().split())
L = []
for i in range(n):
    a,b,c = map(int,input().split())
    L.append([a,b,c])
dp = [[10**5]*401 for i in range(401)]
make = [[0,0],[L[0][0],L[0][1]]]
dp[L[0][0]][L[0][1]] = L[0][2]
dp[0][0] = 0
for i in range(1,n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(len(make)):
        t = make[j][0]
        u = make[j][1]
        dp[t+a][u+b] = min(dp[t][u]+c,dp[t+a][u+b])
        make.append([t+a, u+b])
    make = list(set(make))
if ma <= mb:
    cnt = 1
    ans = 10**5
    while mb*cnt <= 400:
        ans = min(ans, dp[ma*cnt][mb*cnt])
        cnt += 1
    if ans == 10**5:
        print(-1)
    else:
        print(ans)
else:
    cnt = 1
    ans = 10**5
    while ma*cnt <= 400:
        ans = min(ans, dp[ma*cnt][mb*cnt])
        cnt += 1
    if ans == 10**5:
        print(-1)
    else:
        print(ans)


Fixed submission:
A,B = map(int,input().split())
if (A == 1):
  if (B == 1):
    print('Draw')
  else:
    print('Alice')
else:
  if (B == 1):
    print('Bob')
  elif (A == B):
    print('Draw')
  elif (A > B):
    print('Alice')
  else:
    print('Bob')