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

Fixed submission:
import math

n, m=map(int, input().split())
t = {}
a = int(math.sqrt(m))

s=0

line = [2, 3] + [i%2*2 + i//2 * 6 + 5 for i in range(a)]
# line = [2] + list(range(3, m+2, 2))

for i in line:
# for i in range(2, m+2, 2):
#     print(i)
    cnt = 0
    while m%i==0:
        m=m//i
        cnt += 1

    if cnt>0:
        t[i]=cnt

    if m==1:
        break

if m!=1:
    t[m]=1

def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 

out=1
for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
#     out = out%(1000000007)
print(out%(1000000007))

Buggy submission (verdict: Runtime Error):
import math

n, m=map(int, input().split())
t = {}
# a = int(math.sqrt(m))

s=0

# line = [2, 3] + [i%2*2 + i//2 * 6 + 5 for i in range(a)] + [m]
line = [2] + list(range(3, m+2, 2))

for i in line:
# for i in range(2, m+2, 2):
#     print(i)
    cnt = 0
    while m%i==0:
        m=m//i
        cnt += 1

    if cnt>0:
        t[i]=cnt

    if m==1:
        break

def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 

out=1
for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
#     out = out%(1000000007)
print(out%(1000000007))

Buggy submission (verdict: Runtime Error):
import math
s=0
n, m=map(int, input().split())

t = {}

while s==0:
    for i in range(2,m+1):
        if m%i==0:
            m=m//i
            if m==1:
                s=1
            if i in t.keys():
                t[i]+=1
            else:
                t[i]=1
            break
out=1
for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
print(out%(1000000007))
Problem p03286 (python)

Fixed submission:
N=int(input())

lr = ""
i=1

if N==0:
    print(0)

else:    
    while N!=0:
        if N%(2**i)!=0:
            lr = "1" + lr
            N = N - (-2)**(i-1)
        else:
            lr = "0" + lr

        i+=1

    print(lr)

Buggy submission (verdict: Runtime Error):
N = int(input())
ts = fetch_Hosu(N)

le = len(ts)
numl = [0]* 15

for i in range(15):
    tmp = int(ts[2*i+1:2*i+3])
    
    if tmp ==1:
        numl[i]  += 11
    elif tmp ==11:
        if i>1:
            numl[i-1]  += 11
        numl[i]  += 1
    else:
        numl[i]  += tmp
    
#     print(numl)

# print(numl)

for j in range(len(numl)):
    if numl[14-j]==21:
        numl[13-j]  += 11
        numl[14-j]  = 1

    if numl[14-j]==12:
        numl[14-j]  = 0
    
    if numl[14-j]==22:
        numl[14-j]  = 10
    
# print(numl)
outttt = ["{0:02d}".format(i) for i in numl]
# print(outttt)
ttt=""
for k in range(len(outttt)):
    ttt += outttt[k]

ttt += ts[-1]

if int(ttt)==0:
    print(0)
else:
    tetee = str(ttt)
    tpl = tetee[2:].find("1")
    print(tetee[tpl+2:])

Buggy submission (verdict: Runtime Error):
N = int(input())
ts = fetch_Hosu(N)

le = len(ts)
numl = [0]* 15

for i in range(15):
    tmp = int(ts[2*i+1:2*i+3])
    
    if tmp ==1:
        numl[i]  += 11
    elif tmp ==11:
        if i>1:
            numl[i-1]  += 11
        numl[i]  += 1
    else:
        numl[i]  += tmp
    
#     print(numl)

# print(numl)

for j in range(len(numl)):
    if numl[14-j]==21:
        numl[13-j]  += 11
        numl[14-j]  = 1

    if numl[14-j]==12:
        numl[14-j]  = 0
    
    if numl[14-j]==22:
        numl[14-j]  = 10
    
# print(numl)
outttt = ["{0:02d}".format(i) for i in numl]
# print(outttt)
ttt=""
for k in range(len(outttt)):
    ttt += outttt[k]

ttt += ts[-1]

# print(ttt)
tetee = str(ttt)
tpl = tetee[2:].find("1")
print(tetee[tpl+2:])
Problem p02777 (python)

Fixed submission:
s, t = map(str, input().split())
a, b = map(int,input().split())
u = input()

if u==s:
    print(a-1, b)

else:
    print(a, b-1)

Buggy submission (verdict: Runtime Error):
s,t=map(str,input().spilt())
a,b=map(int,input().split())
u=input()
if u==s:
  print(str(a-1),str(b))
else:
  print(str(a),str(b-1))

Buggy submission (verdict: Runtime Error):
s,t=map(str,input().spilt())
a,b=map(int,input().split())
u=input()
if u==s:
  print(a-1,b)
else:
  print(a,b-1)

Buggy submission (verdict: Runtime Error):
s,t=map(str,input().spilt())
a,b=map(int,input().split())
u=input()
if u==s:
  print(s-1,t)
else:
  print(s,t-1)
Problem p02881 (python)

Fixed submission:
import sys
n=int(input())
L=[]
for i in range(1,int(n**(1/2))+1):
    if n//i == n/i:
        L.append(n//i+i-2)
print(min(L))

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
L=[]
for i in range(1,int(n**(1/2))):
    if n//i == n/i:
        L.append(n//i+i-2)
print(min(L))
Problem p02891 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    A = set(list(S))
    if len(S) == 1:
        print(K // 2)
        return

    elif len(A) == 1:
        if len(S) % 2 == 1:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
        else:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
    else:
        for s in S:
            if s == last:
                a += 1
                last = ""
            else:
                last = s
        if S[0] != S[-1]:
            print(a * K)
        elif len(S) == 2:
            print(a * K)
        else:
            x = 0
            y = 0
            for i in range(len(S) // 2):
                if S[i] == S[0]:
                    x += 1
            for j in range(len(S) // 2):
                if S[len(S) - j - 1] == S[-1]:
                    y += 1

            if x % 2 == 1 and y % 2 == 1:
                b = 1
            else:
                b = 0

            print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    if len(S) == 1:
        print(K // 2)
        return
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[0:2] == S[-2:] and len(S) > 2:
            k = 0
            while True:
                if S[k] == S[len(S) - k - 1]:
                    k += 1
                else:
                    break
            b = k % 2
        else:
            if S[1] == S[0] or S[-2] == S[0]:
                b = 0
            else:
                b = 1

    print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[-2] == S[0] or S[1] == S[0]:
            b = 0
        else:
            b = 1

    print(a * K + b * (K - 1))


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

Fixed submission:
import sys
import queue


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7


def main():
    L = list(input())

    pow = [0] * (len(L) + 1)
    pow[0] = 1
    for i in range(1, len(L) + 1):
        pow[i] = pow[i - 1] * 3 % MOD
    N = len(L)
    if L[-1] == "0":
        answer = 1
    else:
        answer = 3
    for i in range(1, N):
        if L[N - i - 1] == "1":
            answer = answer * 2 + pow[i]
            answer %= MOD
        else:
            continue
    print(answer)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


MOD = 10 ** 9 + 7


def main():
    L = list(input())

    def cnt(s):
        if len(s) == 1:
            if s[0] == "1":
                return 3
            else:
                return 1
        if s[0] == "0":
            return cnt(s[1:]) % MOD
        else:
            return (cnt(s[1:]) % MOD) * 2 + 3 ** (len(s) - 1) % MOD

    answer = cnt(L) % MOD

    print(answer)


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

Fixed submission:
N=int(input())
H=[int(i) for i in input().split()]
hotel=0
for i in range(N):
    count=0
    for k in range(i):
        if H[k]<=H[i]:
            count+=1
        continue
            
    if count==i:
        hotel+=1


print(hotel)

Buggy submission (verdict: Runtime Error):
N=int(input())
H=[int(i) for i in input().split()]
hotel=0
for i in range(N):
    count=0
    for k in range(i):
        if H[k]<=H[i]:
            count+=1
        continue
            
    if count==i:5
        hotel+=1


print(hotel)
Problem p03127 (python)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
while len(a)>1:
    c=[]
    d=min(a)
    for i in range(len(a)):
        if a[i]!=d:
            div=a[i]%d
            if div!=0:
                c.append(div)
    c.append(d)        
    a=c
print(a[0])

Buggy submission (verdict: Runtime Error):
import sys
import math


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = A[0]
    B = set()
    for i in range(1, N):
        g = math.gcd(A[i], a)
        if g == 1:
            B.add(1)
        elif g == a:
            continue
        else:
            B.add(g)
    if len(B) == 0:
        print(a)
    else:
        print(min(B))


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

Fixed submission:
import math
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
print(1+math.ceil((n-k)/(k-1)))

Buggy submission (verdict: Runtime Error):
import math
n.k=map(int,input().split())
A=[int(i) for i in input().split()]
print(math.ceil(n/k))
Problem p03803 (python)

Fixed submission:
A,B=map(int,input().split())
N=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a=N.index(A)
b=N.index(B)
if a<b:
    print('Bob')
elif a>b:
    print('Alice')
else:
    print('Draw')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
N=[2,3,4,5,6,7,8,9,10,11,12,13,1]
if N.index(A)<N.index(B):
    print('Bob')
elif N.index(A)>N.index(B):
    print('Alice')
else N.index(A)==N.index(B):
    print('Draw')
Problem p03805 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
n,m=map(int,input().split())
bra=[set() for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    for e in bra[a]:
        if visit[e]==0:
            visit[e]=1
#            print(visit)
            dfs(e,visit)
            visit[e]=0  
    return 
dfs(0,visit)
print(len(cnt))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
n,m=map(int,input().split())
bra=[set() for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    else:
        for e in bra[a]:
            if visit[e]==0:
                visit[e]=1
#                print(visit)
                dfs(e,visit)
                visit[e]=0   
dfs(0,visit)
print(len(cnt))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
n,m=map(int,input().split())
bra=[set() for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    else:
        for e in bra[a]:
            if visit[e]==0:
                visit[e]=1
#                print(visit)
                dfs(e,visit)
                visit[e]=0   
dfs(0,visit)
print(sum(cnt))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
bra=[set() for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    else:
        for e in bra[a]:
            if visit[e]==0:
                visit[e]=1
#                print(visit)
                dfs(e,visit)
                visit[e]=0

                
dfs(0,visit)
print(sum(cnt))
Problem p03835 (python)

Fixed submission:
K,S=map(int,input().split())
if S<=K:
    print((S+2)*(S+1)//2)
elif S<=2*K:
    m=0
    for i in range(K+1):
        s=S-i
        if s<=K:
            m+=s+1
            
        else:
            c=s-K
            a=s-2*c
            m+=a+1         
    print(m)

else:
    s=3*K-S
    print((s+2)*(s+1)//2)

Buggy submission (verdict: Runtime Error):
K,S=map(int,input().split())
if S<=K:
    print((S+2)*(S+1)//2)
elif S<=2*K:
    s=S-math.ceil(K/3)*3
    print((s+2)*(s+1)//2)
else:
    s=3*K-S
    print((s+2)*(s+1)//2)
Problem p02679 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if (a, b) in [(1, 0), (0, 1)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) % MOD
print((ans + MOD - 1) % MOD)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
for i in range(N):
    a, b = MI()
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
print((ans + MOD - 1) % MOD)
Problem p02777 (python)

Fixed submission:
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


S, T = input().split()
A, B = MI()
U = input()
if U == S:
    A -= 1
elif U == T:
    B -= 1
print(A, B)

Buggy submission (verdict: Runtime Error):
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


S, T = input().split()
A, B = MI()
U = input()
if U == S:
    S -= 1
elif U == T:
    B -= 1
print(A, B)
Problem p02987 (python)

Fixed submission:
S = input()

if S[0] == S[1] and S[2] == S[3] and S[0] != S[3]:
    print("Yes")
elif S[0] == S[2] and S[1] == S[3] and S[0] != S[1]:
    print("Yes")
elif S[0] == S[3] and S[2] == S[1] and S[0] != S[1]:
    print("Yes")
else:
    print("No")

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

if S[0] == S[1] and S[2] == S[3] and S[0] != S[3]:
    print("Yes")
elif S[0] == S[2] and S[1] == S[4] and S[0] != S[1]:
    print("Yes")
elif S[0] == S[3] and S[2] == S[1] and S[0] != S[1]:
    print("Yes")
else:
    print("No")

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

if S[0] == S[1] and S[2] == S[3] and S[0] != S[3]:
    print("Yes")
    exit(0)
if S[0] == S[2] and S[1] == S[4] and S[0] != S[1]:
    print("Yes")
    exit(0)
if S[0] == S[3] and S[2] == S[1] and S[0] != S[1]:
    print("Yes")
    exit(0)
print("No")
Problem p02989 (python)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
D.sort()

ans = D[int(N / 2)] - D[int((N / 2) - 1)]
print(ans)

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

count = 0
cur = 0
for i in range(10**5 + 1):
    if cur == N / 2:
        count += 1
    if cur > N / 2:
        break
    if D[cur] < i and cur < N:
        cur += 1
        while D[cur - 1] == D[cur]:
            cur += 1
print(count)

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

count = 0
cur = 0
for i in range(10**5 + 1):
    if cur == N / 2:
        count += 1
    if cur > N / 2:
        break
    if D[cur] < i:
        cur += 1
        while D[cur - 1] == D[cur]:
            cur += 1
print(count)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
broken = set()
for _ in range(M):
    a = int(input())
    broken.add(a)

INF = 10 ** 9 + 7

memo = [None for _ in range(N + 1)]
memo[0] = 1
memo[1] = 0 if 1 in broken else 1
for i in range(2, N + 1):
    if i in broken:
        memo[i] = 0
    else:
        memo[i] = (memo[i - 2] + memo[i - 1]) % INF

print(memo[N])

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

INF = 10 ** 9 + 7

memo = [None for _ in range(N + 1)]
if 1 not in broken:
    memo[1] = 1
else:
    memo[1] = 0
if 2 not in broken:
    if 1 not in broken:
        memo[2] = 2
    else:
        memo[2] = 1
else:
    memo[2] = 0
for i in range(3, N + 1):
    if i in broken:
        memo[i] = 0
    else:
        memo[i] = (memo[i - 2] + memo[i - 1])

print(memo[N] % INF)

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

INF = 10 ** 9 + 7

memo = [None for _ in range(N + 1)]
if 1 not in broken:
    memo[1] = 1
else:
    memo[1] = 0
if 2 not in broken:
    if 1 not in broken:
        memo[2] = 2
    else:
        memo[2] = 1
else:
    memo[2] = 0
for i in range(3, N + 1):
    if i in broken:
        memo[i] = 0
    else:
        memo[i] = (memo[i - 2] + memo[i - 1]) % INF

print(memo[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
broken = [False for _ in range(10 **5)]
for _ in range(M):
    a = int(input())
    broken[a] = True

INF = 1000000007

memo = [None for _ in range(N + 1)]
if not broken[1]:
    memo[1] = 1
else:
    memo[1] = 0
if not broken[2]:
    memo[2] = 2
else:
    memo[2] = 0
for i in range(3, N + 1):
    if broken[i]:
        memo[i] = 0
        continue
    memo[i] = (memo[i - 2] + memo[i - 1]) % INF

print(memo[N])
Problem p03033 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


# 区間updateと要素クエリ
class SegmentTree(object):

    def __init__(self, n, ele, segfun):
        self.ide_ele = ele
        self.segfun = segfun
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)

    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret

N, Q = MI()
STX = [tuple(MI()) for _ in range(N)]
D = [I() for _ in range(Q)]

seg = SegmentTree(Q, INF, min)
for S, T, X in STX:
    # [S - X, T - X) に出発する人(l番目の人からr番目の人まで)が影響を受ける
    l = bisect_left(D, S - X)
    r = bisect_left(D, T - X)
    seg.update(l, r, X)

for i in range(Q):
    ans = seg.query(i)
    if ans == INF:
        print(-1)
    else:
        print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(300000)
from heapq import heappush, heappop
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, Q = MI()
events = list()
for _ in range(N):
    S, T, X = MI()
    # [S - X, T - X) に出発する人が影響を受ける
    events.append((S - X, 1, X))
    events.append((T - X, 2, X))
for i, d in enumerate([I() for _ in range(Q)]):
    events.append((d, 3, i))

ans = [0] * Q
events.sort()
blocks = defaultdict(int)
blockq = list()
for e1, type, e3 in events:
    if type == 1:
        X = e3
        blocks[X] += 1
        heappush(blockq, X)
    elif type == 2:
        X = e3
        if blocks[X] > 1:
            blocks[X] -= 1
        else:
            del blocks[X]
    else:
        i = e3
        if len(blocks) == 0:
            ans[i] = -1
        else:
            while True:
                block = heappop(blockq)
                if block in blocks:
                    break
            ans[i] = block

for a in ans:
    print(a)