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

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    if K >= 41:
        K = 41
    for k in range(K):
        next_A = [0 for i in range(N)]
        for i in range(len(A)):
            high = i + A[i] + 1
            if high > N:
                high = N
            low = i - A[i]
            if low < 0:
                low = 0
            for j in range(low,high):
                next_A[j] += 1
        A = next_A
    
    print(*A)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    if K > 41:
        K = 41
    
    for k in range(K):
        B = [0 for i in range(N)]
        for i in range(N):
            low = max(0,i-A[i])
            high = min(N-1,i+A[i])
            B[low] += 1
            if high+1 < N:
                B[high+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
    
    print(*A)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0
dist = [[float("inf")]*W for i in range(H)]

for sy in range(H):
    for sx in range(W):
        if D[sy][sx] == "#":
            Q = deque()
            Q.append((sx,sy))
            dist[sy][sx] = 0
            visited = [[0]*W for i in range(H)]
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and visited[ny][nx] == 0 and D[ny][nx] == ".":
                        Q.append((nx,ny))
                        visited[ny][nx] = 1
                        dist[ny][nx] = min(dist[y][x]+1,dist[ny][nx])

for i in range(H):
    for j in range(W):
        if D[i][j] == ".":
            ans = max(ans,dist[i][j])
print(ans)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))
### BUGGY CODE ###

import itertools
N=int(input())
L=list(map(int,input().split()))
C=list(itertools.combinations(L,3))
ans=0
for i in range(len(C)):
  if C[i][0]<C[i][1]+C[i][2] and C[i][1]<C[i][0]+C[i][2] and C[i][2]<C[i][1]+C[i][0]:
    ans+=1
print(ans)

### FIXED CODE ###

import bisect
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(N-2):
  for j in range(N-i-2):        
    ans+=min(N-i-j-2,N-bisect.bisect_left(L,L[-j-1]-L[i]+1)-j-1)
print(ans)
### BUGGY CODE ###

import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    b = []
    for i in range(n):
        if i % 2 == (n - 1) % 2:
            b.insert(0, a[i])
        else:
            b.append(a[i])
    return ' '.join(map(str, b))


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys


# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    b = [0] * n
    p = 0
    q = n - 1
    for i in range(n-1, -1, -1):
        if i % 2 == (n-1) % 2:
            b[p] = a[i]
            p += 1
        else:
            b[q] = a[i]
            q += -1
    return ' '.join(map(str, b))


def main():
    res = solve()
    print(res)


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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
for _ in range(K):
    imos = [0] * (N+1)
    for i in range(N):
        left = max(0, i-A[i])
        right = min(N-1, i+A[i])+1
        imos[left] += 1
        imos[right] += -1
    next_A = [0] * N
    next_A[0] = imos[0]
    for i in range(1, N):
        next_A[i] = next_A[i-1] + imos[i]
    A = next_A
print(" ".join([str(x) for x in A]))


### FIXED CODE ###

from numba import jit


@jit
def solve(N, K, A):
    for _ in range(K):
        imos = [0] * (N+1)
        for i in range(N):
            left = max(0, i-A[i])
            right = min(N-1, i+A[i])+1
            imos[left] += 1
            imos[right] += -1

        next_A = [0] * N
        next_A[0] = imos[0]
        for i in range(1, N):
            next_A[i] = next_A[i-1] + imos[i]

        if A == next_A:
            return A
        A = next_A
    return A


N, K = map(int, input().split())
A = [int(x) for x in input().split()]
print(" ".join([str(x) for x in solve(N, K, A)]))
### BUGGY CODE ###


mod = 10**9 + 7


def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    ans = 0
    for k in range(60):
        a = 0
        for i in range(n):
            a += A[i] & 1
            A[i] >>= 1
        da = (1 << k) % mod
        da *= (n - a)*a
        da %= mod
        ans += da
        ans %= mod
    print(ans)


main()


### FIXED CODE ###


mod = 10**9 + 7


def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    ans = 0
    for k in range(60):
        a = 0
        for i in range(n):
            a += A[i] & 1
            A[i] >>= 1
        da = (1 << k) % mod
        da *= (n - a)*a
        da %= mod
        ans += da
        ans %= mod
    print(ans)


