Harryxun/stf_run huggingface dataset:
n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(60):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
            n_0 = n-n_1
            
        ans += n_0*n_1
        ans %= 10**9+7
print(ans)

### FIXED CODE ###


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()
P, Y = [], []
for i in range(M):
    j, k = LI()
    P.append(j)
    Y.append(k)

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**5)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append(y)

#  print(city_records)

for i in range(len(city_records)):
    if city_records[i] == []:
        continue
    city_records[i].sort()

#  print(city_records)

for p, y in zip(P, Y):
    #  order = (city_records[p].index(y)) + 1
    order = bisect.bisect_left(city_records[p], y) + 1
    print(str(p).zfill(6) + str(order).zfill(6))


### FIXED CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()
P, Y = [], []
for i in range(M):
    j, k = LI()
    P.append(j)
    Y.append(k)

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**6)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append(y)

#  print(city_records)

for i in range(len(city_records)):
    if city_records[i] == []:
        continue
    city_records[i].sort()

#  print(city_records)

for p, y in zip(P, Y):
    #  order = (city_records[p].index(y)) + 1
    order = bisect.bisect_left(city_records[p], y) + 1
    print(str(p).zfill(6) + str(order).zfill(6))
if a % 2 and (b % 2): print("Odd")
else: print("Even")

### FIXED CODE ###

a, b = map(int, input().split())
if a % 2 and (b % 2): print("Odd")
else: print("Even")
while True:
    H, W = [int(i) for i in input().split()]

    if H + W % == 0
        print('#')

    else:
        print('.')

print

        

### FIXED CODE ###

while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
       break

    for h in range(H):
        for w in range(W):
            if (h + w) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')

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

list.sort()

if n%2==0:
    count=0
else: count=1
while count<n and list[count]==list[count+1]:
    count+=2
if count>=len(list):
    if n%2==0:
        print(int(2**(n/2)))
    else:
        print(int(2**((n-1)/2)))
else:
    print(0)

### FIXED CODE ###

import sys
n=int(input())
array=list(map(int, input().split()))

if not (0<=min(array) and max(array)<n):
    print(0)
    sys.exit()

if n%2==0:
    if (n**2)/2 != sum(array):
        print(0)
        sys.exit()
else:
    if (n**2-1)/2 != sum(array):
        print(0)
        sys.exit()

sub_list=list(set(array))

if n%2==0:
    if int(n/2)==len(sub_list):
        print((2 ** int(n / 2))%(10**9 + 7))
    else:
        print(0)
else:
    if int(n/2)==len(sub_list)-1:
        print((2 ** int(n / 2)) % (10 ** 9 + 7))
    else:
        print(0)
n=int(input())
result=1000000000000
for i in range(n):
  nn=n/(i+1)
  if (nn.is_integer() and result>nn+i-1):
    result=nn+i-1
    print(nn)
    print(i+1)
print(result)

### FIXED CODE ###

a,b=map(int,input().split())
if a>9 or b>9:
  print(-1)
else:
  print(a*b)
N = input()
a = int(N[1])
b = int(N[2])
c = int(N[3])

print(a+b+c)



### FIXED CODE ###

N = input()
a = int(N[0])+int(N[1])+int(N[2])

