Harryxun/sft_time huggingface dataset:
### 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):
        ans += A[i]*A[j]
print(ans%(10**9+7))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
ans = 0

for i in range(N):
  sum_A = sum_A - A[i]
  
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))
### BUGGY CODE ###

import random
from copy import deepcopy

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]

ans = []
last = [0]*26
for i in range(d):
    ma_po = -10**10
    ma_di = 0
    for j in range(26):
        po = s[i][j]
        for k in range(26):
            if k == j:
                continue
            po -= c[k]*(i+1-last[k])
        if po > ma_po:
            ma_po = po
            ma_di = j
    last[ma_di] = i+1
    ans.append(ma_di+1)

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans,ma
    li = deepcopy(ans)
    D = random.randrange(d)
    Q = random.randrange(26)
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)
        ma = score(li)

for i in range(30000):
    random_search()

for i in ans:
    print(i)

### FIXED CODE ###

import random

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(365)]

for i in range(d):
    print(random.randrange(1, 27, 1))
### BUGGY CODE ###

def loop(n, a):
    for i in range(n):
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp
    

n = int(input())
a = [int(input()) for i in range(n)]
 
loop(n, a)


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
b_max = b[-1]
b.pop(-1)
b_2max = b[-1]

for i in a:
    if i == b_max:
        print(b_2max)
    else:
        print(b_max)
### BUGGY CODE ###

X,Y,Z,K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()


array = []

for a in range(min(K,len(A))):
  for b in range(min(K,len(B))):
    for c in range(min(K,len(C))):
      array.append(A[a]+B[b]+C[c])

array.sort()
array.reverse()
for i in range(K):
  print(array[i])

### FIXED CODE ###

from heapq import heappop, heappush,heapify
X,Y,Z,K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
H = []
heappush(H,[-1*(A[0]+B[0]+C[0]),0,0,0])
count = 1
memo = []
while H and count <= K:
  tmp,i,j,k = heappop(H)
  print(-1*tmp)
  count += 1
  if i+1 < X and ((i+1,j,k) not in memo):
    heappush(H,[-1*(A[i+1]+B[j]+C[k]),i+1,j,k])
    memo.append((i+1,j,k))
  if j+1 < Y and ((i,j+1,k) not in memo):
    heappush(H,[-1*(A[i]+B[j+1]+C[k]),i,j+1,k])
    memo.append((i,j+1,k))
  if k+1 < Z and ((i,j,k+1) not in memo):
    heappush(H,[-1*(A[i]+B[j]+C[k+1]),i,j,k+1])
    memo.append((i,j,k+1))
### BUGGY CODE ###

N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
if S[0] == "0":
    ans = sum(L[:2*K])
    for k in range(l-2*K+1):
        if k%2 == 1:
            ans = max(ans,sum(L[k:k+2*K+1]))
else:
    ans = sum(L[:2*K+1])
    for k in range(l-2*K+1):
        if k%2 == 0:
            ans = max(ans,sum(L[k:k+2*K+1]))
print(ans)


### FIXED CODE ###

N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
A = [0 for k in range(l+2)]

for k in range(l):
    A[k+1] = A[k] + L[k]
A[l+1] = A[l]
if S[0] == "0":
    ans = A[min(l,2*K)]
    if l%2 == 1:
        for k in range(l-2*K+1):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
else:
    ans = A[min(l,2*K+1)]
    if l%2 == 1:
        for k in range(l-2*K):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K+1):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])

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

import sys
def rec(N,dp,i,j,k):
    if dp[i][j][k]>=0.0:return dp[i][j][k]
    if all([i==0,j==0,k==0]):return 0.0
    res=0.0
    if i>0:res+=rec(N,dp,i-1,j,k)*i
    if j>0:res+=rec(N,dp,i+1,j-1,k)*j
    if k>0:res+=rec(N,dp,i,j+1,k-1)*k
    res+=N
    res*=1.0/(i+j+k)
    dp[i][j][k]=res
    return dp[i][j][k]
