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

N , M = map(int, input().rstrip().split())

pricelist = list(map(int, input().split()))
#moneylist = input().rstrip().split()
#pricelist.append(price)

for i in range(M):
  maxprice = max(pricelist)
  num = pricelist.index(maxprice)
  pricelist[num] = maxprice // 2

print(sum(pricelist)) 



### FIXED CODE ###

import heapq
N , M = map(int, input().rstrip().split())
 
pricelist = list(map(int, input().split()))
for i in range(N):
  pricelist[i] = pricelist[i] * (-1)
heapq.heapify(pricelist)

 
for i in range(M):
  minprice = heapq.heappop(pricelist)
  if minprice % 2 == 0:
    minprice = minprice // 2
  else:
    minprice = minprice // 2 + 1
  heapq.heappush(pricelist, minprice)

print(sum(pricelist)* (-1))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M, Q = mi()
abcd = li2(Q)

'''
a = '0' * N
m = str(M-1)
l = [a]

while True:
    i = N-1
    while i >= 0 and a[i] == m:
        i -= 1
    if i == -1:
        break
    a = list(a)
    num = str(int(a[i]) + 1)
    a[i] = num
    if i != N-1:
        for j in range(i+1, N):
            a[j] = num
    tmp = ''.join(a)
    l.append(tmp)
'''

def dfs(num, length):
    if length == N:
        l.append(num)
        return
    last = int(num[-1])
    for i in range(last, M):
        dfs(num + str(i), length+1)

#l = []
#dfs('0', 1)

from collections import deque
keta_list = [str(i) for i in range(M)]
l = deque([str(i) for i in range(M)])

while len(l[0]) <= N:
    num = l.popleft()
    last = int(num[-1])
    for tail in keta_list[last:]:
        l.append(num + tail)

ans = 0
for num in l:
    cnt = 0
    num = list(map(int, list(num)))
    for i in range(Q):
        if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:
            cnt += abcd[i][3]
    ans = max(ans, cnt)

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M, Q = mi()
abcd = li2(Q)

#N = 10

a = '0' * N
m = str(M-1)
l = [a]
#for length in range(N):
while True:
    i = N-1
    while i >= 0 and a[i] == m:
        i -= 1
    if i == -1:
        break
    a = list(a)
    num = str(int(a[i]) + 1)
    a[i] = num
    if i !=N-1:
        for j in range(i+1, N):
            a[j] = num
    tmp = ''.join(a)
    l.append(tmp)


ans = 0
for num in l:
    cnt = 0
    num = list(map(int, list(num)))
    for i in range(Q):
        if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:
            cnt += abcd[i][3]

    ans = max(ans, cnt)

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

import sys
input = sys.stdin.readline
s=input().replace('\n','')
q=int(input())
num1=0
for i in range(q):
    query=input()
    if query[0]=='1':
        num1+=1
    else:
        query=query.replace('\n','')
        _,f,c=map(str,query.split())
        if f=='1':
            if num1%2==0:
                s=c+s
            else:
                s=s+c[::-1]
        else:
            if num1%2==0:
                s=s+c
            else:
                s=c[::-1]+s
if num1%2==0:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
s=input().replace('\n','')
q=int(input())
num1=0
sento=''
matsubi=''

for i in range(q):
    query=input()
    if query[0]=='1':
        num1+=1
    else:
        query=query.replace('\n','')
        _,f,c=map(str,query.split())
        if f=='1':
            if num1%2==0:
                sento=c+sento
            else:
                matsubi+=c
        else:
            if num1%2==0:
                matsubi+=c
            else:
                sento=c+sento
ans=sento+s+matsubi
if num1%2==0:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor:GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a, b):
    """a, bの最小公倍数(least common multiple:LCM)を求める
    計算量: O(log(min(a, b)))"""
    return (a * b) // gcd(a, b)

             
def multi_lcm(array):
    """arrayのLCMを求める"""
    ans = array[0] 
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
    return ans 

import sys
input = sys.stdin.readline

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

l = [0] * n
for i in range(n):
    cnt = 0
    tmp = a[i]
    while True:
        if tmp % 2 == 0:
            cnt += 1
            tmp //= 2
        else:
           break
    l[i] = cnt
if max(l) != min(l):
    print(0)
    exit()
    
div = multi_lcm(a)
ans = 0
if m - div // 2 >= 0:
    ans += 1
