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

n = int(input())
a = list(map(int, input().split()))
# a = sorted(a)
a.sort()
if n == 1:
    print(1)
    exit()
if a[0] == 1:
    if a[1] == 1:
        print(0)
        exit()
    else:
        print(1)
        exit()
check = True
ans = 0
double = []
for i in range(n):
    if not i == 0:
        if a[i-1] == a[i]:
            double.append(a[i])
    for j in range(0, i):
        if not a[j] == 1:
            if a[j]*2 > a[i]:
                break
        if i == j:
            continue
        if a[i]%a[j] == 0:
            check = False
            break

    if check:
        ans += 1
        # print(i)
    check = True
# print(a)
# print(ans)
# print(double)
for i in set(double):
    ans -= a.count(i)
# ans -= len(set(double))
# ans -= len(double)
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)
m = max(a) + 1
dp = [False]*m
ans = 0
for ai in a:
    if dp[ai]:
        continue
    if c[ai] == 1:
        ans += 1
    for i in range(ai, m, ai):
        dp[i] = True
print(ans)
### BUGGY CODE ###

S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        amari[s % 2019] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

### FIXED CODE ###

S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))
### BUGGY CODE ###

def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N-M+1):
        ans = max(ans, sum(A[i:M+i]))
    ans = (ans+M) / 2
    
    return ans

print(solve())


### FIXED CODE ###

import itertools

def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    # スコアの累積和
    l = list(itertools.accumulate(A))

    score = sum(A[:M])
    for i in range(1, N-M):
        score = max(score, l[i+M] - l[i])
        
    ans = (M + score) / 2

    return ans

print(solve())
### BUGGY CODE ###

N,M=map(int,input().split())
nekotyann=[]
wanntyann=[]
ans="IMPOSSIBLE"
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        nekotyann.append(b)
    if b==N:
        wanntyann.append(a)
for i in range(len(wanntyann)):
    if wanntyann[i] in nekotyann:
        ans="POSSIBLE"
        break
print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
nekotyann=[0]*N
wanntyann=[0]*N
ans="IMPOSSIBLE"
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        nekotyann[b-1]+=1
    if b==N:
        wanntyann[a-1]+=1
for k in range(N):
    if nekotyann[k]!=0 and wanntyann[k]!=0:
        ans="POSSIBLE"
        break
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for q in range(Q):
    l, r = map(int, input().split())
    s = S[l-1:r]
    print(s.count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N)
for n in range(N-1):
    add = 1 if S[n:n+2] == "AC" else 0
    t[n+1] = t[n] + add
for q in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 1

    for a in As:
        ans *= a

    if ans > 10**18:
        print(-1)
        return
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 1
    if 0 in As:
        print(0)
        return

    for a in As:
        ans *= a
        if ans > 10**18:
            print(-1)
            return

    print(ans)


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

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

s=[tuple(map(int,input().split())) for _ in range(n)]

s.sort()

ans=[s[0]]

for i in range(1,n):
    for j in range(len(ans)):
        if s[i][0]+ans[j][0]<= W :
            ans.append((s[i][0]+ans[j][0],s[i][1]+ans[j][1]))

print(max(ans,key= lambda x : x[1])[1])




### FIXED CODE ###

n,W=map(int,input().split())
values=[]
weights=[]

for _ in range(n):

    a,b=map(int,input().split())
    weights.append(a)
    values.append(b)

ans=[[0]*(W+1) for _ in range(n)]

for i in range(0,n):
    for j in range(1,W+1):
        p=0
        if j>=weights[i] :
            p=ans[i-1][j-weights[i]]+values[i]
        ans[i][j]=max(ans[i-1][j],p)

print(ans[-1][W])
### BUGGY CODE ###

    
def main():
    N = int(input())
    P = list(map(int, input().split()))
    
    count = 0
    for i in range(N):
        flag = True
        for j in range(i):
            if P[i] > P[j]: 
                flag = False
                break

        if flag:
            count += 1
    print(count)
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    P = list(map(int, input().split()))
    
    count = 0
    k = 0
    for i in range(N):
        flag = True
        for j in range(k, i):
            if P[i] > P[j]: 
                flag = False
                break

        if flag:
            count += 1
            k = i
            
    print(count)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

A,B,C,K = (int(i) for i in input().split())

for i in range(K):
    tmpA = A
    tmpB = B
    A = B+C
    B = C+tmpA
    C = tmpA + tmpB

