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

import sys
input=sys.stdin.readline

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

for i in range(n):
    for j in range(i+1,n):
        if abs(i-j)==(a[i]+a[j]):
            ans+=1

print(ans)

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int,input().split()))
li=[]
ans=0

for i,var in enumerate(a,1):
    li.append(i+var)

li=collections.Counter(li)

for j,var in enumerate(a,1):
    ans+=li[j-var]

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

a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
jobs.reverse()
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

### FIXED CODE ###

import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)
### BUGGY CODE ###

def main():
  N,D,A = map(int,input().split())
  import numpy as np
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  X = [xh[0] for xh in XH]
  H = np.array([xh[1] for xh in XH])
  ans = 0
  l=[0]*N
  x = X[0]
  j = 0
  h = H[0]
  b = (h+A-1)//A
  ans += b
  while True:
    if j+1>=N:
      break
    if X[j+1]<=x+2*D:
      j+=1
    else:
      break
  H[0:j+1:]-=b*A
  l[0]=j
  for i in range(1,N):
    x = X[i]
    j = max(i,l[i-1])
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      while True:
        if j+1>=N:
          break
        if X[j+1]<=x+2*D:
          j+=1
        else:
          break
      H[i:j+1:]-=b*A
  print(ans)
main()

### FIXED CODE ###

def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()
### BUGGY CODE ###

S = input()
Q = int(input())
before_chr = []
after_chr = []
for i in range(Q):
    query = list(input().split())
    if query[0] == "1":
        S = S[::-1]
    elif query[1] == "1":
        S = query[2] + S
    else:
        S += query[2]
print(S)

### FIXED CODE ###

S = input()
Q = int(input())
before_chr = []
after_chr = []
reverse_status = 1
for i in range(Q):
    query = list(input().split())
    if query[0] == "1":
        reverse_status *= -1
    elif reverse_status * (1.5-int(query[1])) == 0.5:
        before_chr += query[2]
    else:
        after_chr += query[2]
if reverse_status == 1:
    print("".join(before_chr[::-1])+S+"".join(after_chr))
else:
    print("".join(after_chr[::-1])+S[::-1]+"".join(before_chr))
### BUGGY CODE ###

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

if N == 1:
    print(A[0])
else:

    for i in range(N):
        j = i

        while j > 0 and A[j] < A[j-1]:
            if A[j] > A[j-1]:

                break
                k = A[j]
                l = A[j-1]
                A[j-1] = k
                A[j] = l
                j -= 1

            S = str(A[0])
            for k in range(1,N-1):
                S += " " + str(A[k])

            S = S + " "+str(A[N-1])
            print(S)



### FIXED CODE ###

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


for i in range(N):
    if N == 1:
        print(A[0])
        break
    j = i

    while j > 0 and A[j] < A[j-1]:
        if A[j] > A[j-1]:

            break
        k = A[j]
        l = A[j-1]
        A[j-1] = k
        A[j] = l
        j -= 1

    S = str(A[0])
    for k in range(1,N-1):
        S += " " + str(A[k])

    S = S + " "+str(A[N-1])
    print(S)
### BUGGY CODE ###

import sys
import copy
import time
import random

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

D = None
C = None
S = None

def cnt_score(t):
    global D, C, S
    score = 0
    cnt = [-1] * 26

    for i in range(D):
        score += S[i][t[i] - 1]
        minusscore = 0
        cnt[t[i] - 1] = i
        for j in range(26):
            minusscore += (i - cnt[j]) * C[j]
        score -= minusscore
    return score


def main():
    global D, C, S
    D = int(input())
    C = [int(x) for x in input().split()]
    S = [[int(x) for x in input().split()] for _ in range(D)]

    start = time.time()

    ans = []
    for s in S:
        ans.append(s.index(max(s)) + 1)

    # A = [[None] * COL for j in range(ROW)]

    old_score = cnt_score(ans)
    day = 0
    while True:
        # time up
        current = time.time()
        if current - start > 1.9:
            break

        # main
        new_ans = copy.deepcopy(ans)

        max_sore = old_score
        max_contest = ans[day]
        for i in range(26):
            new_ans[day] = i + 1
            new_score = cnt_score(new_ans)
            if new_score > old_score:
                max_contest = i + 1
                old_score = new_score
        ans[day] = max_contest

        # increment day
        day = (day + 1) % D

    for a in ans:
        print(a)