m = m - div // 2 
ans += m // div
if m < 0:
    print(0)
else:
    print(ans)


### FIXED CODE ###

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor:GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a, b):
    """a, bの最小公倍数(least common multiple:LCM)を求める
    計算量: O(log(min(a, b)))"""
    return (a * b) // gcd(a, b)

             
def multi_lcm(array, m):
    """arrayのLCMを求める"""
    ans = array[0] 
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
        if ans > 5*m:
            return 5*m
    return ans 

import sys
input = sys.stdin.readline

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

l = [0] * n
for i in range(n):
    cnt = 0
    tmp = a[i]
    while True:
        if tmp % 2 == 0:
            cnt += 1
            tmp //= 2
        else:
           break
    l[i] = cnt
if max(l) != min(l):
    print(0)
    exit()
    
div = multi_lcm(a, m)
ans = 0
if m - div // 2 >= 0:
    ans += 1
m = m - div // 2 
ans += m // div
if m < 0:
    print(0)
else:
    print(ans)
### BUGGY CODE ###

url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    for t in range(1, tate + 1):

        for y in range(1, yoko + 1):
            arround = 0
            if tate == 1 and yoko == 1:
                arround += 1
            elif (t == 1 and t == tate) or (y == 1 and y == yoko):
                if (1 < t < tate) or (1 < y < yoko):
                    arround += 3
                else:
                    arround += 2
            elif (t == 1 or t == tate) and (y == 1 or y == yoko):
                arround += 4
            elif (t == 1 or t == tate) or (y == 1 or y == yoko):
                arround += 6
            else:
                arround += 9
            if arround % 2 != 0:
                count += 1
    print(count)




if __name__ == '__main__':
    main()




### FIXED CODE ###

url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    if tate == 1 and yoko == 1:
        print("1")
        exit()
    elif tate == 1:
        print(yoko - 2)
        exit()
    elif yoko == 1:
        print(tate - 2)
        exit()
    count += (yoko - 2) * (tate - 2)
    print(count)




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

N,K = map(int, input().split())
A = [int(i) for i in input().split()]

l=[]
for i in range(N+1):
  l.append(A.count(i))

ls = sorted(l,reverse=True)

ans = N
for j in range(K):
  ans -= ls[j]

print(ans)

### FIXED CODE ###

import collections as co
N,K = map(int, input().split())
A = list(map(int, input().split()))

ldic = co.Counter(A)        
l = list(ldic.values())
ls = sorted(l,reverse=True)

print(sum(ls[K:]))
### BUGGY CODE ###

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

a_ol = {}
def_count = 0
for i in a_uni:
    a_co = a.count(i)
    if a_co > 1:
        a_ol[i] = a_co
        def_count += a_co * (a_co - 1) // 2

for k in range(n):
    if a[k] in a_ol:
        print(def_count - a_ol[a[k]] + 1)
    else:
        print(def_count)



### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))


a_ol = Counter(a)
def_count = 0
for item in a_ol.items():
    a_co = item[1]
    def_count += a_co * (a_co - 1)

def_count //= 2

for k in a:
    print(def_count - a_ol[k] + 1)
### BUGGY CODE ###

import numpy as np


def imos2d(x1, y1, x2, y2, board):
    board[y1][x1] += 1
    board[y2][x2] += 1
    board[y2][x1] -= 1
    board[y1][x2] -= 1


if __name__ == '__main__':
    N, K = map(int, input().split())
    lines = [input().split() for _ in range(N)]
    xs, ys, cs = zip(*[[int(line[0]), int(line[1]), line[2]] for line in lines])

    # N, K = 4, 3
    # xs = [0, 1, 5, 5]
    # ys = [1, 2, 3, 4]
    # cs = ["W", "W", "B", "B"]

    K2 = 2 * K
    add_dict = {"W": 0, "B": K}
    board = np.zeros((K2 + 1, K2 + 1), np.int64)
    for x, y, c in zip(xs, ys, cs):
        x = x % K2
        y = (y + add_dict[c]) % K2

        if (x < K and y < K) or (K <= x and K <= y):
            # 左上・右上・中央・左下・右下

            x_ = x % K
            y_ = y % K

            # 左上
            imos2d(0, 0, x_ + 1, y_ + 1, board)
            # 右上
            imos2d(x_ + K + 1, 0, K2, y_ + 1, board)
            # 左下
            imos2d(0, y_ + K + 1, x_ + 1, K2, board)
            # 右下
            imos2d(x_ + K + 1, y_ + K + 1, K2, K2, board)
            # 中央
            imos2d(x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1, board)
        else:
            # 上・下・左・右
            x_ = x % K
            y_ = y % K

            # 上
            imos2d(x_ + 1, 0, x_ + K + 1, y_ + 1, board)
            # 下
            imos2d(x_ + 1, y_ + K + 1, x_ + K + 1, K2, board)

            # 左
            imos2d(0, y_ + 1, x_ + 1, y_ + K + 1, board)
            imos2d(x_ + K + 1, y_ + 1, K2, y_ + K + 1, board)

    board_cum = board.cumsum(axis=0).cumsum(axis=1)
    print(board_cum.max())