ans = A-B
if ans>10**8:
    print("Unfair")
else:
    print(ans)

### FIXED CODE ###

A,B,C,K = (int(i) for i in input().split())


if K%2 == 0:
    ans = A-B
else:
    ans = B-A

if ans>10**18:
    print("Unfair")
else:
    print(ans)
### BUGGY CODE ###

h, n = map(int, input().split())
c = [0]*n
m = [0]*n

mc = 0
for i in range(n):
    c[i], m[i] = map(int, input().split())
    if mc < c[i]:
        mc = c[i]
    
dp = [0]*(h+1+mc)
dpn = [0]*(h+1+mc)

while True:
    for i in range(len(dp)):
        for j in range(n):
            if i == c[j]:
                if dp[i] == 0 and dpn[i] == 0:
                    dpn[i] = m[j]
                elif dpn[i] > 0:
                    dpn[i] = min(m[j], dpn[i])
            elif i > c[j]:
                if dp[i-c[j]] > 0:
                    if dpn[i] == 0:
                        dpn[i] = dp[i-c[j]] + m[j]
                    else:
                        dpn[i] = min(dp[i-c[j]] + m[j], dpn[i])
    if dp == dpn:
        break
    dp = dpn
    dpn = dpn[:]

mi = 10**9    
for i in dpn[h:]:
    if i > 0 and i < mi:
        mi = i

print(mi)

### FIXED CODE ###

h, n = map(int, input().split())
c = [0]*n
m = [0]*n

mc = 0
for i in range(n):
    c[i], m[i] = map(int, input().split())
    if mc < c[i]:
        mc = c[i]
    
dp = [10**10]*(h+mc)
dp[0] = 0

for i in range(1, h + mc):
    dp[i] = min(dp[i-a] + b for a, b in zip(c, m))
        
print(min(dp[h:]))
### BUGGY CODE ###

n = int(input())
for i in range(1, n+1):
    x = 1
    count = 0
    while (x+1)**2 <= i-2:
        y = 1
        while x**2 + y**2 + x*y + x + y <= i-1:
            z = 1
            while x**2 + y**2 + z**2 +x*y + y*z + z*x <= i:
                if x**2 + y**2 + z**2 +x*y + y*z + z*x == i:
                    if x == y and y == z and z == x:
                        count += 1
                    elif x == y or y == z or z == 1:
                        count += 3
                    else:
                        count += 6
                    break
                else:
                    z += 1
            else:
                y += 1
                continue
            break
        else:
            x += 1
            continue
        break
    print(count)

### FIXED CODE ###

n = int(input())
ans = [0 for i in range(10050)]
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            f = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if f < 10050:
                ans[f] += 1
for i in range(n):
    print(ans[i+1])
### BUGGY CODE ###

def count_descending(nums):
    if not nums:
        return 0

    count = 1
    previous = nums[0]
    for i in range(1, len(nums)):
        if previous < nums[i]:
            return count
        else:
            count += 1
            previous = nums[i]

    return count


def max_move(nums):
    start = 0
    current_max = 0
    while start < len(nums):
        n = count_descending(nums[start:])
        current_max = max(current_max, n)
        start += n

    return current_max


