Harryxun/stf_run huggingface dataset:
import math
import functools import reduce

N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[inputcities[i]-X for i in range(N)]
D = reduce(math.gcd, cities)
print(D)

### FIXED CODE ###

def gcd(a,b):
    if a < b:
        a,b = b,a
    if a % b == 0:
        return b
    else:
        return gcd(b,(a % b))
 
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
cities.sort()
D=cities[0]
for i in range(N):
  D=gcd(D,cities[i])
print(D)
s=input()
t=input()
dp=[[-1]*(len(t)+1) for x in range(len(s)+1)]
arr = ""
def func(i,j):
    if i>=(len(s)) or j>=(len(t)):
        dp[i][j]=0
        return dp[i][j]
    if dp[i][j]!=-1:
        return dp[i][j]
    if s[i]==t[j]:
        dp[i][j] = func(i+1,j+1)+1
        return dp[i][j]
    dp[i][j] = max(func(i+1,j),func(i,j+1))
    return dp[i][j]
l=func(0,0)

i,j=0,0
while len(arr)!=l:
    if s[i] == t[j]:
        arr=arr+s[i]
        i+=1
        j+=1
    else:
        if dp[i+1][j]>=dp[i][j+1]:
            i+=1
        else:
            j+=1
print(arr)


# for i in range(len(s)-1,-1,-1):
#     for j in range(len(t)-1,-1,-1):
#         if s[i] == t[j]:
#             dp[i][j] = dp[i+1][j+1] + 1
#         else:
#             dp[i][j] = max(dp[i+1][j],dp[i][j+1])
# l=dp[0][0]

### FIXED CODE ###

s=input()
t=input()

dp=[[-1]*(len(t)+1) for x in range(len(s)+1)]
arr = ""
for i in range(len(s),-1,-1):
    for j in range(len(t),-1,-1):
        if i>=(len(s)) or j>=(len(t)):
            dp[i][j] = 0
        else:
            if s[i] == t[j]:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = max(dp[i+1][j],dp[i][j+1])

l=dp[0][0]
i,j=0,0
while len(arr)!=l:
    if s[i] == t[j]:
        arr=arr+s[i]
        i+=1
        j+=1
    else:
        if dp[i+1][j]>=dp[i][j+1]:
            i+=1
        else:
            j+=1

print(arr)



# def func(i,j):
    # if i>=(len(s)) or j>=(len(t)):
    #     return 0
    # if dp[i][j]!=-1:
    #     return dp[i][j]
    # if s[i]==t[j]:
    #     dp[i][j] = func(i+1,j+1)+1
    #     return dp[i][j]
    # if s[i]!=t[j]:
    #     dp[i][j] = max(func(i+1,j),func(i,j+1))
    #     return dp[i][j]
# l=func(0,0)
a,b=map(int,input().split())
c=1
d=2
e=3
if a!=3 and b!=3:
	print(e)
elif a!=2 and b!=2:
	print(d)
else:
	print(c)

### FIXED CODE ###

a=int(input())
b=int(input())
if a!=3 and b!=3:
  print(3)
elif a!=2 and b!=2:
  print(2)
else:
  print(1)