print(a)
print(abs(int(input())-int(input())*2)

### FIXED CODE ###

print(-1*(int(input())-int(input())*2))
ans=""
while True:
	try:
		info=input()
	except:
		break
	if ans!="":
		ans+="\n"
    info_2=info.split()
    ans+=str(int(info_2[0])+int(info_2[1]))
print(ans)

### FIXED CODE ###

ans=""
while True:
	try:
		info=input()
	except:
		break
	if ans!="":
		ans+="\n"
	info_2=info.split()
	ans+=str(int(info_2[0])+int(info_2[1]))
print(ans)
n, k = map(int,input().split())
lst = list(map(int, input().split()))
#cnt = 0
ans = []
"""
def arr(m,a):
  if m==n:
    print(a+sum([1 for j in range(n) if not j+m>n and sum(lst[j:j+m])>=k]))
    return
  return arr(m+1,a+sum([1 for j in range(n) if not j+m>n and sum(lst[j:j+m])>=k]))
  
arr(1,0)
"""

for i in range(1,n+1):
  ans += [1 for j in range(n) if not j+i>n and sum(lst[j:j+i])>=k]
print(sum(ans))
"""
  for j in range(n):
    if j+i > n:
      continue
    if sum(lst[j:j+i]) >= k:
      cnt += 1
      #print(j,j+1,sum(lst[j:j+i]),cnt)
"""

#ans += [lst[j] for j in lst if sum(lst) >= k:]


  

### FIXED CODE ###

x, a = map(int,input().split())
if a > x:
  print(0)
else:
  print(10)
n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * n

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i-1]))
    # 一番目の足場では一つ前しか存在しない
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i -2]))

print(dp[n-1])


### FIXED CODE ###

N = int(input())
H = [int(x) for x in input().split()]
dp = [0] * N
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
print(dp[N-1])
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from heapq import heappush,heappop,heapify

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(W) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[(1,1),(-1,1),(1,-1),(-1,-1),(2,0),(-2,0),(0,2),(0,-2),(1,2),(-1,2),(1,-2),(-1,-2),(2,1),(-2,1),(2,-1),(-2,-1),(2,2),(-2,2),(2,-2),(-2,-2)]

#隣接リスト
al=defaultdict(lambda: [])

for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            continue
        for dh,dw in D:
            if 0<=h+dh<H and 0<=w+dw<W:
                if S[h+dh][w+dw]==".":
                    al[(h,w)].append((0,h+dh,w+dw))    #コスト,toの座標
        for dh,dw in WARP:
            if 0<=h+dh<H and 0<=w+dw<W:
                if S[h+dh][w+dw]==".":
                    al[(h,w)].append((1,h+dh,w+dw))    #コスト,toの座標 ワープはコスト1

d=defaultdict(lambda: float("inf"))    #(h,w):kyori スタート地点からその点までの距離

def dij(x,y):
    d[(x,y)]=0
    hq=[]
    heappush(hq,(0,x,y))
    while hq:
        cost,fro_x,fro_y=heappop(hq)
        for cost,to_x,to_y in al[(fro_x,fro_y)]:
            if d[(to_x,to_y)]==0: continue
            alt=d[(fro_x,fro_y)]+cost
            if alt<d[(to_x,to_y)]:
                d[(to_x,to_y)]=alt
                heappush(hq, (alt,to_x,to_y))

dij(CH,CW)
if d[(DH,DW)]==float("inf"):
    print -1
else:
    print d[(DH,DW)]


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(H) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[]
for dh in range(-2,3):
    for dw in range(-2,3):
        if abs(dh)+abs(dw)<=1: continue
        WARP.append((dh,dw))

d=defaultdict(lambda: float("inf")) #スタート地点から各マスまでの距離

q=deque()
q.append((0,CH,CW))
d[(CH,CW)]=0

while q:
    kyori, fro_h, fro_w=q.popleft()
    if d[(fro_h, fro_w)]<kyori: continue
    #歩いて移動
    for dh,dw in D:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori
                q.appendleft((kyori, to_h, to_w))
    #ワープ
    for dh,dw in WARP:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori+1 < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori+1
                q.append((kyori+1, to_h, to_w))

if d[(DH,DW)]==float("inf"):
    print -1
else:
    print d[(DH,DW)]
s = input()

ans = 0

for i in [0, 1, 2]:
  if s[i] == s[i + 1]:
    ans += 1
  else:
  
if ans >= 1:
  print('Bad')
else:
  print('Good')


### FIXED CODE ###

s = input()

ans = 0

for i in [0, 1, 2]:
  if s[i] == s[i + 1]:
    ans += 1
    