def main():
    n = int(input())
    h = [int(x) for x in input().split()]

    print(max_move(h) - 1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def count_descending(nums, start):
    if start >= len(nums):
        return 0

    count = 1
    previous = nums[start]
    for i in range(start + 1, len(nums)):
        if previous < nums[i]:
            return count
        else:
            count += 1
            previous = nums[i]

    return count


def max_move(nums):
    start = 0
    current_max = 0
    while start < len(nums):
        n = count_descending(nums, start)
        current_max = max(current_max, n)
        start += n

    return current_max


def main():
    n = int(input())
    h = [int(x) for x in input().split()]

    print(max_move(h) - 1)


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

n,k = map(int,input().split())
field = list(map(int,input().split()))
dp = [float("inf")]*len(field)
dp[0] = 0
for i in range(0,n - 1):
  for j in range(1,k + 1):
    if i + j < n:
      dp[i + j] = min(dp[i + j],dp[i] + abs(field[i + j] - field[i]))
print(dp.pop())


### FIXED CODE ###

import numpy as np
n,k = map(int,input().split())
field = np.array(input().split(),np.int64)
dp = np.zeros(n,np.int64)
# numpyのブロードキャストとスライスを組み合わせることで1重のfor文で済ますという変態的なことをしてる
# ただ計算量がO(N)になっているかは謎
for i in range(1,n):
  left = max(0,i - k)
  dp[i] = (dp[left:i] + abs(field[left:i] - field[i])).min()
print(dp[-1])
### BUGGY CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


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

d = {}
for a in A:
    for x in make_divisors(a):
        d[x] = d.get(x, 0) + 1

print(sorted([(k,v) for k,v in d.items() if v >= N-1], key=lambda x: -x[0])[0][0])


### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

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

n = int(input())
left = []
right = []
for i in range(n):
    s = input()
    n0 = 0
    n1 = 0
    l = len(s)
    for j in range(l):
        if s[j] == "(":
            n0 += 1
        else:
            if n0 == 0:
                n1 += 1
            else:
                n0 -= 1
    if n0 > 0 or n1 > 0:
        if n0 >= n1:
            left.append([n1, n0])
        else:
            right.append([n0, n1])
 
left.sort()
right.sort()
 
def solve():
    nl0 = 0
    nl1 = 0
    for p in left:
        if p[0] > nl0:
            return False
        nl0 -= p[0]
        nl0 += p[1]
    nr0 = 0
    nr1 = 0
    for p in right:
        if p[0] > nr1:
            return False
        nr1 -= p[0]
        nr1 += p[1]
    if nl0 == nr1:
        return True
    else:
        return False
 
if solve():
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())
left = []
right = []
for i in range(n):
    s = input()
    n0 = 0
    n1 = 0
    l = len(s)
    for j in range(l):
        if s[j] == "(":
            n0 += 1
        else:
            if n0 == 0:
                n1 += 1
            else:
                n0 -= 1
    if n0 > 0 or n1 > 0:
        if n0 >= n1:
            left.append([n1, n0])
        else:
            right.append([n0, n1])
 
left.sort()
right.sort()
 
def solve():
    nl0 = 0
    nl1 = 0
    for p in left:
        if p[0] > nl0:
            return False
        nl0 -= p[0]
        nl0 += p[1]
    nr0 = 0
    nr1 = 0
    for p in right:
        if p[0] > nr1:
            return False
        nr1 -= p[0]
        nr1 += p[1]
    if nl0 == nr1:
        return True
    else:
        return False
 
if solve():
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

for i in range(N):
    m=max(A[i:])
    for j in range(N-i-A[i]):
        k=i+j+A[i]

        if A[i]+A[k]==k-i:
            count = count+1
            #print("{} {}".format(i+1,k+1))
        if A[i]+m+i<k:
            break


print("{}".format(count))


### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
count=0
L = [0]*N
R = [0]*N
N2=2*N
hash_L=[0]*N2
hash_R=[0]*N2

sheet_L=[0]*N2
sheet_R=[0]*N2
for i in range(N):
    L[i]=A[i]+i+1
    if L[i]<N2:
        if sheet_L[L[i]]==0:
            hash_L[L[i]]=L[i]
            sheet_L[L[i]]=1
        else:
            sheet_L[L[i]]=sheet_L[L[i]]+1

    R[i]=-A[i]+i+1
    if R[i]>0:
        if sheet_R[R[i]]==0:
            hash_R[R[i]]=R[i]
            sheet_R[R[i]]=1
        else:
            sheet_R[R[i]]=sheet_R[R[i]]+1


for i in range(2*N):
    if not hash_L[i]==0:
        if hash_L[i]==hash_R[i]:
            count=count+sheet_L[i]*sheet_R[i]
#print("{}".format(hash_L))
#print("{}".format(hash_R))
print("{}".format(count))
### BUGGY CODE ###

import numpy as np
 
n = int(input())
A = np.array(list(map(int, input().split(' '))))
 
A_unique = np.unique(A)
num_dict = {}
total = 0
for a in A_unique:
  tmp = np.count_nonzero(A==a)
  num_dict[a] = (tmp*(tmp-1)/2, (tmp-1)*(tmp-2)/2)
  total += tmp*(tmp-1)/2

for k in range(n):
  print(int(total - num_dict[A[k]][0] + num_dict[A[k]][1]))

### FIXED CODE ###

import collections

n = int(input())
A = list(map(int, input().split(' ')))
 
c = dict(collections.Counter(A))
num_dict = {}
total = 0
for a, count in c.items():
  num_dict[a] = (count*(count-1)/2, (count-1)*(count-2)/2)
  total += count*(count-1)/2