while(1):
  count = int(raw_input())
  if count == 0: break
  previous_cube = [1, 2, 3, 4, 5, 6]
  operation = {'North':[2, 6, 3, 4, 1, 5], 'East':[4, 2, 1, 6, 5, 3], 'West': [3, 2, 6, 1, 5, 4], 'South':[5, 1, 3, 4, 6, 2], 'Right':[1, 3, 5, 2, 4, 6], 'Left':[1, 4, 2, 5, 3, 6]}
  sum = 1
  for i in xrange(count):
    new_cube = []
    for e in xrange(5):
      new_cube.append(previous_cube[operation[str(raw_input().strip()][e]])
    sum += new_cube[0]
    previous_cube = new_cube
  print sum

### FIXED CODE ###

while 1:
  n = input()
  if n == 0:  break
  d = range(1, 7)
  ans = 1
  for i in range(n):
    c = raw_input()[0]
    if c == 'N': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans
maxx = 2**29
    ans = 0
    for _ in range(int(input())):
        a, b = map(int, input().split(' '))
        if b < maxx:
            maxx = b
            ans = a
    print(ans + maxx)

### FIXED CODE ###

al = []
bl = []
for _ in range(int(input())):
    a, b = map(int, input().split(' '))
    al.append(a)
    bl.append(b)
print(max(al) + min(bl))
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**10
for i in range(n):
	K=k
	score=0
	pre_score=0
	visit=[0]*n
	now=i
	cnt=0
	while visit[now]==0:
		cnt+=1
		visit[now]=1
		now=p[now]-1
		pre_score+=c[now]
		if cnt!=1:
			score=max(score,pre_score)
		else:
			score=pre_score
		K-=1
		if K==0:
			break
	ans=max(score,ans)
	if K==0:
		print(2/0)
		continue
	loop=[0]
	NOW=now
	#NOWはループ元
	for j in range(n):
		now=p[now]-1
		loop.append(loop[-1]+c[now])
		if NOW==now:
			break
	pre_score+=max(loop[-1],0)*(K//(len(loop)-1))
	K%=(len(loop)-1)
	pre_score+=max(loop[:K+1])
	score=max(score,pre_score)
	ans=max(ans,score)
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**10
for i in range(n):
	loop=[0]
	now=i
	while True:
		now=p[now]-1
		loop.append(loop[-1]+c[now])
		if now==i:
			break
	L=len(loop)-1
	if k<=L:
		score=max(loop[1:k+1])
		ans=max(score,ans)
	else:
		score=max(loop[-1],0)*(k//L-1)
		ans=max(ans,score)
		for j in range(k%L+L):
			score+=loop[j%L+1]-loop[j%L]
			ans=max(score,ans)
print(ans)
n, h, d = map(int, input().split())
MOD = 10 ** 9 + 7


if d != 1:
    print(re)

fact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = fact[i] * (i + 1)
    fact[i + 1] %= MOD

# fact_sum = fact[1] + fact[2] + ... + fact[n]
fact_sum = 0
for i in range(1, n + 1):
    fact_sum += fact[i]
    fact_sum %= MOD

dp = [0] * (h + 1)
dp[0] = 1
for i in range(h):
    dp[i + 1] = dp[i] * fact_sum
    dp[i + 1] %= MOD

print((dp[-1] - dp[-2] * (fact_sum - fact[-1])) % MOD)

### FIXED CODE ###

n, h, d = map(int, input().split())
MOD = 10 ** 9 + 7


fact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = fact[i] * (i + 1)
    fact[i + 1] %= MOD

# fact_sum = fact[1] + fact[2] + ... + fact[n]
fact_sum = 0
for i in range(1, n + 1):
    fact_sum += fact[i]
    fact_sum %= MOD

dp = [0] * (h + 1)
ru = [0] * (h + 2)
dp[0] = 1
ru[1] = 1
for i in range(h):
    l = max(i + 1 - d, 0)
    dp[i + 1] += (ru[i + 1] - ru[l]) * fact_sum
    dp[i + 1] %= MOD
    ru[i + 2] = ru[i + 1] + dp[i + 1]
    ru[i + 2] %= MOD

print((dp[-1] * fact[n] * pow(fact_sum, MOD - 2, MOD)) % MOD)
#xi以外の場所にコマを置く理由がない
#コマを置くというのは担当区間の分割
#xi x(i + 1)の間隔を無視するということ
#距離がでかいところから分割してやれば良い
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
l = [X[i + 1] - X[i] for i in range(M - 1)]
l.sort()
for _ in range(N - 1):
  l.pop()
print(sum(l))

### FIXED CODE ###

#xi以外の場所にコマを置く理由がない
#コマを置くというのは担当区間の分割
#xi x(i + 1)の間隔を無視するということ
#距離がでかいところから分割してやれば良い
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
l = [X[i + 1] - X[i] for i in range(M - 1)]
l.sort()
for _ in range(N - 1):
  if len(l):
    l.pop()
print(sum(l))
mport sys

a = []
for line in sys.stdin:
    a.append(line)

for n in a:
    inl=n.split()
    num1=inl[0]
    check=1
    list=[]
    while check<=math.sqrt(num1):
        if num1%check==0:
            list.append(check)
        check+=1
    list.sort()
    list.reverse()
    num2=inl[1]
    for i in list:
        if num2%i==0:
            gud=i
            break
    lcm==num1*num2/gud
    print gud,lcm

### FIXED CODE ###

import sys
import math

a = []
for line in sys.stdin:
    a.append(line)

for n in a:
    inl=n.split()
    num1=int(inl[0])
    check=1
    list=[]
    while check<=math.sqrt(num1):
        if num1%check==0:
            list.append(check)
            list.append(num1/check)
        check+=1
    list.sort()
    list.reverse()
    num2=int(inl[1])
    for i in list:
        if num2%i==0:
            gud=i
            break
    lcm=num1*num2/gud
    print gud,lcm
OK=[]
S,T=input().split()
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if s[i]!=t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

A=[input() for i in range(2)]
S=A[0]
T=A[1]
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if not s[i]==t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")
import math
S = input()
A = int(S[0])
B = int(S[1:])
n = math.ceil(B/A)
print(n, " power strips, each with", A , "sockets, extend the socket into", A*n, "empty sockets.")

### FIXED CODE ###

input1 = input()
x = []
y=[]
check=0

for i in input1:
    if i!=" " and check==0:
        x.append(i)
    elif i==" ":
        check=1
    elif i!=" " and check==1:
        check==1
        y.append(i)
xstring=''.join(x)
ystring=''.join(y)

xint=int(xstring)
yint=int(ystring)

if yint==1:
    print(0)
else:
    cnt=0
    while ((xint-1)*(cnt))+xint<yint:
        cnt=cnt+1
    cnt=cnt+1
    print(cnt)
N = int(input)
A = int(input)

if N%500 <= A:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
A = int(input())

if N%500 <= A:
  print("Yes")
else:
  print("No")
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
answer_set = {}
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == N:
            continue
        else:
            answer_set.add((i, j))

print(len(answer_set))
for x in answer_set:
    print(*x)



### FIXED CODE ###

import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
answer_list = []
pair = N if N&1 else N+1
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == pair:
            continue
        else:
            answer_list.append((i, j))

print(len(answer_list))
for x in answer_list:
    print(*x)
n=int(input())
A = list(map(int, input().split
c=collections.Counter(A)
if c=len(A):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

import collections
n=int(input())
A = list(map(int, input().split()))
c=collections.Counter(A)
if len(c)==len(A):
    print("YES")
else:
    print("NO")
a, b ,c = [int(i) for i in input().split()]

a for i in(1, 10001):
b for i in(1, 10001):
c = a == b

    
    

### FIXED CODE ###

a, b ,c = [int(i) for i in input().split()]

total = 0
for d in range(a, b + 1):
    if c % d == 0:
        total += 1

print(total)
data=set([input() for i in range(3)])
if len(data)==1:
  print("NO")
else:
  print("YES")

### FIXED CODE ###

a, b, c = input()
s=set([a, b, c])
if len(s)==1:
  print("No")
else:
  print("Yes")
x=int(input())
for a in range(-100,101):
	b5=a**5-x
	if int(b**0.2)**5==b:
		print(a,int(b**0.2))
		break
		

### FIXED CODE ###

x=int(input())
for a in range(-200,201):
	f=False
	for b in range(-201,201):
		if a**5-b**5==x:
			print(a,b)
			f=True
			break
	if f:break
a=int(input("a"))
b=int(input("b"))
c=(a*b)%2
if c=0:
  print("Even")
else:
  print("Odd")


### FIXED CODE ###

a, b=map(int, input().split())
c=(a*b)%2
if c==0:
  print("Even")
else:
  print("Odd")
A, B = map(int, input().split())
print(max(A+B,
          A-B,
          A*X))

### FIXED CODE ###

A, B = map(int, input().split())
print(max(A+B,
          A-B,
          A*B))
import sys, bisect

def main():
    _,M,*A = map(int, open(0).read().split())

    A.sort()
    i = M
    while i > 0:
        a = int(A.pop() / 2)
        i-=1
        while a >= A[-1] and i > 0:
            a = int(a / 2)
            i-=1
        bisect.insort_left(A,a)

    print(sum(A))

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
from heapq import heappush, heappop

def main():
    _,M,*A = map(int, open(0).read().split())

    A = [-x for x in A] # reverse max to min
    A.sort()

    for _ in range(M):
        a = int(heappop(A) / 2)
        heappush(A, a)
    print(-sum(A))

if __name__=='__main__':
    main()
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N, *XY = map(int,open(0).read().split())
MOD = 10**9 + 7

neighbor = [[] for _ in range(N)]
for x,y in zip(*[iter(XY)]*2):
    neighbor[x-1] += y-1
    neighbor[y-1] += x-1

parent = {0}

def dp(node):
    black_output = white_output = 1
    for child in neighbor[node]:
        if child in parent:
            continue
        else:
            parent.add(child)
            tmp_black, tmp_white = dp(child)
            black_output *= tmp_white
            white_output *= tmp_black + tmp_white
    black_output %= MOD
    white_output %= MOD
    return black_output, white_output

print(sum(dp(0)) % MOD)

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N, *XY = map(int,open(0).read().split())
MOD = 10**9 + 7

neighbor = [[] for _ in range(N)]
for x,y in zip(*[iter(XY)]*2):
    neighbor[x-1] += y-1,
    neighbor[y-1] += x-1,

parent = {0}

def dp(node):
    black_output = white_output = 1
    for child in neighbor[node]:
        if child in parent:
            continue
        else:
            parent.add(child)
            tmp_black, tmp_white = dp(child)
            black_output *= tmp_white
            white_output *= tmp_black + tmp_white
    black_output %= MOD
    white_output %= MOD
    return black_output, white_output

print(sum(dp(0)) % MOD)
N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

# 各数字に必要なマッチの本数
num  = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    dp[num[a]] = 1

for i in range(1,N+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[N]):
    for a in A:
        if dp[N-num[a]] == dp[N]-1  and  N-num[a] >= 0:
            ans += str(a)
            N -= num[a]
            break

print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

# 各数字に必要なマッチの本数
num  = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1000)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    dp[num[a]] = 1

for i in range(1,N+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[N]):
    for a in A:
        if dp[N-num[a]] == dp[N]-1  and  N-num[a] >= 0:
            ans += str(a)
            N -= num[a]
            break

print(ans)
import sys
sys.setrecursionlimit(2000)

def dfs(i,j):
    for m in move:
        ni = i + m[0]
        nj = j + m[1]
        if ni < 0 or ni >= H or nj < 0 or nj >= W:
            continue
        if ch[ni][nj]:
            continue
        if X[i][j] == X[ni][nj]:
            continue
            
        ch[ni][nj] = 1
        K[(ni+nj)%2] += 1
        dfs(ni, nj)
        
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
ch = [[0] * W for _ in range(H)]
    
move = [[0,1], [0,-1], [1,0], [-1,0]]

K = [0, 0]
ans = 0
for i in range(H):
    for j in range(W):
        if ch[i][j] > 0:
            continue
        ch[i][j] = 1
        K = [0, 0]
        K[(i+j)%2] = 1
        dfs(i, j)
        ans += K[0] * K[1]
        
print(ans)



### FIXED CODE ###

H, W = map(int, input().split())

X = [[0] * W for i in range(H)]
G = [[0,0] for i in range(W*H)] 
L = [[-1] * W for i in range(H)] # Group ID

for i in range(H):
    s = input()
    for j in range(W):
        if (i+j) % 2 == 0:
            if s[j] == "#":
                X[i][j] = 1
        else:
            if s[j] != "#":
                X[i][j] = 1



g = -1
for i in range(H):
    for j in range(W):
        if L[i][j] < 0:
            g += 1
            L[i][j] = g
            post = [[i,j]]
            G[g][(i+j)%2] += 1
            while post:
                pre = post
                post = []
                for ggg in pre:
                    i0, j0 = ggg
                    if i0>0 and L[i0-1][j0] < 0 and X[i0][j0] == X[i0-1][j0]:
                        post.append([i0-1,j0])
                        L[i0-1][j0] = g
                        G[g][(i0+j0+1)%2] += 1
                    if i0<H-1 and L[i0+1][j0] < 0 and X[i0][j0] == X[i0+1][j0]:
                        post.append([i0+1,j0])
                        L[i0+1][j0] = g
                        G[g][(i0+j0+1)%2] += 1
                    if j0>0 and L[i0][j0-1] < 0 and X[i0][j0] == X[i0][j0-1]:
                        post.append([i0,j0-1])
                        L[i0][j0-1] = g
                        G[g][(i0+j0+1)%2] += 1
                    if j0<W-1 and L[i0][j0+1] < 0 and X[i0][j0] == X[i0][j0+1]:
                        post.append([i0,j0+1])
                        L[i0][j0+1] = g
                        G[g][(i0+j0+1)%2] += 1
                        
            # print(GGG)
# print(G)
ans = 0
for t in G:
    aa, bb = t
    ans += aa * bb
    
print(ans)
r=input()
print(r^2)

### FIXED CODE ###

print(int(input())**2)
N, M = map(int, input().split())
ABs = []
for i in range(M):
  A, B = map(int, input().split())
  A, B = A-1, B-1
  ABs.append((A, B))
UF = list(range(N))
Ns = [1]*N
def par(m):
  if UF[m] == m:
    return m
  r = par(UF[m])
  UF[m] = r
  return r
def unite(m, n):
  i = par(m)
  j = par(n)
  UF[i] = j
  Ns[j] = Ns[i]+Ns[j]
def size(m):
  return Ns[par(m)]
r = N*(N-1)//2
rs = [r]
for A, B in reversed(ABs):
  if par(A) == par(B):
    rs.append(r)
    continue
  sA = size(A)
  sB = size(B)
  unite(A, B)
  r -= sA*sB
  rs.append(r)
rs.pop()
for r in reversed(rs):
  print(r)


### FIXED CODE ###

N, M = map(int, input().split())
ABs = []
for i in range(M):
  A, B = map(int, input().split())
  A, B = A-1, B-1
  ABs.append((A, B))
UF = list(range(N))
Ns = [1]*N
def par(m):
  s = []
  r = UF[m]
  while r != m:
    s.append(m)
    m = r
    r = UF[m]
  for i in s:
    UF[i] = r
  return r
def unite(m, n):
  i = par(m)
  j = par(n)
  UF[j] = i
  Ns[i] = Ns[j] = Ns[i]+Ns[j]
def size(m):
  return Ns[par(m)]
r = N*(N-1)//2
rs = [r]
for A, B in reversed(ABs):
  if par(A) == par(B):
    rs.append(r)
    continue
  sA = size(A)
  sB = size(B)
  unite(A, B)
  r -= sA*sB
  rs.append(r)
rs.pop()
for r in reversed(rs):
  print(r)
K = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
  if i%K == 0:
  print('OK')
else:
  print('No')


### FIXED CODE ###

K = int(input())
a,b = map(int,input().split())
c = 'NG'
for i in range(a,b+1):
  if i % K == 0:
    c = 'OK'
    break
print(c)
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

reversed_input = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string: str):
    if len(string) == 0:
        return True
    else:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                return is_concatted_string(string)
        return False


if INPUT_STR != '' and is_concatted_string(reversed_input):
    print("YES")
else:
    print("NO")


### FIXED CODE ###

INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

string = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string):
    string = ''.join(list(reversed(string)))
    while len(string) != 0:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                if len(string) == 0:
                    return True
                break
        else:
            return False
    return False


if INPUT_STR != '' and is_concatted_string(INPUT_STR):
    print('YES')
else:
    print('NO')
n = int(input())
if n > 30:
  prtin('Yes')
 else:
  print('No')

### FIXED CODE ###

n = int(input())
if n < 30:
  print("No")
else:
  print("Yes")
H, N = input().split()
A = []
A = input().split()

if int(H)-sum(A) <=0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

H, N = input().split()
A = list(map(int, input().split()))

if int(H)-sum(A) <=0:
    print("Yes")
else:
    print("No")
import sys, collections, heapq
def single_input(F): return F.readline().strip("\n")
def line_input(F): return F.readline().strip("\n").split()

def solve():
    F = sys.stdin
    N, Q = map(int, line_input())
    event = []
    for i in range(N):
        s, t, x = map(int, line_input())
        event.append((s-x, 1, x))
        event.append((t-x,-1, x))
    for i in range(Q):
        d = int(single_input())
        event.append((d, 2, d))
    event.sort()
    candidate = []
    heapq.heapify(candidate)
    stop = collections.defaultdict(int)
    ans = ""
    for time, parameter, co in event:
        if parameter == 1:
            heapq.heappush(candidate, co)
            stop[co] += 1
        elif parameter == -1:
            stop[co] -= 1
        else:
            while candidate:
                x = heapq.heappop(candidate)
                if stop[x] > 0:
                    heapq.heappush(candidate, x)
                    ans += str(x) + "\n"
                    break
            else: ans += "-1\n"
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys, collections, heapq
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    N, Q = map(int, line_input())
    event = []
    for i in range(N):
        s, t, x = map(int, line_input())
        event.append((s-x, 1, x))
        event.append((t-x,-1, x))
    for i in range(Q):
        d = int(single_input())
        event.append((d, 2, d))
    event.sort()
    candidate = []
    heapq.heapify(candidate)
    stop = collections.defaultdict(int)
    ans = ""
    for time, parameter, co in event:
        if parameter == 1:
            heapq.heappush(candidate, co)
            stop[co] += 1
        elif parameter == -1:
            stop[co] -= 1
        else:
            while candidate:
                x = heapq.heappop(candidate)
                if stop[x] > 0:
                    heapq.heappush(candidate, x)
                    ans += str(x) + "\n"
                    break
            else: ans += "-1\n"
    print(ans)

    return 0

if __name__ == "__main__":
    solve()
ans = 5
cnt = 0
N = int(input())
for i in range(5):
    c = int(input())
    if N <= c:
        continue
    else:
        if i == 0:
            ans += N // c
            minn = c
        else:
            if minn - c > 0:
                cnt += 1
                minn = c
for i in range(cnt):
    ans += 2 ** i
print(ans)

### FIXED CODE ###

import math
C = []
N = int(input())
for i in range(5):
    c = int(input())
    C.append(c)
print(math.ceil(N / min(C)) + 4)
N,Q=map(int, input().split())
s=input()
td=[input().split() for i in range(Q)]

l=0
r=len(s)-1
for spell in reversed(td):
    if spell[0]==s[l] and spell[1]=='L':
        l+=1
    elif spell[0]==s[r] and spell[1]=='R':
        r-=1
print(max(0,r-l+1))


### FIXED CODE ###

N,Q=map(int, input().split())
s=input()
td=[input().split() for i in range(Q)]

def move(s,td,position):
    p=position
    for spell in td:
        if s[p]==spell[0] and spell[1]=='L':
            p-=1
        elif s[p]==spell[0] and spell[1]=='R':
            p+=1
        if p<0 or p>=N: break
    return p

l=0
r=N-1
watched=[0]*N
while(True):
    p=(r+l)//2
    if watched[p]>0:
        if p<N-1 and watched[p+1]==0:
            p+=1
        else:
            break
    res=move(s,td,p)
    if res<0:
        l=p
        watched[p]=1
    else:
        r=p
        if watched[p]==0: watched[p]=2
ans_l=N
for i in range(N):
    if watched[i]==2:
        ans_l=i
        break

l=0
r=N-1
watched2=[0]*N
while(True):
    p=(r+l)//2
    if watched2[p]>0:
        if p<N-1 and watched2[p+1]==0:
            p+=1
        else:
            break
    res=move(s,td,p)
    if res>=N:
        r=p
        watched2[p]=3
    else:
        l=p
        if watched2[p]==0: watched2[p]=2
ans_r=-1
for i in range(N-1,-1,-1):
    if watched2[i]==2:
        ans_r=i
        break
print(max(0,ans_r-ans_l+1))