if ans >= 1:
  print('Bad')
else:
  print('Good')
import sys
input = sys.stdin.readline

X,A =list(map(int,input().split()))
print(X//A*10)


### FIXED CODE ###

import sys
input = sys.stdin.readline

X,A =list(map(int,input().split()))
print(10 if A <= X else 0)
k = int(input())
x = int(input())

if k*500 < x:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

k,x=(int(x) for x in input().split())

if k*500 < x:
    print("No")
else:
    print("Yes")
import math

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
d = [[math.inf]*N for _ in range(N)]
for a, b in AB:
    d[a-1][b-1] = 1


def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


warshall_floyd(d)
min_d = min([d[i][i] for i in range(N)])
if min_d == math.inf:
    print(-1)
else:
    ans = []
    for i in range(N):
        if d[i][i] == min_d:
            ans.append(i + 1)
    if len(ans) != min_d:
        raise ValueError('同じループが二つ')
    print(min_d)
    for i in ans:
        print(i)


### FIXED CODE ###

import math
import sys
from collections import deque, defaultdict

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
g = [set() for _ in range(N)]
for a, b in AB:
    g[a - 1].add(b - 1)


def find_loop(s, subnode):
    q = deque([(s, {s})])
    visited = defaultdict(lambda: math.inf)
    while len(q) > 0:
        node, p = q.popleft()
        for to_node in g[node] & subnode:
            if to_node == s:
                return p
            if visited[to_node] > len(p):
                visited[to_node] = len(p)
                q.append((to_node, p | {to_node}))
    return -1


V = set(range(N))
for i in range(N):
    subnode = find_loop(i, V)
    if subnode != -1:
        break
if subnode == -1:
    print(-1)
    sys.exit()


while True:
    # 条件判定
    flg = True
    for i in subnode:
        if len(g[i] & subnode) != 1:
            flg = False
            s = i
            break
    if flg:
        break
    subnode = find_loop(s, subnode)

print(len(subnode))
for node in subnode:
    print(node+1)
a = []
for i in range(5):
    a.append(int(input()))
 
b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
      　num = a[j]%10
        c.append(num)
        b.append(a[j] - c[j])
        
 
b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10
 
print(b_sum + c_sum)

### FIXED CODE ###

a = []
for i in range(5):
    a.append(int(input()))

b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
        c.append(a[j] % 10)
        b.append(a[j] - c[j])
        

b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10

print(b_sum + c_sum)
Flag =  0 
S = input()
SA = [str(c) for c in S]
#A = list(['A','A','A'])
#B = list(['B','B','B'])
S1 = SA[1]
S2 = SA[2]
S3 = SA[3]
if(S1 == S2 == S3):
    print("No")
else:
    print("Yes")

### FIXED CODE ###

Flag =  0 
S = input()
SA = [str(c) for c in S]
#A = list(['A','A','A'])
#B = list(['B','B','B'])
S1 = SA[0]
S2 = SA[1]
S3 = SA[2]
if(S1 == S2 == S3):
    print("No")
else:
    print("Yes")
#!usr/bin/env python3


from collections import defaultdict

def main():
    #Read stdin
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    #Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t,w))

    #initialized
    visited = []
    #unseen = [R]
    d = {}
    d[0] = 0
    q = [R]
    while q != []:
        u = q.pop(0)
        if u not in visited:
            for v in G[u]:
                if v[0] not in visited:
                    d[v[0]] = d[u] + v[1]
                    q.append(v[0])
            visited.append(u)

    for k in d.keys():
        print(d[k])

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict
from collections import deque
from sys import stdin
#time 2.49
def sp(G,R,V):
    d = {}
    INF = float('inf')
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = deque([(0, R)])
    while q:
        (cost, v) = q.popleft()
        for (u, c) in G[v].items():
            if d[u] > d[v] + c:
                d[u] = d[v] + c
                q.append((d[u], u))
    return d

V, E, R = [int(x) for x in stdin.readline().split()]
G = defaultdict(dict)
for case in range(E):
    s, t, w = [int(x) for x in stdin.readline().split()]
    G[s][t] = w
d = sp(G, R, V)
for k in range(V):
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])
N, M =map(int, input().split())
a, b = [0]*N, [0]*N
c, d = [0]*N, [0]*N
ans = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    

