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

n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
count = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if l[i] >= l[j]*2:
      break
    else:
      for k in range(j+1, n):
        if l[i] < l[j]+l[k]:
          count += 1
        else:
          break
print(count)

### FIXED CODE ###

import bisect

n = int(input())
l = sorted(list(map(int, input().split())))
count = 0
for b in range(n-2):
  for c in range(b+1, n-1):
    count += max(0, bisect.bisect_left(l, l[b]+l[c])-c-1)

print(count)
### BUGGY CODE ###

def main():
    N = int(input())
    S = []
    for _ in range(N):
        S.append(int(input()))
    
    maxScore = 0
    for i in range(2 ** N):
        tmp = 0
        for j in range(N):
            if ((i >> j) & 1):
                tmp = tmp + S[j]
        if tmp % 10 == 0:
            tmp = 0
        if maxScore < tmp:
            maxScore = tmp
    
    print(maxScore)


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    S = []
    M = []
    sumsum = 0
    for _ in range(N):
        t = int(input())
        if t != 0:
            sumsum = sumsum + t
            S.append(t)
            if t % 10 != 0:
                M.append(t)

    if sumsum % 10 != 0:
        print(sumsum)
        return
    
    if len(M) == 0:
        print("0")
        return

    M.sort()
    print(sumsum - M[0])


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

N, K, C = map(int, input().split())
m = {"x":0, "o":1}
S = list(map(lambda x:m[x], input()))

must = []
k = -1
while 1:
  try:
    if k >= 0:
      S[k] = 1
    k = S.index(1, k+1)
    S[k] = 0
  except:
    break
  j = -C-1
  for i in range(K):
    try:
      j = S.index(1, j+C+1)
    except:
      must.append(k)
      break

for m in must:
  print(m+1)

### FIXED CODE ###

N, K, C = map(int, input().split())
S = input()

must = set()
i = len(S)+C
for j in range(K):
  i = S.rindex("o", 0, i-C)
  must.add(i)
if i<=C or "o" not in S[:i-C]:
  i = -C-1
  for j in range(K):
    i = S.index("o", i+C+1)
    if i in must:
      print(i+1)
### BUGGY CODE ###

from itertools import accumulate


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(loop)

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = sum(loop)
        table = [list(accumulate(loop[i:] + loop[:i])) for i in range(loop_len)]
        ans = max(max(max(table[i][:min(loop_len, k)]) for i in range(loop_len)), ans)
        if loop_num > 0:
            ans = max(loop_sum * (loop_num - 1) + max(max(table[i][:loop_len]) for i in range(loop_len)), ans)
            if loop_mod > 0:
                ans = max(loop_sum * loop_num + max(max(table[i][:loop_mod]) for i in range(loop_len)), ans)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def mod_max(loop, mod):
    if mod == 0:
        return 0
    loop_len = len(loop)
    mm = min(loop)
    for start in range(loop_len):
        current_sum = 0
        for i in range(mod):
            current_sum += loop[(start + i) % loop_len]
            mm = max(current_sum, mm)
    return mm


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(loop)

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = sum(loop)
        ans = max(mod_max(loop, min(loop_len, k)), ans)
        if loop_num > 0:
            ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
            ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
    print(ans)


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

N, K = map(int, input().split())
S = input()

n_sum = []

ct = 1
for i in range(N-1):
    if S[i+1] == S[i]:
        ct += 1
    else:
        n_sum.append(ct)
        ct += 1

n_sum.append(ct)

if len(n_sum) == 1:
    if S[0] == '0':
        for i in range(2*K+1):
            n_sum.append(ct)
            n_sum.insert(0, 0)
    else:
        for i in range(2*K):
            n_sum.append(0)
            n_sum.insert(0, 0)

else:
    if S[-1] == '0':
        n_sum.append(ct)
    if S[0] == '0':
        n_sum.insert(0, 0)

if K < len(n_sum)//2:
    Max = -1
    i = 0
    while i+2*K < len(n_sum):
        if i == 0:
            tmp = n_sum[i+2*K]
        else:
            tmp = n_sum[i+2*K] - n_sum[i-1]
        i += 2
        Max = max(Max, tmp)
else:
    Max = ct

print(Max)


### FIXED CODE ###

import sys