### FIXED CODE ###

import numpy as np


def imos2d(x1, y1, x2, y2, board):
    board[y1][x1] += 1
    board[y2][x2] += 1
    board[y2][x1] -= 1
    board[y1][x2] -= 1


if __name__ == '__main__':
    N, K = map(int, input().split())
    lines = [input() for _ in range(N)]

    # N, K = 4, 3
    # lines = ["0 1 W", "1 2 W", "5 3 B", "5 4 B"]

    K2 = 2 * K
    add_dict = {"W": 0, "B": K}
    board = [[0 for _ in range(K2 + 1)] for _ in range(K2 + 1)]
    for line in lines:
        ls = line.split()
        x = int(ls[0]) % K2
        y = (int(ls[1]) + add_dict[ls[2]]) % K2
        x_ = x % K
        y_ = y % K

        # 左上・右上・中央・左下・右下
        if (x < K and y < K) or (K <= x and K <= y):
            # 左上
            imos2d(0, 0, x_ + 1, y_ + 1, board)
            # 右上
            imos2d(x_ + K + 1, 0, K2, y_ + 1, board)
            # 左下
            imos2d(0, y_ + K + 1, x_ + 1, K2, board)
            # 右下
            imos2d(x_ + K + 1, y_ + K + 1, K2, K2, board)
            # 中央
            imos2d(x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1, board)
        # 上・下・左・右
        else:
            # 上
            imos2d(x_ + 1, 0, x_ + K + 1, y_ + 1, board)
            # 下
            imos2d(x_ + 1, y_ + K + 1, x_ + K + 1, K2, board)

            # 左
            imos2d(0, y_ + 1, x_ + 1, y_ + K + 1, board)
            imos2d(x_ + K + 1, y_ + 1, K2, y_ + K + 1, board)

    board = np.array(board)
    for x in range(K2):
        board[:, x + 1] += board[:, x]
    for y in range(K2):
        board[y + 1, :] += board[y, :]

    print(board.max())
### BUGGY CODE ###

N,K = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
C = {}
tot1 = 0
for i in range(K):
    t,d = A[i]
    if t not in C:
        C[t] = 0
    C[t] += 1
    tot1 += d
tot2 = len(C)
tot = tot1+tot2**2
cur = K
for i in range(K-1,-1,-1):
    t,d = A[i]
    if C[t]>1:
        tot1 -= d
        C[t] -= 1
        j = cur
        while j<N:
            t1,d1 = A[j]
            if t1 not in C:
                C[t1]=1
                tot1 += d1
                tot2 += 1
                if tot1+tot2**2>tot:
                    tot = tot1+tot2**2
                cur = j+1
                break
            else:
                j += 1
print(tot)

### FIXED CODE ###

N,K = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
C = {}
tot1 = 0
for i in range(K):
    t,d = A[i]
    if t not in C:
        C[t] = 0
    C[t] += 1
    tot1 += d
tot2 = len(C)
tot = tot1+tot2**2
cur = K
for i in range(K-1,-1,-1):
    t,d = A[i]
    if C[t]>1:
        tot1 -= d
        C[t] -= 1
        j = cur
        while j<N:
            t1,d1 = A[j]
            if t1 not in C:
                C[t1]=1
                tot1 += d1
                tot2 += 1
                if tot1+tot2**2>tot:
                    tot = tot1+tot2**2
                cur = j+1
                break
            else:
                j += 1
                cur = j
print(tot)
### BUGGY CODE ###

import sys
input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10 ** 7)  # NOQA


def dfs(N, a, i, b, procedure):
    if i == 0:
        return procedure

    for j in range(1, i+1):
        if a[j-1] == j:
            l = a[:]
            del l[j-1]
            p = procedure[:]
            p.append(j)
            ret = dfs(N, l, i-1, b, p)
            if ret is not None:
                return ret


