Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
M = [[] for i in range(N+1)]

for i in range(N-1):
    a, b, c = list(map(int, input().split(" ")))
    M[a].append((b,c))
    M[b].append((a,c))

Qn, K = list(map(int, input().split(" ")))

Q = []
for i in range(Qn):
    Q.append(list(map(int, input().split(" "))))

distance = [0]*(N+1)

def dfs(k, parent, dist):
    for n, x in M[k]:
        if n != parent:
            distance[n] = dist + x
            dfs(n, k, dist + x)

dfs(K, 0, 0)
for q in Q:
    print(distance[q[0]] + distance[q[1]])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(50000)

N = int(input())
M = [[] for i in range(N+1)]

for i in range(N-1):
    a, b, c = list(map(int, input().split(" ")))
    M[a].append((b,c))
    M[b].append((a,c))

Qn, K = list(map(int, input().split(" ")))

Q = []
for i in range(Qn):
    Q.append(list(map(int, input().split(" "))))

distance = [0]*(N+1)

def dfs(k, parent, dist):
    for n, x in M[k]:
        if n != parent:
            distance[n] = dist + x
            dfs(n, k, dist + x)

dfs(K, 0, 0)
for q in Q:
    print(distance[q[0]] + distance[q[1]])

Buggy submission (verdict: Runtime Error):
N = int(input())
M = [[] for i in range(N+1)]

for i in range(N-1):
    a, b, c = list(map(int, input().split(" ")))
    M[a].append((b,c))
    M[b].append((a,c))

Qn, K = list(map(int, input().split(" ")))

Q = []
for i in range(Qn):
    Q.append(list(map(int, input().split(" "))))

distance = [0]*(N+1)

def dfs(k, parent, dist):
    for n, x in M[k]:
        if n != parent:
            distance[n] = dist + x
            dfs(n, k, dist + x)

dfs(K, 0, 0)
for q in Q:
    print(distance[q[0]] + distance[q[1]])
Problem p02989 (python)

Fixed submission:
N = int(input())
d = list(map(int,input().split()))
d.sort()
#print(d)
c = [0] * N 
i = 0
tmp = d[0]
count = 1
 
for j in range(1,N):
    if tmp == d[j]:
        #print("yes",j)
        count += 1
    else:
        #print("no",j)
        tmp = d[j]   
        c[i] = count
        count = 1
        i += 1
#print(c)
 
hantei = 0
hantei1 = 0

for j in range(N):
    hantei += c[j]
    if len(d) / 2 == hantei:
        hantei1 = 1
        break
    elif len(d) / 2 < hantei:
        #hantei1 = 0
        break
 