ans_dict = {}
for a in c.keys():
  ans_dict[a] = total - num_dict[a][0] + num_dict[a][1]

for k in range(n):
  print(int(ans_dict[A[k]]))
### BUGGY CODE ###

def solve(s1,s2):
    rows=len(s1)
    cols=len(s2)
    dp=[[0]*(cols+1) for i in range(rows+1)]
    for i in range(1,rows+1):
        for j in range(1,cols+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])
                
    max_len=dp[rows][cols]
    result=[""]*(max_len+1)
    result[max_len]=""
    i=rows
    j=cols
    while i>0 and j>0:
        if s1[i-1]==s2[j-1]:
            result[max_len-1]=s1[i-1]
            max_len -=1
            i -=1
            j -=1
        elif dp[i-1][j]>dp[i][j-1]:
            i -=1
        else:
            j -=1
    return "".join(result)
            
                
#     if i==n or j==m:
#         return result
#     if s1[i]==s2[j]:
#         result +=s1[i]
#         return result+solve(s1,s2,n,m,i+1,j+1,result)
#     else:
#         left=solve(s1,s2,n,m,i+1,j,result)
#         right=solve(s1,s2,n,m,i,j+1,result)
#         if left:
#             result
        
        ##return max(solve(s1,s2,n,m,i+1,j,result),solve(s1,s2,n,m,i,j+1,result))
s1=input()
s2=input()
n=len(s1)
m=len(s2)
result=""
print(solve(s1,s2))

### FIXED CODE ###

def solve(s1,s2):
    rows=len(s1)
    cols=len(s2)
    dp=[[0]*(cols+1) for i in range(rows+1)]
    for i in range(1,rows+1):
        for j in range(1,cols+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])
                
    max_len=dp[rows][cols]
    result=[""]*(max_len+1)
    result[max_len]=""
    i=rows
    j=cols
    while i>0 and j>0:
        if s1[i-1]==s2[j-1]:
            result[max_len-1]=s1[i-1]
            max_len -=1
            i -=1
            j -=1
        elif dp[i-1][j]>dp[i][j-1]:
            i -=1
        else:
            j -=1
    return "".join(result)
            
                
#     if i==n or j==m:
#         return result
#     if s1[i]==s2[j]:
#         result +=s1[i]
#         return result+solve(s1,s2,n,m,i+1,j+1,result)
#     else:
#         left=solve(s1,s2,n,m,i+1,j,result)
#         right=solve(s1,s2,n,m,i,j+1,result)
#         if left:
#             result
        
        ##return max(solve(s1,s2,n,m,i+1,j,result),solve(s1,s2,n,m,i,j+1,result))
s1=input()
s2=input()
n=len(s1)
m=len(s2)
result=""
print(solve(s1,s2))
### BUGGY CODE ###

import sys


import sys
input = sys.stdin.readline

N = int(input())
A=list(map(int, input().split()))
ans = 0
for i in range(N):
    S = A[:]
    del(S[i])
    for j in range(N -1):
        for k in range(j+1,N -1):
            if(S[j] == S[k]):
                ans += 1
            else:
                pass
    print(ans)
    ans = 0


### FIXED CODE ###

import collections

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

C = collections.Counter(a)
total = 0
for i in C.keys():
    total += C[i] * (C[i] - 1) // 2
for i in range(n):
    A = a[i]
    print(total - C[A] + 1)
### BUGGY CODE ###

import bisect
a,b,q = map(int,input().split())
s = [-10**11]+[int(input()) for _ in range(a)]+[10**11]
t = [-10**11]+[int(input()) for _ in range(b)]+[10**11]
for i in range(q):
  ans = 10**11
  x = int(input())
  l = bisect.bisect(s,x)
  m = bisect.bisect(t,x)
  arr = [[s[l-1],s[l]],[t[m-1],t[m]]]
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      S += abs(now-arr[j][i >> j & 1])
      now = arr[j][i >> j & 1]
    ans = min(ans,S)
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      S += abs(now-arr[1-j][i >> j & 1])
      now = arr[1-j][i >> j & 1]
    ans = min(ans,S)
  print(ans)

### FIXED CODE ###