def main():
    N = int(input())
    b = list(map(int, input().split()))

    res = dfs(N, b, N, b, [])
    if res is None:
        print(-1)
    else:
        print(*res[::-1], sep="\n")


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10 ** 7)  # NOQA


def dfs(N, a, i, procedure):
    if i == 0:
        return procedure

    for j in reversed(range(1, i+1)):
        if a[j-1] == j:
            l = a[:]
            del l[j-1]
            p = procedure[:]
            p.append(j)
            ret = dfs(N, l, i-1, p)
            if ret is not None:
                return ret
            break


def main():
    N = int(input())
    b = list(map(int, input().split()))

    res = dfs(N, b, N, [])
    if res is None:
        print(-1)
    else:
        print(*res[::-1], sep="\n")


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

def main():
  inf = float("INF")
  a,b,q = map(int, input().split())
  s = [None] * (a + 3)
  s[0:2] = [-inf,-inf]
  s[-1] = inf
  t = [None] * (b + 3)
  t[0:2] = [-inf,-inf]
  t[-1] = inf
  for i in range(a):
      s[i+2] = int(input())
  for i in range(b):
      t[i+2] = int(input())

  from bisect import bisect_right

  dp0 = [None] * (a+3)
  dp1 = [None] * (b+3)

  for _ in range(q):
    ans = inf
    x = int(input())
    sr = bisect_right(s, x)
    tr = bisect_right(t, x)    
    for si in (sr, sr-1):
      for ti in (tr, tr-1):
        ans = min(ans, abs(x-s[si]) + abs(s[si]-t[ti]), abs(x-t[ti]) + abs(s[si]-t[ti]))
    print(ans)
  
if __name__ == "__main__":
  main()


### FIXED CODE ###

#A

"""
s = input().split("/")
if int(s[1]) <= 4:
    print("Heisei")
else:
    print("TBD")
"""
#B
"""
n = int(input())
ans = 0
for i in range(n):
    a = input().split()
    if a[1] == "JPY":
        ans += int(a[0])
    else:
        ans +=  float(a[0]) * 380000
print(ans)
"""

#C
"""
n, a, b, c = map(int, input().split())
abc = [a,b,c]
x = [int(input()) for i in range(n)]
x.sort()
ans = []
flg = 0
for i in x:
    if i in abc:
        ans.append(i)
        flg = 1
if flg:
    for i in ans:
        abc.remove(i)
        x.remove(i)

"""
#D

a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
s.sort()
t.sort()

import bisect


for i in range(q):
    x = int(input())
    s_l = bisect.bisect_left(s, x) - 1
    t_l = bisect.bisect_left(t, x) - 1
    s_r = s_l + 1
    t_r = t_l + 1
    if s_l == -1:
        s_l = 0
    if t_l == -1:
        t_l = 0
    if s_l == a :
        s_l = a - 1
        s_r = a - 1
    if s_r == a:
        s_r = a - 1
    if t_l == b:
        t_l = b - 1
        t_r = b - 1
    if t_r == b:
        t_r = b - 1
    ans = min(abs(t[t_l] - s[s_r]) + min(abs(t[t_l] - x), abs(s[s_r] - x)),
    abs(s[s_l] - t[t_r]) + min(abs(s[s_l] - x), abs(t[t_r] - x)),
    abs(s[s_l] - t[t_l]) + min(abs(s[s_l] - x), abs(t[t_l] - x)),
    abs(s[s_r] - t[t_r]) + min(abs(s[s_r] - x), abs(t[t_r] - x)),
    )
    
    print(ans)
### BUGGY CODE ###

N=int(input())
S=[input()for _ in'_'*N]
z=0
for k in range(-N,0):
	for t in range(N*N):
		i=t//N
		j=t%N
		if S[i][j+k]!=S[j][i+k]:
			break
	else:
		z+=N
print(z)


### FIXED CODE ###

N=int(input())
S=[input()for _ in'_'*N]
z=0
for k in range(-N,0):
	for t in range(N*N):
		i=t//N
		j=t%N
		if S[i][j+k]!=S[j][i+k]:
			break
	else:
		z+=N
print(z)
### BUGGY CODE ###