main()
### BUGGY CODE ###

import sys
from heapq import *
from pprint import pprint

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

ans=-1
hp=[(0,si,sj)]
dx=[-2,-1,0,1,+2]
dy=[-2,-1,0,1,+2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
while hp:
    k,i,j=heappop(hp)
    if i==ti and j==tj:
        ans=k
        break
    for ci in dy:
        for cj in dx:
            if ci==cj==0:
                continue
            ni,nj=i+ci,j+cj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if (abs(ci)==1 and cj==0) or (ci==0 and abs(cj)==1):
                x=k
            else:
                x=k+1
            if x>=dist[ni][nj]:
                continue
            dist[ni][nj]=x
            heappush(hp,(x,ni,nj))


#pprint(dist)

print(ans)


### FIXED CODE ###

import sys
from heapq import *

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

ans=-1
hp=[(0,si,sj)]
dirs=[-2,-1,0,1,2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
while hp:
    k,i,j=heappop(hp)
    if i==ti and j==tj:
        ans=k
        break
    if k>dist[i][j]:
        continue
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                nk=k
            else:
                nk=k+1
            if nk>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            heappush(hp,(nk,ni,nj))

print(ans)
### BUGGY CODE ###

N = int(input())
n = 0
h = 0
w = 0

for i in range(1, 3501):
    for j in range(1, 3501):
        tmp1 = N * i * j
        tmp2 = (4 * i * j) - (N * j) - (N * i)
        if tmp2 != 0:
            s, m = divmod(tmp1, tmp2)
            if m == 0 and s >= 0:
                n, h, w = i, j, s
                print(n, h, w)
                exit()


### FIXED CODE ###

N = int(input())
n = 0
h = 0
w = 0

for i in range(1, 3501):
    for j in range(1, 3501):
        tmp1 = N * i * j
        tmp2 = (4 * i * j) - (N * j) - (N * i)
        if tmp2 != 0:
            s, m = divmod(tmp1, tmp2)
            if m == 0 and s >= 0:
                n, h, w = i, j, s
                print(n, h, w)
                exit()
### BUGGY CODE ###

S=input()
L=len(S)
ans=0

i=0
while i<=L-1:
    j=i+3
    while j<=L-1:
        ans+=1*(int(S[i:j+1])%2019==0)
        j+=1
    i+=1

print(ans)

### FIXED CODE ###

S=input()
R_S=S[::-1]
ans=0
count=[1]+[0]*2018
remainder=0

i=0
while i<len(S):
    remainder+=int(R_S[i])*pow(10,i,2019)
    remainder=remainder%2019
    ans+=count[remainder]
    count[remainder]+=1
    i+=1

print(ans)
### BUGGY CODE ###

def search(x,y,s1,s2,end1,end2):
  count = 0
  while  x < end1 and y < end2 and s1[x] == s2[y]:
    count += 1
    x += 1
    y += 1
  return count

def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      end1 = len(s1)
      end2 = len(s2)
      ans = 0
      for i in range(end1):
        for j in range(end2):
          if s1[i] == s2[j]:
            a = search(i,j,s1,s2,end1,end2)
            if a > ans:
              ans = a
      print(ans)
    except EOFError:
      break
solve()


### FIXED CODE ###

while True:
    try:
        s1 = input()
    except EOFError:
        break
    s2 = input()
    BASE = 27
    MOD = 1000000007


    def rolling_hash(s):
        h_lst = [0]
        for c in s:
            h_lst.append((h_lst[-1] * BASE + ord(c)) % MOD)
        return h_lst


    h_lst1 = rolling_hash(s1)
    h_lst2 = rolling_hash(s2)
    length1 = len(s1)
    length2 = len(s2)

    pow_mem = [pow(BASE, i, MOD) for i in range(min(length1, length2) + 1)]


    def check(center):
        hash_set = {(h_lst1[i + center] - h_lst1[i] * pow_mem[center]) % MOD for i in range(length1 - center + 1)}
        for i in range(length2 - center + 1):
            h2 = (h_lst2[i + center] - h_lst2[i] * pow_mem[center]) % MOD
            if h2 in hash_set:return True
        return False


    left = 0
    right = min(length1, length2)
    while right > left + 1:
        center = (left + right) // 2
        if check(center):
            left = center
        else:
            right = center
    print(right if check(right) else left)
### BUGGY CODE ###

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N

MAX = 3000000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)


### FIXED CODE ###

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N
MAX = 700000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
l1 = []
l2 = []
l3 = []
l4 = []
for i in A:
    if i in l1:
        if i in l2:
            if i in l3:
                if i not in l4:
                    l4.append(i)
            else:
                l3.append(i)
        else:
            l2.append(i)
    else:
        l1.append(i)
for i in l4:
    l2.append(i)
if len(l2) < 2:
    print(0)
else:
    l2.sort()
    print(l2[-1]*l2[-2])

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
d = Counter(A)
key = d.keys()
ans = []
for k in key:
    if d[k] >= 2:
        ans.append(k)
        if d[k] >= 4:
            ans.append(k)
if len(ans) < 2:
    print(0)
else:
    ans.sort()
    print(ans[-1]*ans[-2])
### BUGGY CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,q=input2()
B=str(input())
LR=[input_array() for _ in range(q)]

# E=["A","C","G","T"]

for lr in LR:
	st=lr[0]-1
	fi=lr[1]
	print(B[st:fi].count("AC"))

### FIXED CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,q=input2()
B=str(input())
LR=[input_array() for _ in range(q)]

# E=["A","C","G","T"]
T=[0]*(n+1) #1文字目〜n文字目までに出現する"AC"数の累積和

for i in range(n):
	if B[i:i+2] == "AC":	
		T[i+1] = T[i]+1
	else:
		T[i+1]=T[i]
for lr in LR:
	st=lr[0]-1
	fi=lr[1]-1
	print(T[fi]-T[st])
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
ans = 0
for i in range(k):
  if(a!=0):
    ans+=1
    a-=1
    continue
  elif(b!=0):
    b-=1
    continue
  else:
    c-=1
    ans-=1
    continue
print(ans)
  
  

### FIXED CODE ###

a,b,c,k = map(int,input().split())
if(a>=k):
  print(k)
else:
  if(a+b>=k):
    print(a)
  else:
    print(a-(k-(a+b)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
   N,M = map(int,input().split())
   Set = set()
   for i in range(M):
      a,b = map(int,input().split())
      Set.add((a,b))
      Set.add((b,a))                        #ADD
      for j in range(2,N):
         if (1,j) in Set and (j,N) in Set:
            print("POSSIBLE")
            return
   else:
       print("IMPOSSIBLE")

main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
   N,M = map(int,input().split())
   Set = set()
   for i in range(M):
      a,b = map(int,input().split())
      Set.add((a,b))
      Set.add((b,a))                        #condition
   for j in range(2,N):
      if (1,j) in Set and (j,N) in Set:
         print("POSSIBLE")
         return
   print("IMPOSSIBLE")

main()
### BUGGY CODE ###

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if a[i]+a[j] == j-i:
            ans += 1
            
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
sa = [0]*n
wa = [0]*n

ans = 0
for i in range(n):
    sa[i] = a[i]-i
    wa[i] = a[i]+i
b = Counter(wa)
c = Counter(sa)
    
for i in b:
    ans += b[i]*c[-i]
            
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
As = list(map(int,input().split()))
route = [0]
pre = 0
i = 0
len_route = 1
for k in range(K):
    i = As[i]-1
    if i in route:
        pre = route.index(i)
        route = route[pre:]
        len_route -= pre
        break
    route.append(i)
    len_route += 1
# print(route)
mod = len_route
print(route[(K-pre)%mod]+1)

### FIXED CODE ###

N,K = map(int,input().split())
As = list(map(int,input().split()))
towns = [0]*N
route = [0]
pre = 0
i = 0
towns[0] = 1
for _ in range(K):
    i = As[i]-1
    if towns[i]>0:
        pre = route.index(i)
        route = route[pre:]
        break
    route.append(i)
    towns[i] = 1
mod = len(route)
print(route[(K-pre)%mod]+1)
### BUGGY CODE ###

N = int(input())
Nums = input().split()

A = 1
break_flag = 0
for i in range(N):
  A*=int(Nums[i])
  if A > 10**18:
    A = -1
    break_flag = 1
  if A == 0:
    break_flag = 2

if break_flag == 1:
  print(-1)
else:
  print(A)

### FIXED CODE ###

N = int(input())
Nums = input().split()

AA = set(Nums)

if '0' in AA:
  print(0)
else:
  A = 1
  for i in range(N):
    A*=int(Nums[i])
    if A > 10**18:
      A = -1
      break
  print(A)
### BUGGY CODE ###

n = int(input()) #整数
a = [int(i) for i in input().split() ]

a = list(set(a))
a.sort()
while len(a) > 1:
    while (a[0] < a[1]):
        a[1] %= a[0]
    a = list(set(a))
    a.sort()
    if a[0] == 0:
        a.pop(0)
    if a[0] == 1:
        break
print(a[0])

### FIXED CODE ###

n = int(input()) #整数
a = [int(i) for i in input().split() ]

a = list(set(a))
a.sort()
while len(a) > 1:
    while (a[0] < a[1]):
        a[1] %= a[0]
    x = a[1]
    a[1] = a[0]
    a[0] = x
    if a[0] == 0:
        a.pop(0)
    if a[0] == 1:
        break
print(a[0])
### BUGGY CODE ###

A = input()
N = input().split()
N = [int(s) for s in N]
 
ans = 1
max = 1000000000000000000
for i in range(len(N)):
  ans = ans * N[i]
 
if ans > max:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

ans = 1
max = 10**18
if 0 in N:
  print(0)
else:
  for i in range(len(N)):
    ans = ans * N[i]
    if ans > max:
      ans = -1
      break
  print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

mod = 1000000007

dp = [0 for _ in range(N + 1)]
dp[0] = 1
if 1 not in A:
    dp[1] = 1

for n in range(2, N + 1):
    if n in A:
        dp[n] = 0
    else:
        dp[n] = dp[n - 1] + dp[n - 2]
        if dp[n] >= mod:
            dp[n] -= mod
            
print(dp[N])


### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

mod = 1000000007

dp = [1 for _ in range(N + 1)]
for a in A:
    dp[a] = 0

for n in range(2, N + 1):
    dp[n] *= dp[n - 1] + dp[n - 2]

    if dp[n] >= mod:
        dp[n] -= mod

print(dp[N])
### BUGGY CODE ###

s=str(input())
q=int(input())

for i in range(q):
    a = input()
    if int(a[0]) == 1:
        s=s[::-1]
    else:
        if int(a[2])==1:
            s=a[4] + s
        elif int(a[2]) ==2:
            s=s + a[4]

print(s)

### FIXED CODE ###

s=str(input())
q=int(input())

right=[]
left=[]
flag=0

for i in range(q):
    a = input()
    if int(a[0]) == 1:
        if flag == 0:
            flag=1
        else:
            flag=0
    else:
        if int(a[2]) == 1:
            if flag == 0:
                left.append(a[4])
            else:
                right.append(a[4])
        elif int(a[2]) ==2:
            if flag ==0:
                right.append(a[4])
            else:
                left.append(a[4])

right_result="".join(right)
left_result="".join(left)

if flag==0:
    print(str(left_result[::-1]+s+right_result))
else:
    print(str(right_result[::-1]+s[::-1]+left_result))
### BUGGY CODE ###

INF = float('inf')
class BellmanFord:
    
    def bellmanford(self,s,V,E):
        dist = [INF for _ in range(V)]
        dist[s] = 0
        while (True):
            update = False
            for e in E:
                u,v,cost = e
                if dist[u] != INF and dist[v] > dist[u] + cost:
                    dist[v] = dist[u]+cost
                    update = True
            if not update:break
        return dist

    def findneg(self,V,E):
        dist = [0 for _ in range(V)]
        for i in range(V):
            for e in E:
                u,v,cost = e
                if dist[u] != INF and dist[v] > dist[u] + cost:
                    dist[v] = dist[u]+cost
                    if i == V-1 and v == V-1:return True

def main():
    N,M = map(int,input().split())
    E = []
    for _ in range(M):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        E.append((a,b,-c))
    bf = BellmanFord()
    if bf.findneg(N,E):
        print('inf')
    else:
        ans = bf.bellmanford(0,N,E)
        print(-ans[-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

INF = float('inf')
class BellmanFord:
    
    def bellmanford(self,s,V,E):
        dist = [INF for _ in range(V)]
        dist[s] = 0
        for i in range(V):
            for e in E:
                u,v,cost = e
                if dist[u] != INF and dist[v] > dist[u] + cost:
                    dist[v] = dist[u]+cost
                    if i == V-1 and v == V-1:
                        return -1
        return dist
    

def main():
    N,M = map(int,input().split())
    E = []
    for _ in range(M):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        E.append((a,b,-c))
    bf = BellmanFord()
    dist = bf.bellmanford(0,N,E)
    if dist == -1:
        print('inf')
    else:
        ans = dist[-1]
        print(-ans)

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

from statistics import median

n=int(input())
a=[int(i) for i in input().split()]

for j in range(n):
  b=[int(i) for i in range(n)]
  b.pop(j)
  c=[a[k] for k in b] 
  print(median(c))




### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]

b=sorted(a)

for i in range(n):
  if a[i]<=b[int(n/2)-1]:
    print(b[int(n/2)])
  else:
    print(b[int(n/2)-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

class RangeUpdateQuery:
    def __init__(self, n):
        self.n0 = 2**(n-1).bit_length()
        self.INF = float("inf")
        self.data = [self.INF]*(2*self.n0-1)

    def update(self, l,r,v):
        l += self.n0
        r += self.n0
        while l < r:
            if r&1:
                r -= 1
                self.data[r-1] = v
            if l&1:
                self.data[l-1] = v
                l += 1
            l >>=1
            r >>=1

    def query(self, i):
        i += self.n0-1
        res = self.INF
        while i+1:
            if self.data[i] < res:
                res = self.data[i]
            i = ~-i//2
        return res

n,q = map(int, input().split())
start = [None]*q
se = set()

road = []
for i in range(n):
    s,t,x = map(int, input().split())
    se.add(x-s)
    se.add(x-(t-1))
    road.append([x, x-(t-1), x-s])
for i in range(q):
    d = int(input())
    start[i] = -d
    se.add(-d)

dd = sorted(se)
d = {j:i for i, j in enumerate(dd)}
k = len(d)

RUQ = RangeUpdateQuery(k)
road.sort(reverse=True)

for i, (x, s, t) in enumerate(road):
    l = d[s]
    r = d[t]
    RUQ.update(l, r+1, x)

ans = []
for i in range(q):
    x = RUQ.query(d[start[i]])
    if x == float("inf"):
        x = -1
    ans.append(x)

print(*ans, sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline

class RangeUpdateQuery:
    def __init__(self, n):
        self.n0 = 2**(n-1).bit_length()
        self.INF = float("inf")
        self.data = [self.INF]*(2*self.n0-1)

    def update(self, l,r,v):
        l += self.n0
        r += self.n0
        while l < r:
            if r&1:
                r -= 1
                self.data[r-1] = v
            if l&1:
                self.data[l-1] = v
                l += 1
            l >>=1
            r >>=1

    def query(self, i):
        i += self.n0-1
        res = self.INF
        while i+1:
            if self.data[i] < res:
                res = self.data[i]
            i = ~-i//2
        return res

n,q = map(int, input().split())
start = [None]*q
se = set()

road = []
for i in range(n):
    s,t,x = map(int, input().split())
    road.append([x, x-t, x-s])
for i in range(q):
    d = int(input())
    start[i] = -d

start = start[::-1]

RUQ = RangeUpdateQuery(q)
road.sort(reverse=True)
from bisect import bisect_left,bisect_right
for i, (x, s, t) in enumerate(road):
    l = bisect_right(start, s)
    r = bisect_right(start, t)
    #print(x, (s,t), l, r)
    RUQ.update(l, r, x)

ans = []
for i in range(q):
    x = RUQ.query(i)
    if x == float("inf"):
        x = -1
    ans.append(x)
ans = ans[::-1]
print(*ans, sep="\n")