Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
D, G = map(int, input().split())
p = []
c = []
for i in range(D):
    P, C = map(int, input().split())
    p.append(P)
    c.append(C)

getPoint = [[] for i in range(max(p))]
#getPoint = [0 for i in range(max(p))]
#print(c)
for i in range(max(p)):
    for j in range(D):
        if p[j] - 1> i:
            getPoint[i].append((i + 1) * 100 * (j + 1))
        else:
            getPoint[i].append(p[j] * (j + 1) * 100 + c[j])

#print(getPoint)

def sarch(G, keypoint):
    i = 0
    print(G, keypoint, 1111)
    if max(getPoint[-1]) >= G:
        i = 0
        while True:
            if max(getPoint[i]) >= G:
                print(keypoint + i + 1)
                break
            i += 1
    else:
        G -= max(getPoint[-1])
        keypoint += max(p)
        for i in range(len(getPoint[-1])):
            if getPoint[-1][i] == max(getPoint[-1]):
                key = i
        del p[i]
        del getPoint[max(p) + 1:]
        for i in range(len(getPoint)):
            del getPoint[i][key]
        sarch(G, keypoint)

def sarch2(G, keypoint):
    if G < 0:
        return print(keypoint)
    num = sorted(getPoint[0])[-1]
    for i in range(len(getPoint[0])):
        if getPoint[0][i] == max(getPoint[0]):
            num = i
    i = 0
    while True:
        if getPoint[i][num] < max(getPoint[i]):
            G -= getPoint[i][num]
            keypoint = keypoint + i + 1
            for j in range(len(getPoint)):
                if j < i:
                    #print(j, i)
                    getPoint[j][num] = getPoint[j + i + 1][num]
                else:
                    getPoint[j][num] = getPoint[-1][num]
            sarch2(G, keypoint)
            break
        i += 1
        if i >= len(getPoint):
            break
i = 0
#sarch(G, 0)
sarch2(G, 0)

Fixed submission:
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]

ans_cnt = 10 ** 20
for i in range(2 ** (D)):
    def make_p(i):
        p = bin(i)[2::]
        while len(p) != D:
            p = "0" + p
        key = D
        for j in range(D - 1, -1, -1):
            if int(p[j]) == 0:
                key = j
                break
        return p, key
    
    p_and_key = make_p(i)
    p = p_and_key[0]
    key = p_and_key[1]
    cnt = 0
    ansP = 0
    for j in range(len(p)):
        if p[j] == "1":
            ansP += pc[j][0] * 100 * (j + 1) + pc[j][1]
            cnt += pc[j][0]
    j = 0
    if int(key) != int(D):
        key = int(key)
        while ansP < G:
            j = int(j)
            if pc[key][0] <= j:
                break
            ansP += 100 * (key + 1)
            cnt += 1
            j += 1
    if ansP >= G:
        ans_cnt = min(ans_cnt, cnt)