N, K = map(int, input().split())
S = input()

n_sum = []

ct = 1
for i in range(N-1):
    if S[i+1] == S[i]:
        ct += 1
    else:
        n_sum.append(ct)
        ct += 1

n_sum.append(ct)

if len(n_sum) == 1:
    print(ct)
    sys.exit()

else:
    if S[-1] == '0':
        n_sum.append(ct)
    if S[0] == '0':
        n_sum.insert(0, 0)

if K < len(n_sum)//2:
    Max = -1
    i = 0
    while i+2*K < len(n_sum):
        if i == 0:
            tmp = n_sum[i+2*K]
        else:
            tmp = n_sum[i+2*K] - n_sum[i-1]
        i += 2
        Max = max(Max, tmp)
else:
    Max = ct

print(Max)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

P = 10 ** 9 + 7
Q = 13


def main():
    S = input().rstrip()

    N = len(S)
    dp = [[0] * Q for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        base = pow(10, N - 1 - i, Q)
        D = S[i]
        if D == "?":
            for d in range(10):
                n = d * base
                for j in range(Q):
                    next_j = (j + n) % Q
                    dp[i + 1][next_j] += dp[i][j]
                    dp[i + 1][next_j] %= P
        else:
            n = int(D) * base
            for j in range(Q):
                next_j = (j + n) % Q
                dp[i + 1][(j + n) % Q] += dp[i][j]
                dp[i + 1][(j + n) % Q] %= P

    ans = dp[N][5]
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

input = sys.stdin.readline

P = 10 ** 9 + 7
Q = 13


def main():
    S = input().rstrip()

    N = len(S)
    dp = [[0] * Q for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        base = pow(10, N - 1 - i, Q)
        D = S[i]
        if D == "?":
            for d in range(10):
                n = d * base
                for j in range(Q):
                    next_j = (j + n) % Q
                    dp[i + 1][next_j] += dp[i][j]
                    dp[i + 1][next_j] %= P
        else:
            n = int(D) * base
            for j in range(Q):
                next_j = (j + n) % Q
                dp[i + 1][(j + n) % Q] += dp[i][j]
                dp[i + 1][(j + n) % Q] %= P

    ans = dp[N][5]
    print(ans)


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

import collections

S = input()

list1 = []
list2 = []
result = 0

for i in range(len(S)):
    if int(S[-i:])%2019==0:
        result += 1
    list1.append(int(S[-i:])%2019)
a = collections.Counter(list1)
val = list(a.values())
for j in range(len(a.values())):
    result += val[j]*(val[j]-1)/2
print(int(result))
        



### FIXED CODE ###

s = input()[::-1]
counts = [0] * 2019
counts[0] = 1
num, d = 0, 1
result = 0

for i in s:
    num += int(i) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1
    
for cnt in counts:
    result += cnt*(cnt-1)//2
    
print(result)
### BUGGY CODE ###

n,q = map(int, raw_input().split())
ls = [set([i]) for i in range(n)]
ref = [i for i in range(n)]
for i in range(q):
	com,x,y = map(int, raw_input().split())
	if com == 0: # unite
		x = ref[x]
		ls[x] = ls[x]|ls[ref[y]]
		for i in list(ls[x]):
			ref[i] = ref[x]
	else: # same
		print 1 if y in ls[ref[x]] and x in ls[ref[y]] else 0

### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        self.rank = [0] * size
        self.par = range(size)
        self.g_num = size

    def find(self, x):
        if x == self.par[x]: return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return

        self.g_num -= 1
        if (self.rank[x] > self.rank[y]):
            self.par[y] = x
        else:
            self.par[x] = y
            if (self.rank[x] == self.rank[y]): self.rank[y] += 1

    def group_num(self):
        return self.g_num

n, q = map(int, raw_input().split())
uf = UnionFind(n)
for i in xrange(q):
    c, x, y = map(int, raw_input().split())
    if c == 0:
        uf.unite(x, y)
    else:
        print int(uf.same(x, y))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]

    for i in range(n+1):
        S[i]-=i
        S[i]%=k

    C=[[] for _ in range(k)]
    for i in range(n+1):
        C[S[i]].append(i)

    ans=0
    for d in range(k):
        n=len(C[d])
        if(n<=1): continue
        r=0
        for l in range(n):
            while(r+1<n and C[d][r+1]-C[d][l]<k):
                r+=1
            ans+=r-l
            if(r==l): r+=1
    print(ans)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]

    for i in range(n+1):
        S[i]-=i
        S[i]%=k

    C=defaultdict(list)
    for i in range(n+1):
        C[S[i]].append(i)

    ans=0
    C=list(C.values())
    for d in range(len(C)):
        n=len(C[d])
        if(n<=1): continue
        r=0
        for l in range(n):
            while(r+1<n and C[d][r+1]-C[d][l]<k):
                r+=1
            ans+=r-l
            if(r==l): r+=1
    print(ans)