N,M = map(int,input().split())
ans = 0
for i in range(0,M+1,2):
  ans = max(ans, min((M-i)//2,N+i//2))
print(ans)

### FIXED CODE ###

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

if 2*N >= M:
  print(M//2)
  exit()
else:
  cnum = M-2*N
  print(N+cnum//4)
### BUGGY CODE ###

import sys

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    if n > max(primes):
      for i in range(max(primes) + 1, n + 1):
        if i % 2 == 0 or len([j for j in primes if i % j == 0]) > 0:
          continue
        primes.append(i)
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break

### FIXED CODE ###

import sys
import math

# Sieve of Eratosthenes
N = 999999
searchList = list(range(3, N + 1, 2))
primes = [2]
while True:
  top = searchList.pop(0)
  primes.append(top)
  if top > math.sqrt(N):
    break
  searchList = [s for s in searchList if s % top != 0]
primes.extend(searchList)

# solve
for line in sys.stdin:
  try:
    n = int(line)
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break
### BUGGY CODE ###

import sys

input = sys.stdin.readline
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, n):
    dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
print(dp[n - 1])


### FIXED CODE ###

import sys


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


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
    print(dp[n - 1])


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

class LinkedListNode:
    def __init__(self, key, prev_node, next_node):
        self.key = key
        self.prev_node = prev_node
        self.next_node = next_node

class LinkedList:
    def __init__(self):
        self.front_node = None
        self.last_node = None
        self.size = 0

    def insert(self, key):
        new_node = LinkedListNode(key, None, self.front_node)
        if self.front_node != None:
            self.front_node.prev_node = new_node
        self.front_node = new_node
        if self.last_node == None:
            self.last_node = new_node
        self.size += 1

    def delete(self, key):
        node = self.front_node
        while node != None:
            if node.key == key:
                if node == self.front_node:
                    self.front_node = self.front_node.next_node
                if node == self.last_node:
                    self.last_node = self.last_node.prev_node
                if node.prev_node != None:
                    node.prev_node.next_node = node.next_node
                if node.next_node != None:
                    node.next_node.prev_node = node.prev_node
                self.size -= 1
                break
            node = node.next_node

    def delete_first(self):
        if self.size == 0:
            return
        elif self.size == 1:
            self.front_node = None
            self.last_node = None
            self.size -= 1
        else:
            self.front_node = self.front_node.next_node
            self.front_node.prev_node = None
            self.size -= 1

    def delete_last(self):
        if self.size == 0:
            return
        elif self.size == 1:
            self.front_node = None
            self.last_node = None
            self.size -= 1
        else:
            self.last_node = self.last_node.prev_node
            self.last_node.next_node = None
            self.size -= 1

    def to_a(self):
        a = []
        node = self.front_node
        while node != None:
            a.append(node.key)
            node = node.next_node
        return a

l = LinkedList()
n = int(input())
for i in range(n):
    ins = input().split()
    command = ins[0]
    if command == "insert":
        x = int(ins[1])
        l.insert(x)
    elif command == "delete":
        x = int(ins[1])
        l.delete(x)
    elif command == "deleteFirst":
        l.delete_first()
    elif command == "deleteLast":
        l.delete_last()

print(" ".join(map(str, l.to_a())))

### FIXED CODE ###

import sys
from collections import deque

d = deque()
n = int(input())
lines = sys.stdin.readlines()
for i in range(n):
    ins = lines[i].split()
    command = ins[0]
    if command == "insert":
        d.appendleft(ins[1])
    elif command == "delete":
        try:
            d.remove(ins[1])
        except:
            pass
    elif command == "deleteFirst":
        d.popleft()
    elif command == "deleteLast":
        d.pop()

print(" ".join(d))
### BUGGY CODE ###

from bisect import*
import sys;input=sys.stdin.readline

def doevent(lis):
    global stop
    a,b=lis
    if b>=0:
        if stop=={-1}:
            stop=set()
        stop.add(b)
    else:
        if -b in stop:
            stop.remove(-b)
        if stop==set():
            stop={-1}
    return min(stop)

n,q=map(int,input().split())
event=[]
stop=set([-1])

for i in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x,x))
    event.append((t-x,-x))
event.sort(key=lambda x:x[0])

minlist=[doevent(i)for i in event] #時間をindexとしたminlist

for i in range(q):
    print(minlist[bisect_right(event,(int(input()),10**9))-1])


### FIXED CODE ###

import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))
    
event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop
        
print('\n'.join(map(str, ans)))