Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

k,s=map(int,input().split())
c=0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if(i+l+j==s):
                c+=1
print(c)


### FIXED CODE ###

k,s=map(int,input().split())
c=0
for i in range(k+1):
    for j in range(k+1):
        d=s-i-j
        if(d>=0 and d<=k):
            c+=1
print(c)
### BUGGY CODE ###

s = input()
i = 0
t = ''
while i <= len(s)-5:
  if len(s)-i >= 7:
    if s[i:i+5] == 'dream':
      if s[i+4:i+6] == 'er':
        i += 7
        t += 'dreamer'
      else:
        i += 5
        t += 'dream'
    elif s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
        t += 'eraser'
      else:
        i += 5
        t += 'erase'
  elif len(s)-i == 6:
    if s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
        t += 'eraser'
      else:
        i += 5
        t += 'erase'
  elif len(s)-i == 5:
    if s[i:i+5] == 'erase':
      i = len(s)
      t += 'erase'
    elif s[i:i+5] == 'dream':
      i = len(s)
      t += 'dream'
    else:
      i = len(s)+1
if i == len(s):
  print('YES')
else:
  print('NO')

### FIXED CODE ###

s = input()
t = s[::-1]
i = 0
k = len(s)
while i <= k-5:
  if k-i >= 7:
    if t[i] != 'r':
      if t[i:i+5] == 'maerd':
        i += 5
      elif t[i:i+5] == 'esare':
        i += 5
      else:
        i = k+1
    else:
      if t[i:i+6] == 'resare':
        i += 6
      elif t[i:i+7] == 'remaerd':
        i += 7
      else:
        i = k+1
  elif k-i == 6:
    if t[i:i+6] == 'resare':
      i = k
    else:
      i = k+1
  else:
    if t[i:i+5] == 'esare':
      i = k
    elif t[i:i+5] == 'maerd':
      i = k
    else:
      i = k+1
if i == k:
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
for a in A[::-1]:
    if A.count(a) != a:
        A.remove(a)
        ans += 1
print(ans)

### FIXED CODE ###

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

result = {}
for b in B:
    result[b] = 0
for a in A:
    result[a] += 1

count = N
for b in B:
    if result[b] >= b:
        count -= b

print(count)
### BUGGY CODE ###

from sys import stdin
import numpy as np
N = list(map(int, (stdin.readline().strip().split())))[0]
M = list(map(int, (stdin.readline().strip().split())))
M=np.array(M)
c_list=[]
num_list=np.array([0]*(2*10**5+1))
ans=0
for i in M:
    num_list[i-1]+=1
ans=sum(num_list*(num_list-1))//2
for k in range(N):
    num=num_list[M[k]-1]-1
    print(ans-num)

### FIXED CODE ###

from sys import stdin
import numpy as np
N = list(map(int, (stdin.readline().strip().split())))[0]
M = list(map(int, (stdin.readline().strip().split())))
num_list=np.array([0]*(2*10**5+1))
ans=0
for i in M:
    num_list[i-1]+=1
ans=sum(num_list*(num_list-1))//2
for k in range(N):
    num=num_list[M[k]-1]-1
    print(ans-num)
### BUGGY CODE ###

data1 = input("")
data1 = data1.split(" ")
h = int(data1[0])
w = int(data1[1])
d = int(data1[2])
a = ["0"]*h
for i in range(h):
    a[i] = input("")
    a[i] = a[i].split(" ")
q = int(input(""))
data2 = ["0"]*q
l = [0]*q
r = [0]*q
m = [0]*q
for i in range(q):
    data2[i] = input("")
    data2[i] = data2[i].split(" ")
    l[i] = int(data2[i][0])
    r[i] = int(data2[i][1])
    while l[i] != r[i]:
        for j in range(h):
            for k in range(w):
                if int(a[j][k]) == l[i]:
                    start_X = k
                    start_Y = j
                    for n in range(h):
                        for o in range(w):
                            if int(a[n][o]) == l[i] + d:
                                m[i] += (abs(start_X-o)+abs(start_Y-n))
                                l[i] += d
for i in range(q):
    print(m[i])

### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    h,w,D = LI()
    a = LIR(h)
    d = defaultdict(int)
    for y in range(h):
        for x in range(w):
            d[a[y][x]] = y*w+x
    n = h*w
    dist = [[0 for i in range(n//D+1)] for i in range(D)]
    for i in range(1,n-D+1):
        y = d[i]//w
        x = d[i]%w
        y_ = d[i+D]//w
        x_ = d[i+D]%w
        k = i%D
        j = i//D
        dist[k][j+1] = dist[k][j]+abs(y_-y)+abs(x_-x)
    q = I()
    for i in range(q):
        l,r = LI()
        k = l%D
        print(dist[k][r//D]-dist[k][l//D])
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()
### BUGGY CODE ###

import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
already = set()
cnt = 0
ls = []
parent = [i for i in range(n)]

def unite(a, b):
    if not is_same(a, b):
        parent[find_root(b)] = find_root(a)

def find_root(a):
    while parent[a] != a:
        a = parent[a]
    return a

def is_same(a, b):
    return find_root(a) == find_root(b)

for i in range(m):
    x, y, z = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    unite(x, y)

cnt = 0
_set = set()
for i in range(n):
    _set.add(find_root(i))
print(len(_set))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

def unite(a, b):
    root_a = find_root(a)
    parent[a] = root_a
    root_b = find_root(b)
    parent[b] = root_b
    if root_a != root_b:
        parent[root_b] = root_a

def find_root(a):
    ls = []
    while parent[a] != a:
        ls.append(a)
        a = parent[a]
    for l in ls:
        parent[l] = a
    return a


for i in range(m):
    x, y, z = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    unite(x, y)

_set = set()
for i in range(n):
    _set.add(find_root(i))
print(len(_set))
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    a.sort()
    a[n-1] = a[n-1]//2
print(sum(a))


### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    b = heapq.heappop(a)//(-2)
    heapq.heappush(a,-b)
print(-sum(a))
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    k = int(input())
    print(getresult(k))

def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

from numba import njit

def main():
    k = int(input())
    print(getresult(k))

@njit
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

@njit
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():
  def syaku(j,x,D):
    while True:
      if j+1>=N:
        break
      if XH[j+1][0]<=x+2*D:
        j+=1
      else:
        break
    return j
  N,D,A = map(int,input().split())
  import numpy as np
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  j = 0
  l[0]=syaku(j,x,D)
  for i in range(1,N):
    x = XH[i][0]
    j = l[i-1]
    l[i]=syaku(j,x,D)
  H = np.array([xh[1] for xh in XH])
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      H[i:a+1:]-=b*A
  print(ans)
main()

### FIXED CODE ###

def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()
### BUGGY CODE ###

import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = rl()
a=rl()
a.sort()
b=[]
c=[]
for i in a:
    if len(b)==0:
        b.append(i)
        continue
    flag=True
    for j in b:
        if i==j:
            c.append(j)
        if i%j==0:
            flag=False
    if flag:
        b.append(i)
if c:
    for i in c:
        if b:
            b.remove(i)
print(len(b))

### FIXED CODE ###

import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = rl()
a=rl()
a.sort()
b=[0]*2*10**6
for i in a:
    if b[i]==0:
        b[i]=-1
        for j in range(2,10**6):
            if i*j>10**6:
                break
            b[i*j]+=1
        continue
    
    if b[i]==-1:
        b[i]=1
cnt = 0
for i in a:
    if b[i]==-1:
        cnt+=1
print(cnt)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in A:
  ans.append(i)
  ans=ans[::-1]
print(*ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
print(*A[::-2],end=" ")
print(*A[n%2::2])
### BUGGY CODE ###

import sys
input=sys.stdin.buffer.readline

N=int(input())
vw=[(-1,-1)]
for i in range(N):
    vw.append(tuple(map(int,input().split())))

dp=[[0 for i in range(100001)] for i in range(2**10)]
for i in range(vw[1][1],100001):
    dp[1][i]=vw[1][0]
MAX=min(2**10,N+1)
for i in range(2,MAX):
    v,w=vw[i]
    for j in range(100001):
        dp[i][j]=max(dp[i//2][j],(dp[i//2][j-w]+v)*(j>=w))

def solve(V,L):
    t=[(0,0)]
    while V>=2**10:
        for v,w in t:
            nv,nw=v+vw[V][0],w+vw[V][1]
            t.append((nv,nw))
        V//=2
    ans=0
    for v,w in t:
        if L>=w:
            ans=max(ans,v+dp[V][L-w])
    return ans

for i in range(int(input())):
    v,L=map(int,input().split())
    print(solve(v,L))


### FIXED CODE ###

import sys,random,time,bisect
input=sys.stdin.buffer.readline

start=time.time()
N=int(input())
vw=[(-1,-1)]
for i in range(N):
    vw.append(tuple(map(int,input().split())))

dp=[[] for i in range(2**9)]
def make_dp(v):
    t=[[0,0] for i in range(15)]
    V=v
    id=0
    while v>=1:
        t[id]=vw[v]
        id+=1
        v//=2
    n=id
    temp=[[0,0] for i in range(2**n)]
    for i in range(n):
        for j in range(2**i,2**(i+1)):
            temp[j][0]=temp[j-2**i][0]+t[i][0]
            temp[j][1]=temp[j-2**i][1]+t[i][1]
    temp.sort(key=lambda x:x[1])
    for i in range(1,2**n):
        temp[i][0]=max(temp[i][0],temp[i-1][0])

    dp[V]=[0]*(10**5+1)
    for i in range(2**n-1):
        L=temp[i][1]
        R=temp[i+1][1]
        if L>10**5:
            break
        elif R>10**5:
            R=10**5+1
        for j in range(L,R):
            dp[V][j]=temp[i][0]
    else:
        L=temp[-1][1]
        if L<=10**5:
            for j in range(L,10**5+1):
                dp[V][j]=temp[-1][0]

MAX=min(2**9,N+1)
for i in range(1,MAX):
    make_dp(i)

Q=int(input())
query=[[] for i in range(N+1)]
for i in range(Q):
    v,L=map(int,input().split())
    query[v].append((L,i))

ans=[0]*Q
temp=[[0,0] for i in range(2**9)]
t=[[0,0] for i in range(15)]
def solve(v):
    V=v
    id=0
    while v>=2**9:
        t[id]=vw[v]
        id+=1
        v//=2
    n=id
    for i in range(n):
        for j in range(2**i,2**(i+1)):
            temp[j][0]=temp[j-2**i][0]+t[i][0]
            temp[j][1]=temp[j-2**i][1]+t[i][1]

    for L,ID in query[V]:
        res=0
        for i in range(2**n):
            if L>=temp[i][1]:
                res=max(res,temp[i][0]+dp[v][L-temp[i][1]])
        ans[ID]=res

for i in range(1,N+1):
    if query[i]:
        solve(i)

for i in range(Q):
    print(ans[i])
### BUGGY CODE ###

N,K,Q=map(int,input().split())
c=[K]*N
d=[0]*N
for i in range(Q):
  A=int(input())-1
  for j in range(N):
    if j!=A:
      c[j]-=1
      
for k in range(N):
  if c[k]<=0:
    d[k]='No'
  else:
    d[k]='Yes'
    
for r in range(N):
  print(d[r])
    
      
      
  

### FIXED CODE ###

N,K,Q=map(int,input().split())
c=[K-Q]*N

for i in range(Q):
  A=int(input())-1
  c[A]+=1
    
for k in range(N):
  if c[k]>0:
    c[k]='Yes'
  else:
    c[k]='No'
    
for j in range(N):
  print(c[j])
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for i in A:
    d[i] += 1
d = [x for x in d.items() if x[1]>=2]

ans = 0
for i1,j1 in d:
    for i2,j2 in d:
        if j1 >= 2 and j2 >= 2 and i1 != i2:
            ans = max(ans,i1*i2)
        elif i1==i2 and j1>=4 and j2>=4:
            ans = max(ans,i1*i2)
print(ans)


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i+1<N:
    if len(b)==2:
        break
    if a[i] == a[i+1]:
        b += [a[i]]
        i += 2
    else:
        i += 1

if len(b)<2:
    print(0)
else:
    print(b[0]*b[1])
### BUGGY CODE ###

from collections import deque
from bisect import bisect_left, bisect_right
from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))

result = [-1 for _ in range(n)]
tree = [[] for _ in range(n)]
for _i in range(n-1):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    tree[u].append(v)
    tree[v].append(u)

dp = [float('inf') for _i in range(n+1)]
q = [[0, dp]]
q = deque(q)
while q:
    p, d = q.popleft()
    i = bisect_left(d, a[p])
    d[i] = a[p]
    result[p] = bisect_left(d, float("inf")-1)
    for i in tree[p]:
        if result[i] < 0:
            q.append([i, deepcopy(d)])

for i in result:
    print(i)

### FIXED CODE ###

from bisect import bisect_left
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
a = list(map(int, input().split()))

result = [-1 for _ in range(n)]
tree = [[] for _ in range(n)]
for _i in range(n-1):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    tree[u].append(v)
    tree[v].append(u)
INF = float('inf')
dp = [INF for _i in range(n+1)]


def dfs(p, x):
    i = bisect_left(dp, a[p])
    old = dp[i]
    dp[i] = a[p]
    result[p] = bisect_left(dp, INF)
    for j in tree[p]:
        if j != x:
            dfs(j, p)
    dp[i] = old
    

dfs(0, -1)

for i in result:
    print(i)
### BUGGY CODE ###

n,b,r=map(int,input().split())
blue=True
c=0
while n>0:
    if blue:
        x=b if n>b else n
        c+=x
        n-=x
    else:
        n-=r if n>r else n
    blue=(not blue)
print(c)

### FIXED CODE ###

n,b,r=map(int,input().split())
x=n%(b+r)
c=b*(n//(b+r))
c+=b if x>b else x
print(c)
### BUGGY CODE ###

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

ab=[]
dp=[0]*(10**5)

for _ in range(n):
    a,b=map(int,input().split())
    ab.append((a,b))
    dp[b]=a

#dp[b]は、自分がダメージをｂ受けた時の、相手に与えたダメージ
i=1
while 1:

    dp[i]=max(dp[i],dp[i-1])
    for k in range((i-1)//2+2):
        dp[i]=max(dp[i],dp[k]+dp[i-k])
    
    #print(dp)
    if dp[i]>=h:
        print(i)
        exit()
    i+=1

    
    



### FIXED CODE ###

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

ab=[]
dp=[10**9]*(10**5)

maxA=0
for _ in range(n):
    a,b=map(int,input().split())
    dp[a]=min(dp[a],b)
    maxA=max(maxA,a)
#print(dp)
#dp[a]は、相手にaダメージを与えるときの、消耗する自分の最小HP
result=10**9
for i in range(1,h+maxA):
    #print(i,"##########")
    for k in range(1,i//2+2):
        dp[i]=min(dp[i],dp[k]+dp[i-k])
    if i>=h:
        result=min(result,dp[i])
    #print(dp)
print(result)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
count = 0
for string in strings:
    tmp = strings.count(string)
    if tmp > 1:
        count += (tmp - 1) / 2

print(int(count))

### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

print(count)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    *h, = map(int, input().split())

    ans = f(N, K, h)
    print(ans)


def f(N, K, h):
    dp = [None] * (N + 1)
    dp[0] = 0
    dp[1] = 0

    for i in range(2, N + 1):
        hi = i - 1
        cost = float("inf")
        for k in range(1, K + 1):
            if i - k < 1:
                continue

            tmp = dp[i-k] + abs(h[hi] - h[hi-k])
            cost = min(cost, tmp)

        dp[i] = cost

    ans = dp[N]
    return ans


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    *h, = map(int, input().split())

    ans = f(N, K, h)
    print(ans)


def f(N, K, h):
    dp = [None] * (N + 1)
    dp[0] = 0
    dp[1] = 0

    for i in range(2, N + 1):
        hi = i - 1
        cost = float("inf")
        for k in range(1, K + 1):
            if i - k < 1:
                continue

            tmp = dp[i-k] + abs(h[hi] - h[hi-k])
            cost = min(cost, tmp)

        dp[i] = cost

    ans = dp[N]
    return ans


if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

S = list(input())

cnt = 0

for i in range(0,len(S)-3) :
    for j in range(i+3, len(S)) :
        # print(int(''.join(S[i:j+1])))
        res = int(''.join(S[i:j+1]))
        if res % 2019 == 0 :
            cnt += 1

print(cnt)

### FIXED CODE ###

S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)
### BUGGY CODE ###

#d
n=int(input())
x=list(input())
n=len(x)
def popcount(m):
    return bin(m).count("1")

popcount0 = popcount(int( "0b"+"".join(x) ,0 ))
intx = int( "0b"+"".join(x) ,0 )

jisho = ["yet"]*n
for i in range(n):
    xx = x[:]
    if xx[i]=="0":
        xx[i] = "1"
        pop = popcount0+1
        intxi = intx+pow(2,n-i-1)
    else:
        xx[i] = "0"
        pop = popcount0-1
        intxi = intx-pow(2,n-i-1)

        
    if intxi==0:
        print(0)
        continue
    else:
        c=0
        while intxi!=0:
            if c==0:
                intxi=intxi%pop
            else:
                if jisho[intxi]=="yet":
                    togo = intxi%popcount(intxi)
                    jisho[intxi]= togo
                    intxi = togo
                else:
                    intxi =jisho[intxi]
                
            #print(intxi)
            c+=1
        print(c)
        #print()
#        print("f(n)=",c)

### FIXED CODE ###

#d 
n=int(input())
x=input()

def popcount(m):
    return bin(m).count("1")

intx = int( "0b"+x ,0 )
popcount0 = x.count("1")

intx_mod_pp1 = intx %(popcount0+1)
if popcount0!=1:
    intx_mod_pm1 = intx %(popcount0-1)
    

jisho = ["yet"]*n
# pow2ip = .5
# pow2im = .5

for i in range(n):
    if x[i]=="1" and popcount0==1:
        print(0)
        continue
    
    pow2ip = pow(2,n-i-1,popcount0+1)
    if popcount0!=1:
        pow2im = pow(2,n-i-1,popcount0-1)

    if False:
        pass
    
    
    else:
        intxi=1
        c=0
        while intxi!=0:
            if c==0:
                if x[i]=="0":
                    pop = popcount0+1
                    intxi = (intx_mod_pp1 + pow2ip%pop )%pop
                else:
                    pop = popcount0-1
                    intxi = (intx_mod_pm1 - pow2im%pop )%pop        
            else:
                if jisho[intxi]=="yet":
                    togo = intxi%popcount(intxi)
                    jisho[intxi]= togo
                    intxi = togo
                else:
                    intxi =jisho[intxi]
                
            #print(intxi)
            c+=1
        print(c)
        #print()
    
#        print("f(n)=",c)
### BUGGY CODE ###

import sys
import bisect
 
N, Q = map(int, input().split(' '))
G = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)]
T = [int(sys.stdin.readline()) for _ in range(Q)]

class SegTree :
    def __init__(self, n) :
        self.n = n
        self.A = [10**15] * (2 << (n + 1).bit_length())
 
    def update(self, l, r, val) :
      l += len(self.A) // 2
      r += len(self.A) // 2
      while l < r:
          if l & 1 :
              self.A[l] = min(self.A[l], val)
              l += 1
          if r & 1:
              self.A[r-1] = min(self.A[r-1], val)
              r -= 1
          l //= 2
          r //= 2

    def get(self, i) :
      i += len(self.A) // 2
      ret = self.A[i]
      while i > 0 :
          i //= 2
          ret = min(ret, self.A[i])
      return ret if ret < 10**15 else -1

ST = SegTree(Q)
for g in G :
    s = g[0] - g[2]
    e = g[1] - g[2]
 
    ll = bisect.bisect_left(T, s)
    rr = bisect.bisect_left(T, e)
 
    if ll == rr :
        continue
 
    ST.update(ll, rr, g[2])
 
for i in range(Q) :
    ans = ST.get(i)
    print(ans)


### FIXED CODE ###

import sys
import bisect
 
N, Q = map(int, input().split(' '))
G = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)]
T = [int(sys.stdin.readline()) for _ in range(Q)]

class SegTree :
    def __init__(self, n) :
        self.n = n
        self.A = [10**15] * (2 << (n + 1).bit_length())
 
    def update(self, l, r, val) :
      l += len(self.A) // 2
      r += len(self.A) // 2
      while l < r:
          if l & 1 :
              self.A[l] = min(self.A[l], val)
              l += 1
          if r & 1:
              self.A[r-1] = min(self.A[r-1], val)
              r -= 1
          l //= 2
          r //= 2

    def get(self, i) :
      i += len(self.A) // 2
      ret = self.A[i]
      while i > 0 :
          i //= 2
          ret = min(ret, self.A[i])
      return ret if ret < 10**15 else -1

ST = SegTree(Q)
for g in G :
    s = g[0] - g[2]
    e = g[1] - g[2]
 
    ll = bisect.bisect_left(T, s)
    rr = bisect.bisect_left(T, e)
 
    if ll == rr :
        continue
 
    ST.update(ll, rr, g[2])
 
for i in range(Q) :
    ans = ST.get(i)
    print(ans)