print(ans_cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
i = 2
while True:
    if i / N == 0:
        print(i)
        break
    i += 2

Fixed submission:
N = int(input())
i = 2
if N % 2 == 0:
    print(N)
else:
    print(N * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
data = list(map(int, input().split()))
for i in range(N):
    data[i] -= (i + 1)
ave = sum(data) / N
if ave > 0:
    key = int(ave + 1)
    key1 = int(ave)
else:
    key = int(ave - 1)
    key1 = int(ave)
data.sort()
sumdata = 0
sumdata1 = 0
sumdatax = 0
#for i in data:
 #   sumdata += abs(i - key)
  #  sumdata1 += abs(i - key1)
   # sumdatax += abs(i - ave)
cnt = 0
sumdataa = 0
key = data[0] - 1
for i in data:
    if key != i:
        key = i
        for j in data:
            sumdataa += abs(j - key)
        #print(sumdataa)
        if cnt == 0:
            minsum = sumdataa
        if sumdataa < minsum:
            minsum = sumdataa
    cnt += 1
    sumdataa = 0

#print(sumdatax)
#print(data)
#print(min([sumdata, sumdata1]))
print(minsum)


Fixed submission:
N = int(input())
data = list(map(int, input().split()))
for i in range(N):
    data[i] -= (i + 1)
ave = sum(data) / N
if ave > 0:
    key = int(ave + 1)
    key1 = int(ave)
else:
    key = int(ave - 1)
    key1 = int(ave)
data.sort()
sumdata = 0
sumdata2 = 0
key = data[int(N / 2) - 1]
key2 = data[int(N / 2)]
for i in data:
    sumdata += abs(i - key)
    sumdata2 += abs(i - key2)

#print(sumdatax)
#print(data)
print(min([sumdata, sumdata2]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
s = []
count = 300000
for i in range(N):
    s.append(S[i])
for i in range(N):
    cnt = 0
    for j in range(i):
        if S[j] == "W":
            cnt += 1
            if count < cnt:
                cnt -= 1
                break
    for j in range(N - 1, i, -1):
        if S[j] == "E":
            cnt += 1
            if count < cnt:
                cnt -= 1
                break
    count = cnt

print(count)

Fixed submission:
N = int(input())
S = input()
s = []
cnt = 0
for i in range(N):
    if S[i] == "W":
        s.append(-1)
    elif S[i] == "E":
        s.append(1)
        if i != 0:
            cnt += 1
        
DP = [cnt]

for i in range(1, N):
    cnt = 0
    if s[i - 1] == -1:
        cnt += 1
    if s[i] == 1:
        cnt -= 1
    DP.append(DP[i - 1] + cnt)

print(min(DP))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
S = []
for i in range(1, len(s) + 1):
    k = 0
    while True:
        count = 0
        if len(s) - k - i < 0:
            break
        a = []
        for j in range(0, i):
            a.append(s[j + k])
        k += 1
        for j in S:
            if j == a:
                count += 1
                break
        if count == 0: S.append(a)

#keylist = []
#for i in range(len(S)):
  #  for j in range(len(S)):
 #       if S[i] == S[j] and i != j and i > j:
#            keylist.append(i)

#for i in keylist:
#    del S[i]
S.sort()
print(''.join(S[K - 1]))


Fixed submission:
s = list(input())
K = int(input())
j = 0
candidate = []
while True:
    if j > 26:
        break
    for i in range(len(s)):
        if s[i] == chr(ord("a") + j):
            for k in range(1, min(6, len(s) - i + 1)):
                candidate.append(s[i:i + k])
    j += 1
i = 1
candidate.sort()
while i < len(candidate):
    if candidate[i] == candidate[i - 1]:
        del candidate[i]
        i -= 1
    i += 1

for i in candidate[K - 1]:
    print(i, end = "")
print()

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())
S = []
for i in range(1, len(s) + 1):
    k = 0
    while True:
        if len(s) - k - i < 0:
            break
        a = []
        for j in range(0, i):
            a.append(s[j + k])
        S.append(a)
        k += 1

keylist = []
for i in range(len(S)):
    for j in range(len(S)):
        if S[i] == S[j] and i != j and i > j:
            keylist.append(i)

for i in keylist:
    del S[i]
S.sort()
print(''.join(S[K - 1]))

Fixed submission:
s = list(input())
K = int(input())
j = 0
candidate = []
while True:
    if j > 26:
        break
    for i in range(len(s)):
        if s[i] == chr(ord("a") + j):
            for k in range(1, min(6, len(s) - i + 1)):
                candidate.append(s[i:i + k])
    j += 1
i = 1
candidate.sort()
while i < len(candidate):
    if candidate[i] == candidate[i - 1]:
        del candidate[i]
        i -= 1
    i += 1

for i in candidate[K - 1]:
    print(i, end = "")
print()
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
if K <= 100:
    s = [0 for i in range(B - A + 1)]
    if K > len(s):
        K = len(s)
    
    for i in range(K):
        s[i] = 1
        s[B - A - i] = 1
 
    for i in range(B - A + 1):
        if s[i] == 1:
            print(i + A)

else:
    ss = [0 for i in range(100)]
    sb = [0 for i in range(100)]

    for i in range(K):
        print(i + A)

    for i in range(K):
        print(B - K + i + 1)

Fixed submission:
A, B, K = map(int, input().split())
if B - A <= 100:
    s = [0 for i in range(B - A + 1)]
    if K > len(s):
        K = len(s)
    
    for i in range(K):
        s[i] = 1
        s[B - A - i] = 1
 
    for i in range(B - A + 1):
        if s[i] == 1:
            print(i + A)

else:
    ss = [0 for i in range(100)]
    sb = [0 for i in range(100)]

    for i in range(K):
        print(i + A)

    for i in range(K):
        print(B - K + i + 1)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
s = [0 for i in range(B - A + 1)]
if K > len(s):
    K = len(s)
    
for i in range(K):
    s[i] = 1
    s[B - A - i] = 1

for i in range(B - A + 1):
    if s[i] == 1:
        print(i + A)


Fixed submission:
A, B, K = map(int, input().split())
if B - A <= 100:
    s = [0 for i in range(B - A + 1)]
    if K > len(s):
        K = len(s)
    
    for i in range(K):
        s[i] = 1
        s[B - A - i] = 1
 
    for i in range(B - A + 1):
        if s[i] == 1:
            print(i + A)

else:
    ss = [0 for i in range(100)]
    sb = [0 for i in range(100)]

    for i in range(K):
        print(i + A)

    for i in range(K):
        print(B - K + i + 1)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
print(min([A, B] + min([C, D])))

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
print(min([A, B]) + min([C, D]))
Buggy python submission (verdict: Time Limit Exceeded):
PN = [i for i in range(100001)]
i = 2
while True:
    if i >= len(PN):
        break
    j = i * 2
    while True:
        if j >= len(PN):
            break
        PN[j] = 0
        j += i
    while True:
        i += 1
        if i >= len(PN):
            break
        if PN[i] != 0:
            break
PN[1] = 0
PN_2 = []
for i in range(100001):
    if PN[i] != 0 and PN[int((PN[i] + 1) / 2)] != 0:
        PN_2.append(PN[i])
    else:
        PN_2.append(0)

Q = int(input())
lr = []
for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        if PN_2[j] != 0:
            cnt += 1
    print(cnt)

Fixed submission:
PN = [i for i in range(100001)]
i = 2
while True:
    if i >= len(PN):
        break
    j = i * 2
    while True:
        if j >= len(PN):
            break
        PN[j] = 0
        j += i
    while True:
        i += 1
        if i >= len(PN):
            break
        if PN[i] != 0:
            break
PN[1] = 0
PN_2 = [0]
DPN = [0]
for i in range(1, 100001):
    if PN[i] != 0 and PN[int((PN[i] + 1) / 2)] != 0:
        PN_2.append(PN[i])
        DPN.append(DPN[i - 1] + 1)
    else:
        PN_2.append(0)
        DPN.append(DPN[i - 1])

#print(PN[1:30])
#print(PN_2[1:30])
#print(DPN[1:30])

Q = int(input())
lr = []
for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    print(DPN[r] - DPN[l - 1])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
print(int((a + b ) / 2))


Fixed submission:
a, b = map(int, input().split())
c = (a + b) / 2
if c == int(c): print(int(c))
else: print(int(c + 1))
Buggy python submission (verdict: Time Limit Exceeded):
b = []
count = []
def sarch(num):
    for i in range(len(b)):
        if num == b[i]:
            return i
    b.append(num)
    count.append(0)
    return len(b) - 1
    
N = input()
a = list(map(int, input().split()))
ans = 0
for i in range(len(a)):
    if a[i] != 0:
        count[sarch(a[i])] += 1
for i in range(len(count)):
    if b[i] > count[i]:
        ans += count[i]
    elif b[i] < count[i]:
        ans += (count[i] - b[i])
print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
cnt = 1
key = a[0]
ans = 0
while True:
    if i >= len(a):
        break
    if key == a[i]:
        cnt += 1
    else:
        if key != cnt:
            if cnt > key:
                ans += cnt - key
            else:
                ans += cnt
        cnt = 1
        key = a[i]
    
    i += 1

if key != cnt:
    if cnt > key:
        ans += cnt - key
    else:
        ans += cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = list(map(int, input().split()))
ans = 0
count = 1
for i in range(len(a)):
    if a[i] != 0:
        for j in range(i + 1, len(a)):
            if a[j] == a[i]:
                count += 1
                a[j] = 0
        if a[i] > count: ans += count
        elif a[i] < count: ans += (count - a[i])
        a[i] = 0
        count = 1
print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
cnt = 1
key = a[0]
ans = 0
while True:
    if i >= len(a):
        break
    if key == a[i]:
        cnt += 1
    else:
        if key != cnt:
            if cnt > key:
                ans += cnt - key
            else:
                ans += cnt
        cnt = 1
        key = a[i]
    
    i += 1

if key != cnt:
    if cnt > key:
        ans += cnt - key
    else:
        ans += cnt

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())
time = [0 for i in range(100010)]
CTS = []
for i in range(N):
    S, T, C = map(int, input().split())
    CTS.append([C, S, T])

CTS.sort()

i = 1
while i < len(CTS):
    if CTS[i][0] == CTS[i - 1][0]:
        if CTS[i][1] == CTS[i - 1][2]:
            CTS[i - 1][2] = CTS[i][2]
            del CTS[i]
            i -= 1
    i += 1
    
for i in range(len(CTS)):
    S = CTS[i][1]
    T = CTS[i][2]
    time[S - 1] += 1
    time[T] -= 1   
for i in range(1, 100010):
    time[i] += time[i - 1]


print(max(time))


Fixed submission:
N, c = map(int, input().split())
time = [0 for i in range(100001)]
time_c = [[0 for i in range(100001)] for j in range(c)]
          
for i in range(N):
    S, T, C = map(int, input().split())
    time_c[C - 1][S] += 1
    time_c[C - 1][T] -= 1
    
for i in range(100001):
    for j in range(c):
        if time_c[j][i] > 0:
            time[i - 1] += time_c[j][i]
        if time_c[j][i] < 0:
            time[i] += time_c[j][i]

for i in range(1, 100001):
    time[i] += time[i - 1]

print(max(time))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
#A < B < C
def sarch(i, left, right, x, y):
    mid = (right + left) // 2
    if right - left < 3:
        return left, right
    elif x[i] <= y[mid]:
        sarch(i, left, mid, x, y)
    elif y[mid] <= x[i]:
        sarch(i, mid, right, x, y)
cnt_a = [0 for i in range(N)]
cnt_b = [0 for i in range(N)]


for i in range(N):
    sg = sarch(i, 0, N - 1, B, C)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if B[i] < C[j]:
            ans = 1
            break
    if ans == -1:
        j = N
    cnt_b[i] = N - j
ans_2 = 0    
for i in range(N):
    sg = sarch(i, 0, N - 1, A, B)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if A[i] < B[j]:
            ans = 1
            break
    if ans == 1:
        for k in range(j, N):
            ans_2 += cnt_b[k]
    cnt_a[i] = N - j
print(ans_2)


Fixed submission:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()

cnt = 0
cnt_b = []
for i_b in range(n):
    # if max(c) < b[i_b]:
    #     cnt_b.append(0)
    #     continue
    i_a = bisect.bisect_left(a, b[i_b]) - 1
    i_c = bisect.bisect_right(c, b[i_b])
    if i_a < 0 or n <= i_c:
        continue
    cnt += (i_a + 1) * (n - i_c)
    # print(i_a, i_b, i_c)

print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
#A < B < C
def sarch(i, left, right, x, y):
    mid = (right + left) // 2
    if right - left < 10:
        return left, right
    elif x[i] <= y[mid]:
        sarch(i, left, mid, x, y)
    elif y[mid] <= x[i]:
        sarch(i, mid, right, x, y)
cnt_a = [0 for i in range(N)]
cnt_b = [0 for i in range(N)]


for i in range(N):
    sg = sarch(i, 0, N - 1, B, C)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if B[i] < C[j]:
            ans = 1
            break
    if ans == -1:
        j = N
    cnt_b[i] = N - j
ans_2 = 0    
for i in range(N):
    sg = sarch(i, 0, N - 1, A, B)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if A[i] < B[j]:
            ans = 1
            break
    if ans == 1:
        for k in range(j, N):
            ans_2 += cnt_b[k]
    cnt_a[i] = N - j
print(ans_2)


Fixed submission:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()

cnt = 0
cnt_b = []
for i_b in range(n):
    # if max(c) < b[i_b]:
    #     cnt_b.append(0)
    #     continue
    i_a = bisect.bisect_left(a, b[i_b]) - 1
    i_c = bisect.bisect_right(c, b[i_b])
    if i_a < 0 or n <= i_c:
        continue
    cnt += (i_a + 1) * (n - i_c)
    # print(i_a, i_b, i_c)

print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
cnt = 0
for i in range(len(s) - len(t), -1, -1):
    cnt = 0
    for j in range(len(t)):
        if s[j + i] == "?" or s[j + i] == t[j]:
            cnt += 1
        else:
            break
    if cnt == len(t):
        for j in range(len(s)):
            if i <= j < j + len(t):
                print(t[j - i], end = "")
            elif s[j] == "?":
                print("a", end = "")
            else:
                print(s[j], end = "")
        print()
        break
if cnt != len(t):
    print("UNRESTORABLE")

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

ans = -1
ansS = []
if len(S) < len(T):
    ans = -1
else:
    for i in range(len(S) - len(T) + 1):
        ans = 1
        for j in range(len(T)):
            #print(S[i + j], T[j])
            if S[i + j] != T[j] and S[i + j] != "?":
                ans = -1
                break
        if ans == 1:
            thisS = S[:i] + T + S[i + len(T):]
            for j in range(len(S)):
                if thisS[j] == "?":
                    thisS[j] = "a"
            ansS.append(thisS)

if len(ansS) == 0:
    print("UNRESTORABLE")
else:
    ansS.sort()
    for i in ansS[0]:
        print(i, end = "")
    print()

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

S = []
T = []

S_a = []

for i in range(len(s)):
    S.append(s[i])

for i in range(len(t)):
    T.append(t[i])

for i in range(len(S)):
    if S[i] == T[0]:
        for j in range(len(T)):
            if S[i + j] != T[j] and S[i + j] != "?":
                print('a')
                print(S[i+j] + T[j])
                break
        if j == len(T) - 1:
            string = S[0:i] + T + S[i + len(T)::]
            S_a.append(string)
            for k in range(len(string)):
                if string[k] == "?":
                    string[k] = "a"
S_a.sort()
if S_a == []:
    print("UNRESTORABLE")
else: print(''.join(S_a[0]))

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

ans = -1
ansS = []
if len(S) < len(T):
    ans = -1
else:
    for i in range(len(S) - len(T) + 1):
        ans = 1
        for j in range(len(T)):
            #print(S[i + j], T[j])
            if S[i + j] != T[j] and S[i + j] != "?":
                ans = -1
                break
        if ans == 1:
            thisS = S[:i] + T + S[i + len(T):]
            for j in range(len(S)):
                if thisS[j] == "?":
                    thisS[j] = "a"
            ansS.append(thisS)

if len(ansS) == 0:
    print("UNRESTORABLE")
else:
    ansS.sort()
    for i in ansS[0]:
        print(i, end = "")
    print()
Buggy python submission (verdict: Time Limit Exceeded):
import copy
S = list(input())
s = copy.copy(S)
ans = 1
i = 0
while True:
    if i >= len(s):
        break
    if s[i] == "x":
        del s[i]
        i -= 1
    i += 1
def main(s):
    for i in range(int((len(s)) / 2)):
        if s[i] != s[len(s) - 1 - i]:
            print(-1)
            return 0
    i = 0
    s = copy.copy(S)
    cnt = 0
    while True:
        if i >= int(len(s) / 2):
            break
        if s[i] != s[len(s) - 1 - i]:
            if s[i] != "x":
                s.insert(i, "x")
            else:
                s.insert(len(s) - i, "x")
            i -= 1
            cnt += 1
        i += 1
    print(cnt)
    return 0
        
            
main(s)

Fixed submission:
import copy
S = list(input())
s = copy.copy(S)
ans = 1
i = 0
while True:
    if i >= len(s):
        break
    if s[i] == "x":
        del s[i]
        i -= 1
    i += 1

def main(s):
    for i in range(int((len(s)) / 2)):
        if s[i] != s[len(s) - 1 - i]:
            print(-1)
            return 0
    cnt = 0
    num = [-1]
    for i in range(len(S)):
        if S[i] != "x":
            num.append(i)
    num.append(len(S))
    i = 0
    s = copy.copy(S)
    cnt = 0
    #print(num)
    if len(num) % 2 == 0:
        i = int(len(num) / 2)
        for j in range(i, len(num) - 1):
            #print(i, j, j + 1, len(num) - j - 1, len(num) - j - 2)
            cnt += abs(abs(num[j] - num[j + 1]) - abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
            #print(abs(num[j] - num[j + 1]), i, j)
            #print(abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
    else:
        i = int(len(num) / 2)
        for j in range(i, len(num) - 1):
            #print(i, j, j + 1, len(num) - j - 1, len(num) - j - 2)
            cnt += abs(abs(num[j] - num[j + 1]) - abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
            #print(abs(num[j] - num[j + 1]), i, j)
            #print(abs(num[len(num) - j - 1] - num[len(num) - j - 2]))
    print(cnt)
    return 0
        
            
main(s)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, inpu())
if a == b:
  print(c)
elif b == c:
  print(a)
else:
  print(b)

Fixed submission:
a, b, c = map(int, input().split())
if a == b:
  print(c)
elif b == c:
  print(a)
else:
  print(b)
Buggy python submission (verdict: Runtime Error):
X, t = map(int, input).split())
X -= t
if X < 0:
  X = 0
print(X)

Fixed submission:
X, t = map(int, input().split())
X -= t
if X < 0:
  X = 0
print(X)
Buggy python submission (verdict: Time Limit Exceeded):
def ABC070D():
    N = int(input())
    abc = [list(map(int, input().split())) for i in range(N - 1)]
    ab = [[10000000000000 for i in range(N)] for j in range(N)]
    Q, K = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(Q)]
    for i, j, k in abc:
        ab[i - 1][j - 1] = k
        ab[j - 1][i - 1] = k

    for k in range(N):
        for i in range(N):
            for j in range(N):
                ab[i][j] = min(ab[i][j], ab[i][k] + ab[k][j])

    for x, y in xy:
        print(ab[x - 1][K - 1] + ab[K - 1][y - 1])
ABC070D()

Fixed submission:
def ij2str(i, j):
    return str(i) + '+' + str(j)

n = int(input())
tree = [[] for _ in range(n)]
dis = [0 for _ in range(n)]
c_list = {}
visited = set()
for i in range(n-1):
    a, b, c = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    c_list[ij2str(a-1, b-1)] = c
    c_list[ij2str(b-1, a-1)] = c

from collections import deque

q, k = map(int, input().split())
visited.add(k-1)
next = deque()
next.append(k-1)

while len(next):
    i = next.popleft()
    for j in tree[i]:
        if not j in visited:
            dis[j] = dis[i] + c_list[ij2str(i, j)]
            next.append(j)
            visited.add(j)

for i in range(q):
    x, y = map(int, input().split())
    print(dis[x-1] + dis[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
for i in range(n - 1):
    print(b[i], end = " ")
print(b[n - 1], end = "")
print()


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = []
if n % 2 == 0:
    key = n - 1
else:
    key = n - 2
for i in range(key, 0, -2):
    b.append(a[i])
for i in range(0, n, 2):
    b.append(a[i])
if n % 2 != 0:
    b = b[::-1]
for i in range(n - 1):
    print(b[i], end = " ")
print(b[n - 1], end = "")
print()