resolve()
### BUGGY CODE ###

n = int(input())
s = input()

out = '0'

for i in s:
    if out[-1] != i:
        out += i

print(len(out) - 1)


### FIXED CODE ###

n = int(input())
s = input()

out = '0'

for i in s:
    if out[-1] != i:
        out += i

print(len(out) - 1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
m = 0

A.sort()
B.sort()
C.sort(reverse=True)

for j in range(N):
    for i in range(N):
        if A[i] >= B[j]:
            break
        if A[N-1] < B[j]:
            i = N
    for k in range(N):
        if B[j] >= C[k]:
            break
        if B[j] < C[N-1]:
            k = N
    m =  m + i * k

print(m)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
C.reverse()
 
ans = 0
ai = 0
ci = N-1
for b in B:
    while ai < N and A[ai] < b:
        ai += 1
    while ci >= 0 and C[ci] <= b:
        ci -= 1
    ans += ai * (ci+1)
 
print(ans)
### BUGGY CODE ###

n = int(input())
x = []
y = []
for i in range(n):
    s = list(map(int, input().split()))
    x.append([s[0], i])
    y.append([s[1], i])

x.sort()
y.sort()

xdiff = []
ydiff = []
for i in range(1, n):
    xdiff.append([x[i][0] - x[i - 1][0], x[i - 1][1], x[i][1]])
    ydiff.append([y[i][0] - y[i - 1][0], y[i - 1][1], y[i][1]])

xdiff.sort()
ydiff.sort()

parent = [-1] * n

def getParent(index):
    while parent[index] != -1:
        index = parent[index]

    return index

count = 0
ans = 0
xIndex = 0
yIndex = 0
while count != n - 1:
    if xIndex != n - 1:
        xTemp = xdiff[xIndex]
    if yIndex != n - 1:
        yTemp = ydiff[yIndex]

    if yIndex == n - 1 or (xIndex != n - 1 and xTemp[0] < yTemp[0]):
        xIndex += 1
        temp = xTemp
    else:
        yIndex += 1
        temp = yTemp

    parent1 = getParent(temp[1])
    parent2 = getParent(temp[2])
    if parent1 == parent2:
        continue
    else:
        count += 1
        ans += temp[0]
        parent[parent1] = parent2

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
n = int(input())
x = []
y = []
for i in range(n):
    s = list(map(int, input().split()))
    x.append([s[0], i])
    y.append([s[1], i])

x.sort()
y.sort()

xdiff = []
ydiff = []
for i in range(1, n):
    xdiff.append([x[i][0] - x[i - 1][0], x[i - 1][1], x[i][1]])
    ydiff.append([y[i][0] - y[i - 1][0], y[i - 1][1], y[i][1]])

xdiff.sort()
ydiff.sort()

parent = [-1] * n

def getParent(index):
    if parent[index] == -1:
        return index
    else:
        parent[index] = getParent(parent[index])
        return parent[index]

count = 0
ans = 0
xIndex = 0
yIndex = 0
while count != n - 1:
    if xIndex != n - 1:
        xTemp = xdiff[xIndex]
    if yIndex != n - 1:
        yTemp = ydiff[yIndex]

    if yIndex == n - 1 or (xIndex != n - 1 and xTemp[0] < yTemp[0]):
        xIndex += 1
        temp = xTemp
    else:
        yIndex += 1
        temp = yTemp

    parent1 = getParent(temp[1])
    parent2 = getParent(temp[2])
    if parent1 == parent2:
        continue
    else:
        count += 1
        ans += temp[0]
        parent[parent1] = parent2

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

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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
max_ans = ans
max_index = 0

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    if max_ans < ans:
        max_ans = ans
        max_index = i+1

ans = 0
for i in range(k):
    for j in range(p[max_index+i]):
        ans += (1/p[max_index+i]*(j+1))
    
print(ans)
        

### FIXED CODE ###

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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
max_ans = ans
max_index = 0

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    if max_ans < ans:
        max_ans = ans
        max_index = i+1

ans = 0
for i in range(k):
    pp = p[max_index+i]
    for j in range(pp):
        ans += (1/pp*(j+1))
    
print(ans)
### BUGGY CODE ###

import numpy as np

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

for i in range(len(X)):
    print(int(np.median(X[:i] + X[i+1:])))

### FIXED CODE ###

import numpy as np

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

M = np.median(X)

Y = sorted(X)
a = Y[int(len(Y)/2 - 1)]
b = Y[int(len(Y)/2)]

for x in X:
    if x <= a:
        print(b)
    else:
        print(a)
### BUGGY CODE ###

from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = [], [], []
    for i, c in enumerate(S):
        if c == 'R':
            R.append(i)
        elif c == 'G':
            G.append(i)
        else:
            B.append(i)
    cnt = 0
    for ri in R:
        for gi in G:
            for bi in B:
                if abs(gi-ri) != abs(bi-gi) and abs(ri-bi) != abs(bi-gi) and abs(ri-bi) != abs(ri-gi):
                    cnt+=1

    stdout.write(str(cnt)+"\n")

main()


### FIXED CODE ###

from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = set(), set(), set()
    for i, c in enumerate(S):
        if c == 'R':
            R.add(i)
        elif c == 'G':
            G.add(i)
        else:
            B.add(i)
    cnt, total = 0, len(R) * len(G) * len(B)
    for ri in R:
        for gi in G:
            if abs(ri-gi)+gi in B:
                cnt += 1
            if abs(ri-gi)+ri in B:
                cnt += 1
    for ri in G:
        for gi in B:
            if abs(ri-gi)+gi in R:
                cnt += 1
            if abs(ri-gi)+ri in R:
                cnt += 1
    for ri in R:
        for gi in B:
            if abs(ri-gi)+gi in G:
                cnt += 1
            if abs(ri-gi)+ri in G:
                cnt += 1

    stdout.write(str(total-cnt)+"\n")

main()
### BUGGY CODE ###

#coding:utf-8
import itertools

k, n = map(int, input().split())
a = tuple(map(int, input().split()))
ans = 100000000000000000000

dist = []
pattern = sorted(list(itertools.permutations(a)))
#print(pattern)
#print(len(pattern))

for i in range(len(pattern)):
    tmp = 0
    for j in range(0,n-1):
        right = abs(pattern[i][j+1] - pattern[i][j])
        left = abs(k - pattern[i][j+1])
        #print(right, left)
        tmp += min(right, left)
    if tmp < ans:
        ans = tmp

#print(dist)
print(ans)

### FIXED CODE ###

#coding:utf-8

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

#逆周りの方が距離が短く済むので、距離を2倍にして考える
#池の一周の長さ+a[0]を座標として追加
a.append(a[0] + k)

#距離が最大になる経路は通らないので除外する
for i in range(n):
    dist.append(a[i+1] - a[i])

#print(a, dist)
#池の一周の長さから、距離が最大になるところを除外したものが最短
print(k - max(dist))
### BUGGY CODE ###

n = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

dp = [[-1]*102 for _ in range(sum(T) + 1)]
dp[0][0] = 0

nt = 0
pt = T[0]
# i 秒から i+1 秒へ配る
delta = [-1,0,1]
for i in range(sum(T)):
    if pt == i:
        nt += 1
        pt += T[nt]
    for j in range(101):
        if j > V[nt] or dp[i][j] == -1:break
        for d in delta:
            nj = j + d
            if 0 <= nj <= V[nt]:
                if d != 0 or j == V[nt]:
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + (j+nj)/2)
                else :
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + j + 0.25)