if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    D = int(input())
    C = [int(x) for x in input().split()]
    S = [[int(x) for x in input().split()] for _ in range(D)]


    for i in range(D):
        print(i % 26 + 1)



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

import math
import sys

N, K = map(int, input().split())
if K > 41:
  K = 41
A = list(map(int, input().split()))
A.insert(0, 0)
B = [0] * (N+1)
ans = [N] * N

def operation():
  global A, B, N
  for i in range(1, N+1):
    left = max(1, math.ceil(i - A[i] - 0.5))
    right = min(N, math.floor(i + A[i] + 0.5))
    B[left] += 1
    if right+1 <= N:
      B[right+1] -= 1
  for i in range(1, N+1):
    B[i] += B[i-1]


operation()

#print(A)
#print(B)

for _ in range(K):
  for i in range(1, N+1):
    if A[i] != B[i]:
      A[i] = B[i]
    B[i] = 0
  operation()

print(*A[1:])



### FIXED CODE ###

import math

N, K = map(int, input().split())
K = min(41, K)
A = list(map(int, input().split()))
A.insert(0, 0)

def operation():
  global A, N
  B = [0] * (N+1)
  for i in range(1, N+1):
    left = max(1, math.ceil(i - A[i] - 0.5))
    right = min(N, math.floor(i + A[i] + 0.5))
    B[left] += 1
    if right+1 <= N:
      B[right+1] -= 1
  for i in range(1, N+1):
    B[i] += B[i-1]
  return B


operation()

#print(A)
#print(B)

for _ in range(K):
  A = operation()

print(*A[1:])
### BUGGY CODE ###

n = int(input())
n_copy = n
digit_sum = 0

while(n_copy != 0):
    #print(digit_sum, n_copy%10, n_copy//10)
    digit_sum += n_copy%10
    n_copy //= 10

#print(digit_sum)

if digit_sum%9 == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

num = int(input())
print("Yes") if num%9 == 0 else print("No")
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
S = [0]
s = 0
for a in A:
    s += a
    S.append(s)

count = 0
for r in range(1, N+1):
    for l in range(r,N+1):
        if not (S[l] - S[r-1]) % M:
            count += 1

print(count)


### FIXED CODE ###

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

mod_dict = dict()
S_mod = [0]
s = 0
for a in A:
    s += a
    mod = s % M
    S_mod.append(mod)
    if not mod in mod_dict.keys():
        mod_dict[mod] = 1
    else:
        mod_dict[mod] += 1

if 0 in mod_dict.keys():
    count = mod_dict[0]
else:
    count = 0
for key in mod_dict.keys():
    count += (mod_dict[key] - 1) * mod_dict[key] / 2

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

import re

s = input()

while s:
    r = re.search(r"(dream|dreamer|erase|eraser)$", s)
    if r:
        s = s[:r.start()]
    else:
        print("NO")
        break
else:
    print("YES")


### FIXED CODE ###

s = input()[::-1]
ls = [word[::-1] for word in ["dream", "dreamer", "erase", "eraser"]]
i = 0
while s:
    word = ls[i]
    if s.find(word) == 0:
        s = s[len(word):]
        i = 0
    else:
        i += 1
        if i > 3:
            print("NO")
            break
else:
    print("YES")
### BUGGY CODE ###

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

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N+1):
    if (A_accumulate_cost[i] > K):
        break

    for j in range(0,M+1):
        if (A_accumulate_cost[i] + B_accumulate_cost[j] > K):
            break

        if( i+j > max_num):
            max_num = i+j

print(max_num)

### FIXED CODE ###

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

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

print(max_num)
### BUGGY CODE ###