for i in range(N):
    length = 10**9
    ind = 0
    for j in range(M):
        man =  abs(a[i] - c[j])+abs(b[i] - d[j])
        if length > man:
            length = man
            ind = j+1
    ans.append(ind)

for i in ans:
    print(i)

### FIXED CODE ###

N, M =map(int, input().split())
a, b = [0]*N, [0]*N
c, d = [0]*M, [0]*M
ans = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    

for i in range(N):
    length = 10**9
    ind = 0
    for j in range(M):
        man =  abs(a[i] - c[j])+abs(b[i] - d[j])
        if length > man:
            length = man
            ind = j+1
    ans.append(ind)

for i in ans:
    print(i)
import sys
from collections import deque
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
r = int(str(N)[:-1])

if r in [2, 4, 5, 7]:
    print('hon')
elif r in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')



### FIXED CODE ###

import sys
from collections import deque
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
r = -1
if 0 < N < 10:
    r = N
else:
    r = int(str(N)[-1])

if r in [2, 4, 5, 7, 9]:
    print('hon')
elif r in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')
def insertionSort(A, n, g):
    global cnt 

    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt+=1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    #g = 3
    #g = n // 2 * 2
    g = 2
    #m = max(n // g,1)
    #m = min(m, 100)
    #print(m)  # 1行目
    #G = list(range(g*m,g,-g))
    G = [1]
    m = 1
    for i in range(1,101):
        # gの2乗分ずつGのリスト値を変えていく
        # mは結果のリストから取得 
        #print("g**i:{} ,n:{}".format(g**i, n))
        if g**i <= n:
            m = i+1
            G.append(g**i)
            g += 1
        else:
            break
    G.reverse() 
    print(m)  # 1行目
    print(" ".join(list(map(str,G))))  # 2行目
    for i in range(0,m):
        insertionSort(A, n, G[i])
    print(cnt)  # 3行目
    for i in range(0,len(A)):
        print(A[i]) # 4行目以降

cnt = 0
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

shellSort(A,n)


### FIXED CODE ###

def insertionSort(A, n, g):
    global cnt 

    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt+=1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    g = 1
    G = [1]
    m = 1
    for i in range(1,101):
        tmp = G[i-1]+(3)**i
        if tmp <= n:
            m = i+1
            G.append(tmp)
            g += 1
        else:
            break
    G.reverse() 
    print(m)  # 1行目
    print(" ".join(list(map(str,G))))  # 2行目

    for i in range(0,m):
        insertionSort(A, n, G[i])
    print(cnt)  # 3行目
    for i in range(0,len(A)):
        print(A[i]) # 4行目以降

cnt = 0
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellSort(A,n)
n=int(input())
l=[int(c) for c in input().spilt()]
ans=0
mod=10**9+7
for i in range(60):
  s=sum(a>>i&1 for a in l)
  ans+=s*(n-s)<<i%mod
  ans%=mod
print(ans)


### FIXED CODE ###

n=int(input())
l=[int(c) for c in input().split()]
ans=0
mod=10**9+7
for i in range(60):
  s=sum(a>>i&1 for a in l)
  ans+=s*(n-s)<<i%mod
  ans%=mod
print(ans)
x,y,z = input()
print(z,y,x)

### FIXED CODE ###

x,y,z = map(int,input().split())
print(z,x,y)
from collections import deque
n, m = map(int, input().split())

g = [[] for i in range(n)]

for i in range(m):
  u, v = map(int, input().split())
  u, v = u-1, v-1
  g[u].append(v)
# print(g)