print(dp[-1][0])


### FIXED CODE ###

n = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

dp = [[-1]*102 for _ in range(sum(T) + 1)]
dp[0][0] = 0

nt = 0
pt = T[0]
# i 秒から i+1 秒へ配る
delta = [-1,0,1]
for i in range(sum(T)):
    if pt == i:
        nt += 1
        pt += T[nt]
    for j in range(101):
        if j > V[nt] or dp[i][j] == -1:break
        for d in delta:
            nj = j + d
            if 0 <= nj <= V[nt]:
                if d != 0 or j == V[nt]:
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + (j+nj)/2)
                else :
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + j + 0.25)

print(dp[-1][0])
### BUGGY CODE ###

def Fanc(x):
    ans = 0
    while x > 0:
        ans += x % 10
        x // 10
    return ans     
    
N,A,B = map(int,input().split())
sum = 0
for i in range(1,N + 1):
    if A < Fanc(i) and Fanc(i) < B:
        sum += i
print(sum)

### FIXED CODE ###

def Fanc(x):
    ans = 0
    while x > 0:
        ans += x % 10
        x = x // 10
    return ans     
    
N,A,B = map(int,input().split())
sum = 0
for i in range(1,N + 1):
    if A <= Fanc(i) and Fanc(i) <= B:
        sum += i