A,B,N=map(int,input().split())
start=0
for i in range(1,N+1):
    K=((A*i)//B)-A*(i//B)
    if start<=K:
        start=K
print(start)

### FIXED CODE ###

import math
A,B,N=map(int,input().split())
start=0
i=min(B-1,N)
K=math.floor((A*i)/B)-A*(math.floor(i/B))
if start<=K:
    start=K
print(start)
### BUGGY CODE ###

k, s = map(int, input().rstrip("\n").split())
count = 0

for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            count += (x + y + z == s)

print(count)


### FIXED CODE ###

k, s = map(int, input().rstrip("\n").split())
count = 0

for x in range(k + 1):
    for y in range(k + 1):
        if x + y > s:
            x = k + 1
            y = k + 1
            continue
        count += (s <= x + y + k)

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

A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A)
for i in range(N-1):
    print(B.count(i+1))
print(0)

### FIXED CODE ###

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

P = [0]*N
for i in range(N-1):
    P[A[i]-1] += 1

for i in range(N):
    print(P[i])
### BUGGY CODE ###

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

days = 0
cand = set(range(N))

while True:
    games = set() # その日に試合ができるプレイヤーの集合
    
    for p in cand:
        if A[p] != []:
            if A[ A[p][0] ][0] == p:
                games.add(p)
                games.add(A[p][0])
    
    if not games: # その日の試合が開催されない
        if any(A): # 未だ組み合わせ希望が残っている
            print(-1) # 大会の組み合わせ希望は実現不可能
            break
        else: # 大会が終了
            print(days)
            break
    else: #その日の試合が開催された
        for i in games:
            A[i].pop(0) # 大会の組み合わせ希望から、該当する試合を取り除く

    days += 1
    # cand = games # 前日試合をした選手の中から、その日試合する選手を選択

### FIXED CODE ###

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

days = 0
cand = set(range(N))

while True:
    games = set() # その日に試合ができるプレイヤーの集合
    
    for p in cand:
        if A[p] != []:
            if A[ A[p][0] ][0] == p:
                games.add(p)
                games.add(A[p][0])
            
    # print(A)
    
    if not games: # その日の試合が開催されない
        if any(A): # 未だ組み合わせ希望が残っている
            print(-1) # 大会の組み合わせ希望は不可能
            break
        else: # 大会が終了
            print(days)
            break
    else:
        for i in games:
            A[i].pop(0)

    days += 1
    cand = games # 前日試合をした選手の中から、その日試合する選手を選択
### BUGGY CODE ###

MAX=100001
array=[True for i in range(MAX)]
array[1]=False

for i in range(2, MAX):
	if array[i]:
		for j in range(2, int(MAX/i)+1):
			if(j*i < MAX):
				array[i*j]=False
Q=int(input())
for i in range(Q):
	l,r=map(int, input().split())
	count=0
	for j in range(l, r+1):
		if array[j] and array[int((j+1)/2)]:
			count+=1
	print(count)


### FIXED CODE ###

MAX=100001
array=[True for i in range(MAX)]
array[1]=False
similar=[True for i in range(MAX)]

for i in range(2, MAX):
	if array[i]:
		for j in range(2, int(MAX/i)+1):
			if(j*i < MAX):
				array[i*j]=False
c=[0 for i in range(MAX)]
count=0

for i in range(2, MAX):
	if array[i] and array[int((i+1)/2)]:
		count+=1

	c[i]=count

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