def main():
    N=int(sys.stdin.readline())
    a=tuple(map(int,sys.stdin.readline().split()))
    n1,n2,n3=a.count(1),a.count(2),a.count(3)
    dp=[[[-1.0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N+1)]
    print(rec(N,dp,n1,n2,n3))
if __name__=='__main__':main()


### FIXED CODE ###

import sys
def rec(N,dp,i,j,k):
    if dp[i][j][k]>=0.0:return dp[i][j][k]
    if all([i==0,j==0,k==0]):return 0.0
    res=0.0
    if i>0:res+=rec(N,dp,i-1,j,k)*i
    if j>0:res+=rec(N,dp,i+1,j-1,k)*j
    if k>0:res+=rec(N,dp,i,j+1,k-1)*k
    res=(res+N)*1.0/(i+j+k)
    dp[i][j][k]=res
    return dp[i][j][k]
def main():
    N=int(sys.stdin.readline())
    a=tuple(map(int,sys.stdin.readline().split()))
    n1,n2,n3=a.count(1),a.count(2),a.count(3)
    dp=[[[-1.0 for _ in range(n3+1)] for _ in range(n2+n3+1)] for _ in range(n1+n2+n3+1)]
    print(rec(N,dp,n1,n2,n3))
if __name__=='__main__':main()
### BUGGY CODE ###

s= input()
t = input()
ls = len(s)
lt = len(t)
dp = [["" for _ in range(lt+1) ]  for _ in range(ls+1)] #dp[i][j] sがi文字目,tがj文字目まででのLCS
for ids in range(1,ls+1):
    for idt in range(1,lt + 1):
        #一致してたら文字を足す
        if s[ids-1] == t[idt-1]:
            dp[ids][idt] = dp[ids-1][idt-1] + s[ids-1]
        #違っていたら、長い方の文字を採用
        elif s[ids-1] != t[idt-1]:
            if len(dp[ids][idt-1]) >= len(dp[ids-1][idt]):
                dp[ids][idt] = dp[ids][idt-1]
            else:
                dp[ids][idt] = dp[ids-1][idt]
print(dp[-1][-1])


### FIXED CODE ###

s= input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0 for _ in range(lt+1) ]  for _ in range(ls+1)] #dp[i][j] sがi文字目,tがj文字目まででのLCS
for ids in range(1,ls+1):
    for idt in range(1,lt + 1):
        #一致してたら文字を足す
        if s[ids-1] == t[idt-1]:
            dp[ids][idt] =dp[ids-1][idt-1] + 1
        #違っていたら、長い方の文字を採用
        elif s[ids-1] != t[idt-1]:
            if dp[ids][idt-1] >= dp[ids-1][idt]:
                dp[ids][idt] = dp[ids][idt-1]
            else:
                dp[ids][idt] = dp[ids-1][idt]
ans = ''
num=dp[-1][-1]
ids = ls;idt=lt
while num:
    if dp[ids][idt] == dp[ids][idt-1]:
        idt -= 1
    elif dp[ids][idt] == dp[ids-1][idt]:
        ids -=1
    elif dp[ids][idt] ==dp[ids-1][idt-1] + 1:
        ans += s[ids-1]
        num -=1
        idt -= 1
        ids -=1
print(ans[::-1])
### BUGGY CODE ###

import sys


def isprime(x):
    # 素数判定
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= x ** 0.5:
        if x % i == 0:
            return False
        i += 2
    return True