if hantei1 == 1:
    print(d[len(d)//2] - d[len(d)//2-1])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int,input().split()))
d.sort()
#print(d)
c = [0] * N 
i = 0
tmp = d[0]
count = 1

for j in range(1,N):
    if tmp == d[j]:
        #print("yes",j)
        count += 1
    else:
        #print("no",j)
        tmp = d[j]   
        c[i] = count
        count = 1
        i += 1
#print(c)

hantei = 0
for j in range(N):
    hantei += c[j]
    if len(d) / 2 == hantei:
        hantei1 = 1
        break
    elif len(d) / 2 < hantei:
        hantei1 = 0
        break

if hantei1 == 1:
    print(d[len(d)//2] - d[len(d)//2-1])
else:
    print(0)
Problem p03252 (python)

Fixed submission:
import string

S = input()
T = input()

count1 = [0] * 26
count2 = [0] * 26


for j in range(26):
    count1[j] = S.count(string.ascii_lowercase[j])
    count2[j] = T.count(string.ascii_lowercase[j])

hantei = 1

for i in range(0,len(S)+1):
    count_tmp1 = 0
    count_tmp2 = 0
    for j in range(26):
        if i == count1[j] :
            count_tmp1 += 1
    for j in range(26):
        if i == count2[j] :
            count_tmp2 += 1
    if count_tmp1 != count_tmp2:
        hantei = 0
        break

if hantei == 0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

S1 = sorted(S)
T1 = sorted(T)

count1 = 0
count2 = 0

for j in range(26):
    for i in range(len(S1)):
        if string.ascii_lowercase[j] == S1[i]:
            count1 += 1
            break
    for i in range(len(T1)):
        if string.ascii_lowercase[j] == T1[i]:
            count2 += 1
            break

if count1 == count2:
    print("Yes")
else:
    print("N0")
Problem p02990 (python)

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

from operator import mul
from functools import reduce

def combinations_count(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

div = K - 1  
for i in range(1, K+1):
  split_ball = combinations_count(div, i-1)
  red_ball = N-K-i+1
  if red_ball<0:
    red_balls = 0
  else:
    red_balls = combinations_count(red_ball+i, i)
  print((split_ball * red_balls) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

from operator import mul
from functools import reduce

def combinations_count(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

div = K - 1  
for i in range(1, K+1):
  split_ball = combinations_count(div, i-1)
  red_ball = N-K-i+1
  if i-1==N-K:
    red_balls = 1
  else:
    red_balls = combinations_count(red_ball+i, i)
  print((split_ball * red_balls) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

from operator import mul
from functools import reduce

def combinations_count(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

div = K - 1  
for i in range(1, K+1):
  split_ball = combinations_count(div, i-1)
  red_ball = N-K-i+1
  red_balls = combinations_count(red_ball+i, i)
  print((split_ball * red_balls) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

div = K - 1  
for i in range(1, K+1):
  split_ball = combinations_count(div, i-1)
  red_ball = N-K-i+1
  red_balls = combinations_count(red_ball+i, i)
  print((split_ball * red_balls) % (10**9 + 7))
Problem p03013 (python)

Fixed submission:
N,M = map(int,input().split())
a = [True] * (N+1)

for _ in range(M):
  a[int(input())] = False

S = [0] * (N+1)
S[0] = 1
for n in range(1, N+1):
    if a[n]==False:
        S[n] = 0
    elif n==1:
        S[n] = 1
    else:
        S[n] = (S[n-1] + S[n-2])%1000000007

print(S[n])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
for _ in range(M):
  a.append(input())

S = [0] * (N+1)
for n in range(N+1):
    if str(n) in a:
        S[n] = 0
    elif n<=1:
        S[n] = 1
    else:
        S[n] = S[n-1] + S[n-2]

Buggy submission (verdict: Runtime Error):
def countStep(n):
    global S, b
    if n<0:
        return 0
    elif n==0:
        return 1
    elif str(n) in b:
        count = S[n]
        return count
    else:
        count1 = countStep(n-1)
        count2 = countStep(n-2)
        count = count1 + count2
        b.append(str(n))
        S[n] = count
        return count

N,M = map(int,input().split())
b = []
for _ in range(M):
  b.append(input())
S = [0] * (N+1)

print(countStep(N) % 1000000007)

Buggy submission (verdict: Runtime Error):
def countStep(n):
    global S, b
    if n==-1:
        return 0
    elif n==0:
        return 1
    elif str(n) in b:
        count = S[n]
        return count
    else:
        count1 = countStep(n-1)
        count2 = countStep(n-2)
        count = count1 + count2
        b.append(str(n))
        S[n] = count
        return count

N,M = map(int,input().split())
b = []
for _ in range(M):
  b.append(input())
S = [0] * (N+1)

print(countStep(N) % 1000000007)
Problem p03038 (python)

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

a.sort()
b.sort(reverse = True)

now = 0
end = False

for i in range(0,m):
    if now >= n or end == True:
        break
    for j in range(0,b[i][1]):
        if now >= n:
            break
        if a[now] < b[i][0]:
            a[now] = b[i][0]
            now += 1
        else:
            end = True
            break

print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [[0]*2 for i in range(0,m)]
for i in range(0,m):
    b[i][1],b[i][0] = list(map(int,input().split()))

a.sort()
b.sort(reverse = True)

now = 0

for i in range(0,m):
    if now >n:
        break
    for j in range(0,b[i][1]):
        if now > n:
            break
        if a[now] < b[i][0]:
            a[now] = b[i][0]
            now += 1
        else:
            break

print(sum(a))
Problem p03107 (python)

Fixed submission:
s = list(input())
zero = s.count("0")
ans = min(len(s)-zero,zero)
print(ans*2)

Buggy submission (verdict: Runtime Error):
s = list(input())
count = 0
find = False
while True:
    if len(s) <=2:
        break
    for i in range(0,len(s)-1):
        if s[i] != s[i+1]:
            count += 2
            del s[i]
            del s[i+1]
            break
    else:
        break
    
print(count)
Problem p03127 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = a[0]

def gcd(x,y):
    d = 0
    if max(x,y) == x:
        x,y = y,x
    while True:
        if y%x == 0:
            return x
        else:
            d = y%x
            y,x = x,d

for i in range(1,len(a)):
  ans = gcd(ans,a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
n = int(input())
a = list(map(int,input().split()))
ans = a[0]

for i in range(1,len(a)):
  ans =fraction.gcd(ans,a[i])
print(ans)
Problem p03242 (python)

Fixed submission:
print(1110 - int(input()))

Buggy submission (verdict: Runtime Error):
print(1110 - int(input())
Problem p02987 (python)

Fixed submission:
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2 and len(S2) == 2:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    ezxt()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2 and len(S2) == 2:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
if len(S.strip(A)) == len(S.strip(B)) and len(S.strip(C)) == len(S.sript(D)):
    print("Yes")
else:
    print("No")
Problem p03835 (python)

Fixed submission:
K , S = map(int, input().split())
x , y , z , cnt = 0 , 0 , 0 , 0
A = K + 1
if K * 3 == S:
    cnt = 1
else :
    for i in range(A):
        for j in range(A):
            if  S - (i + j) <= K :
                if 0 <= S - (i + j): 
                    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
    s = input()
    print(s.replace(',', ' '))
Problem p03013 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

if N == 1:
    print(1)
    sys.exit()

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
mod = 1000000007

B = ['.'] * (n + 1)
for a in A:
    B[a] = '#'
    
dp = [0] * (n + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, n + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(1 if n == 1 else dp[-1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
dp[1] = 1
dp[2] = 2
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])
Problem p03053 (python)

Fixed submission:
from collections import deque
 
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
 
que = deque()
INF = float('inf')
dx = [1, 0, -1, 0]
dy = [0, 1, 0 , -1]            
D = [[INF] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            que.append([i, j])
            D[i][j] = 0
                       
def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and A[nx][ny] != '#' and D[nx][ny] == INF:
                que.append([nx, ny])
                D[nx][ny] = D[p[0]][p[1]] + 1
    
bfs()

ans = 0
for i in range(H):
    for j in range(W):
        tmp = D[i][j]
        ans = max(ans, tmp)
        
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
 
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
 
que = deque()
INF = float('inf')
dx = [1, 0, -1, 0]
dy = [0, 1, 0 , -1]            
D = [[INF] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            que.append([i, j])
            D[i][j] = 0
                       
def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and A[nx][ny] != '#' and D[nx][ny] == INF:
                que.append([nx, ny])
                D[nx][ny] = D[p[0]][p[1]] + 1
    
bfs()

ans = 0
for i in range(H):
    for j in range(W):
        tmp = D[i][j]
        ans = max(ans, tmp)
        
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
 
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
 
INF = float('inf')
dx = [1, 0, -1, 0]
dy = [0, 1, 0 , -1]
 
def bfs(i, j):
    D = [[INF] * W for i in range(H)]
    que = deque()
    que.append([i, j])
    D[i][j] = 0
    
    while que != []:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and A[nx][ny] != '#' and D[nx][ny] == INF:
                que.append([nx, ny])
                D[nx][ny] = D[p[0]][p[1]] + 1
            elif 0 <= nx < H and 0 <= ny < W and A[nx][ny] == '#':
                D[nx][ny] = D[p[0]][p[1]] + 1
                return D[nx][ny]
              
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == '.':
            tmp = bfs(i, j)
            ans = max(ans, tmp)
            
print(ans)
Problem p03208 (python)

Fixed submission:
n, k = map(int, input().split())
hs = []
diff = []

for i in range(n):
    h = int(input())
    hs.append(h)

hs.sort()

for i in range(n - k + 1):
    diff.append(hs[i + k - 1] - hs[i])
    
print(min(diff))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = []
D = []

for i in range(n):
    A.append(int(input()))

A.sort(reverse=True)
    
for i in range(k):
    diff = A[i] - A[i + k -1]
    D.append(diff)
    
print(min(D))
Problem p03209 (python)

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

a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
    
def f(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
    
print(f(n, x))

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
ans = 'p'

for i in range(n):
    ans = 'b{}p{}b'.format(ans, ans)

print(ans[-x:].count('p'))
Problem p03307 (python)

Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

n = int(input())
print((n * 2) // gcd(n, 2))

Buggy submission (verdict: Runtime Error):
import fractions
a = int(input())
print((a * 2 ) // math.gcd(a, 2))

Buggy submission (verdict: Runtime Error):
import math
a = int(input())
print((a * 2 ) // math.gcd(a, 2))
Problem p03745 (python)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

if n == 1:
    cnt = 1
else:
    if A[0] < A[1]:
        flag = 1
    elif A[0] > A[1]:
        flag = -1
    else:
        flag = 0
    
    cnt = 1
    x = A[1]
    for i in range(2, n):
        if flag == 1:
            if x <= A[i]:
                pass
            else:
                cnt += 1
                flag = 0
                
        elif flag == -1:
            if x < A[i]:
                cnt += 1
                flag = 0
            else:
                pass
            
        else:
            if x < A[i]:
                flag = 1
            elif x > A[i]:
                flag = -1
            else:
                flag = 0
        #print('x', x, 'A[i]', A[i], 'flag', flag, 'cnt', cnt)
        x = A[i]
    
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

if A[0] < A[1]:
    flag = 1
elif A[0] > A[1]:
    flag = -1
else:
    flag = 0
    
cnt = 1
x = A[1]
for i in range(2, n):
    if flag == 1:
        if x <= A[i]:
            pass
        else:
            cnt += 1
            flag = 0
    if flag == -1:
        if x < A[i]:
            cnt += 1
            flag = 0
        else:
            pass
    else:
        if x < A[i]:
            flag = 1
        elif x > A[i]:
            flag = -1
        else:
            flag = 0
    x = A[i]
    
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

if A[0] <= A[1]:
    flag = 1
else:
    flag = -1
cnt = 1
x = A[1]
for i in range(2, n):
    if flag == 1:
        if x <= A[i]:
            pass
        else:
            cnt += 1
            flag = 0
    if flag == -1:
        if x < A[i]:
            cnt += 1
            flag = 0
        else:
            pass
    else:
        if x < A[i]:
            flag = 1
        elif x > A[i]:
            flag = -1
        else:
            flag = 0
    x = A[i]
    
print(cnt)
Problem p02990 (python)

Fixed submission:
import math

def conb(x,y):
    if x < y:
        return 0
    else:
        return (math.factorial(x) // math.factorial(x - y)) // math.factorial(y)


n,k = map(int,input().split())

for i in range(1,k + 1):
    print(conb(n - k + 1,i) * conb(k - 1,i - 1) % 1000000007)

Buggy submission (verdict: Runtime Error):
import math

def conb(x,y):
    return (math.factorial(x) // math.factorial(x - y)) // math.factorial(y)


n,k = map(int,input().split())

for i in range(1,k + 1):
    print(conb(n - k + 1,i) * conb(k - 1,i - 1) % 1000000007)
Problem p02951 (python)

Fixed submission:
def main():

    i = list(map(int, input().split()))
    a = i[0]
    b = i[1]
    c = i[2]

    if  not (1 <= b and b <= a and a <= 20 and 1 <= c and c <= 20):      
        return

    if c >= a - b:
        k = c - a + b
    else:
        k = 0

    print(k)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    if(1 <= b and b <= a and a <= 20 and 1 <= c and c <= 20): 
        i = list(map(int, input().split()))
        a = i[0]
        b = i[1]
        c = i[2]

        

        k = c - a + b

        print(k)


if __name__ == "__main__":
    main()
Problem p03631 (python)

Fixed submission:
def main():
    i = list(map(int, input().split()))
    n = i[0]

    if n < 100 or 999 < n or isinstance(n, int) == False:
        return

    if(str(n)[0] == str(n)[2]):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    i = list(map(int, input().split()))
    n = i[0]

    if n < 100 or 999 < n or isinstance(n, int) == False:
        return

    if(str(n[0]) == str(n[2])):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()
Problem p03033 (python)

Fixed submission:
import bisect
import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
STX=[tuple(map(int,input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2])
ans=[-1]*Q
jump=[-1]*Q
D=[int(input()) for i in range(Q)]
for s,t,x in STX:
    l=bisect.bisect_left(D,s-x)
    r=bisect.bisect_left(D,t-x)
    while(l<r):
        k=jump[l]
        if k==-1:
            ans[l]=x
            jump[l]=r
            l+=1
        else:
            l=k
for i in range(Q):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
import bisect
N,Q=map(int,input().split())
STX=[list(map(int,input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2])
ans=[-1]*Q
jump=[-1]*Q
D=[int(input()) for i in range(Q)]
for s,t,x in STX:
    l=bisect.bisect_left(D,s-x)
    r=bisect.bisect_left(D,t-x)
    while(l<r):
        k=jump[l]
        if k==-1:
            ans[l]=x
            jump[l]=r
            l+=1
        else:
            l=jump[k]
for i in range(Q):
    print(ans[i])