def main():
    import sys
    input = sys.stdin.buffer.readline
    
    r, c, k = map(int, input().split())
    tizu = [0 for _ in range(r * c)]
    for _ in range(k):
        rr, cc, v = map(int, input().split())
        rr -= 1
        cc -= 1
        tizu[rr * c + cc] = v
        
    dp = [[0, 0, 0, 0] for _ in range(c)]
    dp[0][1] = tizu[0]
    
    for i in range(r):
        for j in range(c):
            v = tizu[i * c + j]
            if i != 0:
                tmp = max(dp[j])
                dp[j][0] = tmp
                dp[j][1] = tmp + v
                dp[j][2] = 0
                dp[j][3] = 0
            if j != 0:
                tmp0 = dp[j - 1][0]
                tmp1 = dp[j - 1][1]
                tmp2 = dp[j - 1][2]
                dp[j][0] = max(dp[j][0], tmp0)
                dp[j][1] = max(dp[j][1], tmp1, tmp0 + v)
                dp[j][2] = max(tmp2, tmp1 + v)
                dp[j][3] = max(dp[j - 1][3], tmp2 + v)
    print(max(dp[-1]))
    
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    
    r, c, k = map(int, input().split())
    tizu = [0 for _ in range(r * c)]
    for _ in range(k):
        rr, cc, v = map(int, input().split())
        tizu[(rr - 1) * c + (cc - 1)] = v
        
    dp = [[0, 0, 0, 0] for _ in range(c)]
    dp[0][1] = tizu[0]
    
    for i in range(r):
        for j in range(c):
            v = tizu[i * c + j]
            if v:
                if i != 0:
                    tmp = max(dp[j])
                    dp[j] = [tmp, tmp + v, 0, 0]
                if j != 0:
                    tmp0 = dp[j - 1][0]
                    tmp1 = dp[j - 1][1]
                    tmp2 = dp[j - 1][2]
                    lst = [max(dp[j][0], tmp0), max(dp[j][1], tmp1, tmp0 + v), max(tmp2, tmp1 + v), max(dp[j - 1][3], tmp2 + v)]
                    dp[j] = lst
            else:
                if i != 0:
                    tmp = max(dp[j])
                    dp[j] = [tmp, 0, 0, 0]
                if j != 0:
                    lst = [max(dp[j][0], dp[j-1][0]), dp[j-1][1], dp[j-1][2], dp[j - 1][3]]
                    dp[j] = lst
    print(max(dp[-1]))
    
main()
### BUGGY CODE ###

ss=0
n=int(input())
while n>0:
	ss+=n%10
	n=n//10
	ss%=9 
if ss==0:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

ss=0
n=input().strip()
for i in range(len(n)):
	ss+=int(n[i])
	ss%=9 
if ss==0:
	print("Yes")
else:
	print("No")
### BUGGY CODE ###

from collections import deque
def solve():
  h,w=map(int,input().split())
  grid=[None]*h
  seen=[[-1 for i in range(w)] for j in range(h)]
  
  que=deque()
  for i in range(h):
    grid[i]=list(input())
    for j in range(len(grid[i])):
      if grid[i][j]=="#":
        grid[i][j]="."
        que.append([i,j,0])
        
  ans=0
  while que:
    node=que.popleft()
    y=node[0]
    x=node[1]
    p=node[2]
    if grid[y][x]=="#":
      continue
    if grid[y][x]==".":
      grid[y][x]="#"
    if y-1>=0:
      que.append([y-1,x,p+1])
    if y+1<h:
      que.append([y+1,x,p+1])
    if x-1>=0:
      que.append([y,x-1,p+1])
    if x+1<w:
      que.append([y,x+1,p+1])
  print(max(p-1,0))

solve()

### FIXED CODE ###

H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

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

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

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

### FIXED CODE ###

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

dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    temp = []
    for j in range(0, min(k, i)):
        temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
    dp[i] = min(temp)
print(dp[n-1])
### BUGGY CODE ###

n=int(input())
cnt=0

for i in range(1,n):
    for j in range(1,int(n)):
        if (n-i) % j ==0:
            cnt+=1
        # print ( f"ここは1回のみカウント：：Ｃは:{i},Aは:{j},Bは：{(n - i) / j}" )
        # print(f"Ｃは:{i},Aは:{j},Bは：{(n-i) / j}")
print(cnt)

### FIXED CODE ###

n=int(input())
cnt=0
for i in range(1,n):
    cnt+=(n-1)//i
        # print(f"Ｃは:{i},Aは:{j},Bは：{(n-i) / j}")
print(cnt)
### BUGGY CODE ###

from collections import Counter

S = input()

"""
counts = Counter()
total = 0
for d in S:
    d = int(d)
    nextCounts = Counter()
    nextCounts[d] += 1
    for k, v in counts.items():
        nextCounts[(10 * k + d) % 2019] += v

    counts = nextCounts
    total += counts[0]
    #print(counts)

print(total)

"""