print(sum)
### BUGGY CODE ###

import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 1)
r = INF
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
    r = min(r, min(dp[-a:]) + b)

print(min(r, dp[-1]))


### FIXED CODE ###

import sys

read = sys.stdin.read

H, N, *AB = map(int, read().split())

INF = 10 ** 10
dp = [INF] * (H + 1)
r = INF
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, H + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
    r = min(r, min(dp[-a:]) + b)

print(min(r, dp[-1]))
### BUGGY CODE ###

N=int(input())

def listdict(s1):
    ret={}
    for i in s1:
        tmp=ret.get(i,0)
        if tmp==0:
            ret[i]=1
        else:
            ret[i]+=1
    return ret

sN=[listdict(input()) for _ in range(N)]
ret=0

for i in range(N-1):
    for j in range(i+1,N):
        if sN[i]==sN[j]:
            ret+=1

print(ret)

### FIXED CODE ###

N=int(input())

def listdict(s1):
    ret={}
    rets=""
    for i in s1:
        tmp=ret.get(i,0)
        if tmp==0:
            ret[i]=1
        else:
            ret[i]+=1
    ret_sorted = sorted(ret.items(), key=lambda x:x[0])
    
    for k in range(len(ret_sorted)):
        rets+=str(ret_sorted[k][0])
        rets+=str(ret_sorted[k][1])
    return rets

sN=[listdict(input()) for _ in range(N)]

d1={}
for i in sN:
    tmp=d1.get(i,0)
    if tmp==0:
        d1[i]=1
    else:
        d1[i]+=1
ret=0
for i in d1.values():
    if i ==1:
        continue
    for j in range(1,i):
        ret+=j
print(ret)
### BUGGY CODE ###

import sys
from operator import itemgetter
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
def main():
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while(e[0] > d):
			if cont == True:
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			else:
				mini = min(kouho)
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			cont = True
			if q < Q-1:
				q = q + 1
				d = int(inputs())
			else:
				flag = True
				q = q + 1
				break
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			cont = False
	for t in [None]*(Q-q):
		print(-1)
		
def sub():
	V = [list(map(int,inputs().split())) for p in [0]*N]
	M = [int(inputs()) for p in [0]*Q]
	V.sort(key = lambda x:(x[2],x[0],x[1]))
	for v in V:
		v[0] -= v[2]
		v[1] -= v[2] + 1
	for m in M:
		for n in range(N):
			if V[n][0] <=m and m <= V[n][1]:
				print(V[n][2])
				break
		else:
			print(-1)

#N200000
#Q200000
if N == Q:
	sub()
else:
	main()

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while p < n:
        if s[p]==x[j]:
            j += 1
            if j == 3:
                result += 1
                break
        p += 1

print(result)

### FIXED CODE ###

n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while p < n:
        if s[p]==x[j]:
            j += 1
            if j == 3:
                result += 1
                break
        p += 1

print(result)
### BUGGY CODE ###

import numpy as np
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
A=np.array(A)

ans=0
for i in range(60):
    count_1=len([i for i in A if i%2==1])
    ans +=2**i*count_1*(n-count_1)
    A >>=1

print(ans%mod)

### FIXED CODE ###

import numpy as np
mod=10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%mod)