def solve(l, r, primelist):
    res = 0
    for i in range(l, r + 1, 2):
        if primelist[i] and primelist[(i + 1) // 2]:
            res += 1
    return res


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


def main():
    primelist = [False] * (10 ** 5 + 10)
    primelist[2] = True
    for i in range(1, 10 ** 5 + 1, 2):
        if isprime(i):
            primelist[i] = True
    # print(primelist[:20])
    Q = int(input())
    for i in range(Q):
        l, r = map(int, input().split())
        print(solve(l, r, primelist))


if __name__ == "__main__":
    main()


### FIXED CODE ###

MAX = 10 ** 5 + 1
f = [True] * (MAX)
c = [0] * (MAX + 1)
for i in range(2, MAX):
    if f[i]:
        for j in range(i + i, MAX, i):
            f[j] = False
for i in range(3, MAX, 2):
    if f[i] and f[(i + 1) // 2]:
        c[i] += 1
for i in range(3, MAX):
    c[i] += c[i - 1]

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(c[r] - c[l - 1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

LL = [[-1] * 2 for _ in range(N)]
R = {}
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if a not in R: R[a] = [[b, i]]
  else: R[a].append([b, i])
  if b not in R: R[b] = [[a, i]]
  else: R[b].append([a, i])
  if D[a] < D[b]:
    LL[b] = [a, i]
  elif D[a] > D[b]:
    LL[a] = [b, i]
  else:
    LL[a] = [b, i]
    LL[b] = [a, i]

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M

for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x][0] == -1:
      print(-1)
      exit()
    else:
      n, m = LL[x]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

t = ""
for i in range(N):
  if L[i] == 1:
    t += "B"
  else:
    t += "W"
print(t)
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

LL = [[-1] * 2 for _ in range(N)]
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if D[a] < D[b]:
    LL[b] = [a, i]
  elif D[a] > D[b]:
    LL[a] = [b, i]
  else:
    LL[a] = [b, i]
    LL[b] = [a, i]

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M

for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x][0] == -1:
      print(-1)
      exit()
    else:
      n, m = LL[x]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

for i in range(N):
  if L[i] == 1:
    L[i] = "B"
  else:
    L[i] = "W"
print("".join(list(map(str, L))))
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])
### BUGGY CODE ###

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

MOD = 998244353
n, k = map(int, input().split())
s = set()
for i in range(k):
    a, b = map(int, input().split())
    s.update(range(a, b + 1))
s = sorted(list(s))

dp = [0] + [-1] * n
def dfs(goal, route):
    if dp[goal] != -1:
        return dp[goal]
    else:
        ans = 0
        for r in route:
            if goal - r < 1:
                break
            else:
                ans = (ans + dfs(goal - r, route)) % MOD
        dp[goal] = ans
        return dp[goal]
dp[1] = 1
print(dfs(n, s))


### FIXED CODE ###

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

MOD = 998244353
n, k = map(int, input().split())
s = list()
for i in range(k):
    s.append(tuple(map(int, input().split())))

dp = [0] + [0] * n
diff = [0] + [0] * n
dp[1] = 1
for i in range(1, n):
    for j, k in s:
        if i + j > n:
            continue
        diff[i + j] += dp[i]
        if i + k + 1 > n:
            continue
        diff[i + k + 1] -= dp[i]
    dp[i] = (dp[i - 1] + diff[i]) % MOD
    dp[i + 1] = (dp[i] + diff[i + 1]) % MOD
print(dp[n])
### BUGGY CODE ###

import sys
a = sys.stdin.read().split('\n')[:-1]
s = list(a[0])
q = int(a[1])
f = 1
for i in range(2, q + 2):
    if a[i][0] == '1':
        f = 1 - f
    else:
        l = len(s)
        s.insert(0 if a[i][2] == '21'[f] else l, a[i][4])
if f != 1:
    s.reverse()
print(''.join(s))

### FIXED CODE ###

import sys
a = sys.stdin.read().split('\n')[:-1]
q = int(a[1])
f = 1
l = [[], []]
for i in range(2, q + 2):
    if a[i][0] == '1':
        f = 1 - f
    else:
        l[0 if a[i][2] == '21'[f] else 1].append(a[i][4])
if f != 1:
    l[1].reverse()
    print(''.join(l[1]) + ''.join(reversed(list(a[0]))) + ''.join(l[0]))
else:
    l[0].reverse()
    print(''.join(l[0]) + a[0] + ''.join(l[1]))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
li=[A[0]]
for i in range(1,N):
  ans+=li[0]
  li.pop(0)
  li.append(A[i])
  li.append(A[i])
print(ans)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
li=[A[0]]
for i in range(1,N):
  ans+=li[i-1]
  li.append(A[i])
  li.append(A[i])
print(ans)
### BUGGY CODE ###

q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

like_numbers = []
for prime in primes:
    if int((prime + 1) / 2) in primes:
        like_numbers.append(prime)

for i in range(q):
    l = lr[i][0]
    r = lr[i][1]
    print(sum((x >= l and x <= r) for x in like_numbers))


### FIXED CODE ###

q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

like_numbers = []
for prime in primes:
    if int((prime + 1) / 2) in primes:
        like_numbers.append(prime)

for i in range(q):
    l = lr[i][0]
    r = lr[i][1]
    print(sum((x >= l and x <= r) for x in like_numbers))