def modInverse(a, m):
    m0 = m
    y = 0
    x = 1

    if m == 1:
        return 0

    while a > 1:

        # q is quotient
        q = a // m

        t = m

        # m is remainder now, process
        # same as Euclid's algo
        m = a % m
        a = t
        t = y

        # Update x and y
        y = x - q * y
        x = t

    # Make x positive
    if x < 0:
        x = x + m0

    return x


div10 = modInverse(10, 2019)
m = 1
mInv = 1

off = 0
counts = Counter()
total = 0
for d in S:
    d = int(d)
    off = 10 * off + d
    m *= 10
    mInv = (mInv * div10) % 2019
    #assert modInverse(m, 2019) == mInv
    counts[((d - off) * mInv) % 2019] += 1
    total += counts[((0 - off) * mInv) % 2019]

print(total)


### FIXED CODE ###

from collections import Counter

S = input()

"""
counts = Counter()
total = 0
for d in S:
    d = int(d)
    nextCounts = Counter()
    nextCounts[d] += 1
    for k, v in counts.items():
        nextCounts[(10 * k + d) % 2019] += v

    counts = nextCounts
    total += counts[0]
    #print(counts)

print(total)

"""

"""
def modInverse(a, m):
    m0 = m
    y = 0
    x = 1

    if m == 1:
        return 0

    while a > 1:

        # q is quotient
        q = a // m

        t = m

        # m is remainder now, process
        # same as Euclid's algo
        m = a % m
        a = t
        t = y

        # Update x and y
        y = x - q * y
        x = t

    # Make x positive
    if x < 0:
        x = x + m0

    return x
"""


#div10 = modInverse(10, 2019)

div10 = 202
#m = 1
mInv = 1

off = 0
counts = [0 for i in range(2019)]
total = 0
for d in S:
    d = int(d)
    off = (10 * off + d) % 2019
    #m *= 10
    mInv = (mInv * div10) % 2019
    #assert modInverse(m, 2019) == mInv
    counts[((d - off) * mInv) % 2019] += 1
    total += counts[((0 - off) * mInv) % 2019]

print(total)
### BUGGY CODE ###

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

k=[0]*60
K=[0]*60
for i in range(N):
  t=A[i]
  for j in range(60):
    if t%2==1:
      k[j]+=1
    t=t//2
    if t<1:
      break
a=1
sumxor=0
for i in range(60):
  K[i]=k[i]*(N-k[i])
  a=a%(10**9+7)
  sumxor=(sumxor+K[i]*a%(10**9+7))%(10**9+7)
  a=a*2
print(sumxor)

### FIXED CODE ###

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

k=[0]*60
K=[0]*60
for i in range(N):
  t=A[i]
  for j in range(60):
    if t%2==1:
      k[j]+=1
    t=t//2
    if t<1:
      break
a=1
sumxor=0
for i in range(60):
  K[i]=k[i]*(N-k[i])
  a=a%(10**9+7)
  sumxor=(sumxor+K[i]*a%(10**9+7))%(10**9+7)
  a=a*2
print(sumxor)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import bisect

N, Q = [int(x) for x in input().split()]
data = []
for i in range(N):
    S, T, X = [int(x) for x in input().split()]
    data.append([X, S, T])
data.sort()
D = [int(input()) for _ in range(Q)]

ans = [-1]*Q
for X, S, T in data:
    l = bisect.bisect_left(D, S - X - 0.5)
    r = bisect.bisect_right(D, T - X - 0.5)
    for i in range(l, r):
        if ans[i] == -1:
            ans[i] = X

for i in range(Q):
    print(ans[i])


### FIXED CODE ###

import sys
input=sys.stdin.readline
from bisect import bisect_left
n,q=map(int,input().split())
stop=[]
for i in range(n):
	s,t,x=map(int,input().split())
	stop.append((s,t,x))
stop.sort(key=lambda x:x[2])
d=[int(input())for i in range(q)]
R=[-1]*q
ans=[-1]*q
for s,t,x in stop:
	#lからrにある区間のansをxに更新したい
	l=bisect_left(d,s-x)
	r=bisect_left(d,t-x)
	while l<r:
		if R[l]==-1:#最左がまだ確定していない場合
			ans[l]=x
			R[l]=r
			l+=1
		else:
			l=R[l]#確定しているところを飛ばす
for x in ans:
	print(x)