s, t = map(int, input().split())
s, t = s-1, t-1

visited = [[-1]*3 for j in range(n)]

l = 0
queue = deque([[s, l]])
visited[s][l] = 0
while queue:
  x, l = queue.popleft()
  if [x, l] == [t, 0]:
    print(visited[x][l]//3)
    exit()
  for x_ in g[x]:
    new_x, new_l = x_, (l+1)%3
    if visited[new_x][new_l] == -1:
      visited[new_x][new_l] = visited[x][l]+1
      queue.append([new_x, new_l])
    
print(visited[t][0])

### FIXED CODE ###

n = int(input())
ds = list(map(int, input().split()))
ds.sort()
#print(ds)

abc = ds[:n//2]
arc = ds[n//2:]
#print(abc)
#print(arc)

print(min(arc)-max(abc))
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from collections import defaultdict
    N, Q = MI()
    event = []
    hash = defaultdict(int)
    for _ in range(N):
        s, t, x = MI()
        event.append((s - x, 1, x))
        event.append((t - x, -1, x))
        hash[x] = 0

    for _ in range(Q):
        d = I()
        event.append((d, 0))

    event.sort(key=lambda x: x[0])
    occur = set()
    for e in event:
        if e[1] == 1:
            occur.add(e[2])
        elif e[1] == -1:
            occur.remove(e[2])
        # クエリ
        elif e[1] == 0:
            if occur:
                print(min(occur))
            else:
                print(-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    import heapq
    N, Q = MI()
    event = []
    for _ in range(N):
        s, t, x = MI()
        event.append((s - x-0.5, 1, x))
        event.append((t - x-0.5, -1, x))

    for _ in range(Q):
        d = I()
        event.append((d, 0))

    event.sort(key=lambda x: x[0])
    occur = set()
    occur_priority = []
    for e in event:
        if e[1] == 1:
            occur.add(e[2])
            heapq.heappush(occur_priority, e[2])
        elif e[1] == -1:
            if e[2] in occur:
                occur.remove(e[2])
        # クエリ
        elif e[1] == 0:
            if occur:
                while 1:
                    if occur_priority[0] in occur:
                        min_occur = occur_priority[0]
                        break
                    else:
                        heapq.heappop(occur_priority)
                print(min_occur)
            else:
                print(-1)


if __name__ == '__main__':
    main()
import math
print(int(math.sqrt(x)))
for i in range(2, int(math.sqrt(x)) + 2):
    if x % i == 0:
        x += 1
print(x)

### FIXED CODE ###

n = int(input())
for i in range(n, 100004):
    flag = 0
    for j in range(2, int(i**0.5) + 1):
        if i % j == 0:
            flag = 1
            break
    if flag == 0:
        print(i)
        break
import collections
n=int(input())
string_list=[input() for i in range(n)]
c = collections.Counter(string_list)
print(len(c))

### FIXED CODE ###

s,w = map(int,input().split())
if s <=w:
    print("unsafe")
else:
    print("safe")
n = int(input())
print(r**2)

### FIXED CODE ###

r = int(input())
print(r**2)
n = int(input())
list_h = list(map(int, input().split()))

# 左から走査する
for i in reversed(range(1, n)):
    print(list_h, i)
    l, r = list_h[i-1], list_h[i]

    #左が小さい場合
    if l <= r:
        continue

    #一個だけ左が大きい場合
    elif l - 1 == r:
        list_h[i-1] = list_h[i-1] -1
        continue
    #あかんパターン
    else:
        print("No")
        exit()

print("YES")

### FIXED CODE ###

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

# 右から左へ走査する
for i in reversed(range(1, n)):
    l, r = list_h[i-1], list_h[i]

    #左が小さい場合
    if l <= r:
        continue

    #一個だけ左が大きい場合
    elif l - 1 == r:
        list_h[i-1] = list_h[i-1] -1
        continue

    #あかんパターン
    else:
        print("No")
        exit()

print("Yes")