import bisect
a,b,q = map(int,input().split())
s = [-10**11]+[int(input()) for _ in range(a)]+[10**11]
t = [-10**11]+[int(input()) for _ in range(b)]+[10**11]
for i in range(q):
  ans = 10**11
  x = int(input())
  l = bisect.bisect(s,x)
  m = bisect.bisect(t,x)
  arr = [[s[l-1],s[l]],[t[m-1],t[m]]]
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      t0 = now-arr[j][i >> j & 1]
      S += t0*((-1)**(t0<0))
      now -= t0
    if ans > S:
      ans = S
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      t0 = now-arr[1-j][i >> j & 1]
      S += t0*((-1)**(t0<0))
      now -= t0
    if ans > S:
      ans = S
  print(ans)
### BUGGY CODE ###

N=int(input())
import math
for i in range(1,N+1):
    ans=0
    for x in range(1,35):
        for y in range(1,35):
            a=-(3*(x*x)+3*(y*y)+2*x*y)/4+i
            if a>0:
                b=(math.sqrt(a)-(x+y)/2)
                if b>0 and b%1==0.0:
                    ans+=1

    print(ans)



### FIXED CODE ###

N=int(input())
li=[0]*N
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            temp=x**2+y**2+z**2+x*y+y*z+z*x
            if temp<=N:
                li[temp-1]+=1
for i in range(N):
    print(li[i])
### BUGGY CODE ###

n = int(input())
d = list(map(int,input().split()))
d.sort()
ans=0
for k in range(1,d[-1]+1):
    abc=[k>i for i in d]
    arc=[k<=i for i in d]
    if sum(arc)==sum(abc):
        ans+=1
print(ans)

### FIXED CODE ###

n = int(input())
d = list(map(int,input().split()))
d.sort()
print(d[n//2]-d[(n//2)-1])
### BUGGY CODE ###

import sys
import numpy as np
from functools import lru_cache
from collections import deque

#nput = sys.stdin.readline
#sys.setrecursionlimit(10 ** 5)

H,W = map(int,input().split())
grid = [list(input()) for i in range(H)]
dp = np.zeros([H + 1,W + 1],dtype = int)
dp[0][0] = 1
div = (10 ** 9) + 7

for i in range(H):
  for j in range(W):
    if i + 1 < H and grid[i + 1][j] == ".":
      dp[i + 1][j] += (dp[i][j] % div)
    if j + 1 < W and grid[i][j + 1] == ".":
      dp[i][j + 1] += (dp[i][j] % div)

print(dp[H - 1][W - 1] % div)

### FIXED CODE ###

import sys
import numpy as np
from functools import lru_cache
from collections import deque

#input = sys.stdin.readline
#sys.setrecursionlimit(10 ** 5)

H,W = map(int,input().split())
grid = [list(input()) for i in range(H)]
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][0] = 1
mod = (10 ** 9) + 7

for i in range(H):
  for j in range(W):
    if i > 0 or j > 0:
      if grid[i][j] == "#":
        dp[i][j] = 0
      else:
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod

print(dp[H - 1][W - 1])
#print(dp)
### BUGGY CODE ###

import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) 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 II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,Q=LI()
HQ=[]
EVS=[]
for i in range(N):
    S,T,X=LI()
    EVS.append((S-0.5-X, 1, X))
    EVS.append((T-0.5-X, 0, X))
for i in range(Q):
    D=II()
    EVS.append((D, 2, D))
EVS.sort()

st=set()
PQ=[]
for time, ev, loc in EVS:
    if ev == 1:
        heapq.heappush(PQ, loc)
        st.add(loc)
    elif ev == 0:
        st.remove(loc)
    else:
        while PQ and PQ[0] not in st:
            heapq.heappop(PQ)
        if PQ:
            print(PQ[0])
        else:
            print(-1)


### FIXED CODE ###

import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) 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 II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,Q=LI()
HQ=[]
EVS=[]
for i in range(N):
    S,T,X=LI()
    EVS.append((S-0.5-X, 1, X))
    EVS.append((T-0.5-X, 0, X))
for i in range(Q):
    D=II()
    EVS.append((D, 2, D))
EVS.sort()

st=set()
PQ=[]
for time, ev, loc in EVS:
    if ev == 1:
        heapq.heappush(PQ, loc)
        st.add(loc)
    elif ev == 0:
        st.remove(loc)
    else:
        while PQ and PQ[0] not in st:
            heapq.heappop(PQ)
        if PQ:
            print(PQ[0])
        else:
            print(-1)