### BUGGY CODE ###

# -*- coding utf-8 -*-
MOD = 10 ** 9 + 7

S = input()
mods = [0] * 13
mods[0] = 1

digit = 1
for s in S[::-1]:
    next_mods = [0] * 13
    if s == '?':
        for i in range(10):
            for m in range(13):
                next_mods[(m + i * digit) % 13] += mods[m]
    else:
        for m in range(13):
            next_mods[(m + int(s) * digit) % 13] += mods[m]

    for m in range(13):
        next_mods[m] %= MOD
    mods = next_mods
    digit *= 10

ans = mods[5]

print(ans)


### FIXED CODE ###

# -*- coding utf-8 -*-
MOD = 10 ** 9 + 7

S = input()
# S = '?' * 100000
mods = [0] * 13
mods[0] = 1

digit = 1
for s in S[::-1]:
    next_mods = [0] * 13
    if s == '?':
        for i in range(10):
            for m in range(13):
                next_mods[(m + i * digit) % 13] += mods[m]
    else:
        for m in range(13):
            next_mods[(m + int(s) * digit) % 13] += mods[m]

    for m in range(13):
        next_mods[m] %= MOD
    mods = next_mods
    digit *= 10
    digit %= 13    # this line dramatically reduces calculation time

ans = mods[5]

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

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

starts = {}
goals = {}
for i in range(len(A)):
    s_num = A[i][0]
    g_num = A[i][1]
    if s_num == '1':
        starts[A[i][1]] = 0
    elif g_num == str(N):
        goals[A[i][0]] = 0

is_ok = False
for s in starts:
    for g in goals:
        if s == g:
            is_ok = True
            break
    if is_ok:
        break


# is_ok = False
# for j in range(len(start)):
#     for k in range(len(goal)):
#         if start[j][1] == goal[k][0]:
#             is_ok = True
#             break
#     if is_ok:
#         break

if is_ok:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

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

starts = {}
goals = {}
for i in range(len(A)):
    s_num = A[i][0]
    g_num = A[i][1]
    if s_num == '1':
        starts[A[i][1]] = 0
    elif g_num == str(N):
        goals[A[i][0]] = 0

is_ok = False
for s in starts:
    if s in goals:
        is_ok = True
        break


# is_ok = False
# for j in range(len(start)):
#     for k in range(len(goal)):
#         if start[j][1] == goal[k][0]:
#             is_ok = True
#             break
#     if is_ok:
#         break

if is_ok:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

a,b = map(int,input().split())

from math import gcd
n = gcd(a,b)

li = [1]
i = 1
for i in range(2,n+1):
    while n%i == 0:
        li.append(i)
        n //=i
print(len(set(li)))

### FIXED CODE ###

x, y = map(int,input().split())
#li = list(map(int, input().split()))

def pr(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

print(len(set(pr(x)) & set(pr(y)))+1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, K = LI()
    h_li = [0] + LI()
    min_cost_li = [INF for _ in range(N+1)]
    min_cost_li[1] = 0

    for i in range(1,N+1):  # 10**5
        for j in range(1, K+1): # 10**2
            if i+j > N: continue
            min_cost_li[i+j] = min(min_cost_li[i+j], min_cost_li[i] + abs(h_li[i] - h_li[i+j]))

    print(min_cost_li[N])

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, K = LI()
    h_li = [0] + LI()
    min_cost_li = [INF for _ in range(N+1)]
    min_cost_li[1] = 0

    for i in range(1,N+1):  # 10**5
        for j in range(1, K+1): # 10**2
            if i+j > N: continue
            min_cost_li[i+j] = min(min_cost_li[i+j], min_cost_li[i] + abs(h_li[i] - h_li[i+j]))

    print(min_cost_li[N])


main()
### BUGGY CODE ###

# D
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)

### FIXED CODE ###

# D
import collections

def combinations_count(n, r):
    return n*(n-1) // 2

N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)
### BUGGY CODE ###

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

a_list = list(map(int, input().split()))

def print_ans(s):
    if len(s)==0:
        print()
    else:
        ans = str(s[0])
        for val in s[1:]:
            ans = ans + " {}".format(val)
        print(ans)

s = []
count = 0
flag = True
done_list = [[]]
while(flag):
    count += 1
    for a in a_list:
        if a in s:
            s = s[0:s.index(a)]
        else:
            s.append(a)

    if count == k:
        print_ans(s)
        exit()

    if s in done_list:
        flag = False
    else:
        done_list.append(s.copy())


loop_num = len(done_list)
s = done_list[ k % loop_num ]
print_ans(s)


### FIXED CODE ###

import bisect

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

ind = [[] for _ in range(2*10**5 + 1)]
for i,num in enumerate(a):
    ind[num].append(i)

for i in range(1,2*10**5 + 1):
    if(ind[i]):
        ind[i].append(ind[i][0] + n)

before = []
cnt = 0
now = a[0]
while(True):
    right = bisect.bisect_right(ind[now], cnt%n)
    cnt += ind[now][right] - ind[now][right-1] + 1
    if(ind[now][right] >= n):
        before.append(ind[now][right-1])
    now = a[cnt%n]
    if(cnt%n == 0):
        break

if(cnt//n==1):
    print('')
    exit()

cyc = k%(cnt//n)

cnt = before[cyc-1]
ans = []
while(cnt < n):
    now = a[cnt]
    right = bisect.bisect_right(ind[now],cnt)
    if(ind[now][right] >= n):
        ans.append(now)
        cnt += 1
    else:
        cnt = ind[now][right] + 1

print(' '.join(map(str,ans)))
### BUGGY CODE ###

from collections import deque

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

a = deque(map(int, input().split()))
ad = {}
for i in range(n):
    ad[i] = a.popleft()

def makea(ad):
    newa = {}
    for i in range(n):
        newa[i] = 0
    for i in range(n):
        if i - ad[i] >= 0:
            if i + ad[i] <= n-1:
                for j in range(i-ad[i], i+ad[i]+1):
                    newa[j] += 1
            else:
                for j in range(i-ad[i], n):
                    newa[j] += 1
        elif i + ad[i] <= n-1:
            for j in range(i+ad[i]+1):
                newa[j] += 1
        else:
            for j in range(n):
                newa[j] += 1
    return newa

for _ in range(k):
    ad = makea(ad)
    if "".join(map(str, list(ad.values()))) == int("1"*n):
        break

print(" ".join(map(str, list(ad.values()))))

### FIXED CODE ###

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

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

def IMOS(a):
    imos = [0]*n
    for i, ai in enumerate(a):
        imos[max(i-ai, 0)] += 1
        if i+ai+1 < n:
            imos[i+ai+1] -= 1
    for i in range(1, n):
        imos[i] += imos[i-1]
    return imos

for _ in range(k):
    if sum(a) == n*n:
        break
    a = IMOS(a)

print(*a)
### BUGGY CODE ###

import heapq


N, Q = map(int, input().split())
event_list = []
for i in range(N):
  s, t, x = map(int, input().split())
  event_list.append([s-x, 1, x])
  event_list.append([t-x, -1, x])

for i in range(Q):
  event_list.append([int(input()), 2, 0])

event_list.sort()
event_list.append([10**10, 1, 10**10])

x_set = set()
x_list = []
for time, event, x in event_list:
  if event == 1:
    x_set.add(x)
    heapq.heappush(x_list, x)
  elif event == -1:
    x_set.remove(x)
  else:
    while x_list and x_list[0] not in x_set:
      _ = heapq.heappop(x_list)
    if x_list:
      print(x_list[0])
    else:
      print(-1)

### FIXED CODE ###

import sys
from heapq import heappop, heappush

input = sys.stdin.readline
N, Q = map(int, input().split())
event_list = []
for i in range(N):
  s, t, x = map(int, input().split())
  event_list.append([s-x, 1, x])
  event_list.append([t-x, -1, x])

for i in range(Q):
  event_list.append([int(input()), 2, 0])

ans = []
event_list.sort()
x_set = set()
x_list = []
for time, event, x in event_list:
  if event == 1:
    x_set.add(x)
    heappush(x_list, x)
  elif event == -1:
    x_set.remove(x)
  else:
    while x_list and x_list[0] not in x_set:
      heappop(x_list)
    if x_list:
      ans.append(x_list[0])
    else:
      ans.append(-1)

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