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

N,M = map(int,input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
for i in range(M):
    A,B = map(int,input().split())
    a[i] = A
    b[i] = B

ans = 0
while 1:
    if len(a) == 0:
        break
    maxVal = max(a)
    maxIdx = a.index(maxVal)

    for j in reversed(range(len(a))):
        if a[j] <= maxVal <= b[j] - 1:
            a.pop(j)
            b.pop(j)

    ans += 1

print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
listAB = [list(map(lambda x:int(x),input().split())) for i in range(M)]
# 要素の2番目でソート
listAB.sort(key=lambda x: x[1])
# 最後に切った橋の位置
last = -1
ans = 0
for a,b in listAB:
    # 切った橋より右側に依頼があるか
    if last <= a:
        ans += 1
        # 切った位置はbの位置
        last = b

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

#coding: utf-8
m,n = map(int,input().split())
# div = [0]
div = [1]
flg = 0

if m % 2 == 0 and n % 2 == 0:
    div.append(2)

# while i < 0:
    # if m 
for i in range(3,m):
    if m % i == 0 and n % i == 0 and i % 2 == 1:
        # ans += 1
        # m = m / i
        # n = n / i
        for j in range(1,len(div)):
            if i % div[j] == 0:
                flg = 1
                break
        if flg == 0:
            div.append(i)
        else:
            flg = 1
    

    # print(student[i]-1)
    # toukou[student[i]-1] = i+1
# print(" ".join(map(str,div)))
print(len(div))


### FIXED CODE ###

#coding: utf-8
from fractions import gcd
import math

# GCDの約数を素因数分解する
def primeFactor(n):
    flg = 0
    count = 0
    tmp = math.sqrt(n)
    i = 2

    if n == 1:
        return 1

    while i <= tmp:
        # print(str(i)+str(',')+str(gcd_cnt))
        if n % i == 0:
            if flg == 0:
                flg = 1
                count += 1
            n = n // i
        else:
            flg = 0
            i += 1
    # if flg == 1:
    #     count += 1
    # print(str('素数=')+str(count)+str(' n=')+str(n)+str(' i=')+str(i))
    if n > 1:
        count += 1
    # 1を足す
    count += 1
    return count


# # print(len(div))
m,n = map(int,input().split())
p = gcd(m,n)
# print(str('gcd=')+ str(p))
ans = primeFactor(p)
print(ans)
### BUGGY CODE ###

n,q=map(int, input().split())
s=input()
for i in range(q):
    l,r=map(int, input().split())
    w=s[l-1:r]
    print(w.count('AC'))

### FIXED CODE ###

n,q=map(int, input().split())
s=input()
num_ac=[0 for i in range(n)]
#num_ac[i]はi+1文字目までのACの数？
for i in range(1,n):
    num_ac[i]=num_ac[i-1]
    if s[i]=='C' and s[i-1]=='A':
        num_ac[i]+=1
for i in range(q):
    l,r=map(int,input().split())
    print(num_ac[r-1]-num_ac[l-1])
### BUGGY CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))

memo = {}


def step(now):

    if now in a:
        return 0
    # print(now)
    if now == n:
        return 1
    if now > n:
        return 0
    if memo.get(now) != None:
        return memo[now]
    # print(now)
    memo[now] = step(now+1)+step(now+2)
    return memo[now]


print(step(0) % 1000000007)
# print(memo)

### FIXED CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))
a=set(a)

memo = [0]*(n+1)
memo[0]=1
if not(1 in a):
    memo[1]=1

for i in range(2,n+1):
    #print(i)
    if i in a:
        continue
    #print(memo[i-1],memo[i-2])
    memo[i]=memo[i-2]+memo[i-1]
            

#print(memo)
print(memo[n]% 1000000007)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(n):
    ans+=i
print(ans)


### FIXED CODE ###

n=int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
anslist = [[0]*3for i in range(m)]
for i in range(m):
  p,y = map(int,input().split())
  anslist[i][0] = p
  anslist[i][2] = y
  cnt = 0
  if i >= 1:
    for j in range(i):
      if anslist[j][0] == p and anslist[j][2] > y:
        anslist[j][1] += 1
      elif anslist[j][0] == p and anslist[j][2] < y:
        cnt += 1
    else:anslist[i][1] = cnt + 1
  else:
    anslist[i][1] = 1
for i in range(m):
  #print(anslist[i][0],anslist[i][1])
  print('0'*(6-len(str(anslist[i][0])))+str(anslist[i][0])+'0'*(6-len(str(anslist[i][1])))+str(anslist[i][1]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())

row = [N - 2] * (N + 2)
col = [N - 2] * (N + 2)
ans = (N - 2)**2

miCol = N
miRow = N

for _ in range(Q):
    q, x = map(int, input().split())

    if q == 1:
        ans -= row[x]
        for i in range(miCol + 1):
            col[i] = min(col[i], x - 2)
        miRow = min(miRow, x)
    if q == 2:
        ans -= col[x]
        for i in range(miRow + 1):
            row[i] = min(row[i], x - 2)
        miCol = min(miCol, x)

print(ans)


### FIXED CODE ###

class MinSegTree:
    """
    0-indexed
    query : [L, R)
    """
    def __init__(self, size):
        self.size = 1 << (size.bit_length())  # 完全二分木にする
        self.data = [INF] * (2 * self.size - 1)

    def build(self, rawData):
        self.data[self.size - 1: self.size - 1 + len(rawData)] = rawData
        for i in range(self.size - 1)[:: -1]:
            self.data[i] = min(self.data[2 * i + 1], self.data[2 * i + 2])

    def update(self, index, value):
        index += self.size - 1
        if self.data[index] <= value:
            return
        self.data[index] = value
        while index >= 0:
            index = (index - 1) // 2
            self.data[index] = min(self.data[2 * index + 1], self.data[2 * index + 2])

    def query(self, left, right):
        L = left + self.size
        R = right + self.size
        ret = INF
        while L < R:
            if R & 1:
                R -= 1
                ret = min(ret, self.data[R - 1])
            if L & 1:
                ret = min(ret, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return ret

N, Q = map(int, input().split())
INF = N - 2
treeRow = MinSegTree(N + 2)
treeCol = MinSegTree(N + 2)

miRow = N - 1
miCol = N - 1
ans = (N - 2)**2

for q in range(Q):
    q, x = map(int, input().split())

    if q == 1:
        col = x
        ans -= treeRow.query(col, N)
        miCol = min(col, miCol)
        treeCol.update(miRow, col - 2)
    if q == 2:
        row = x
        ans -= treeCol.query(row, N)
        miRow = min(row, miRow)
        treeRow.update(miCol, row - 2)

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

import sys
sys.setrecursionlimit(10**7)

def max_happiness(n, data, a, b, c):
  if n == 0:
    if a and b:
      return max(data[n][0], data[n][1])
    elif b and c:
      return max(data[n][1], data[n][2])
    elif c and a:
      return max(data[n][2], data[n][0])
  
  max_a = -1
  max_b = -1
  max_c = -1
  
  if a:
    max_a = data[n][0] + max_happiness(n-1, data, a=False, b=True, c=True)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, a=True, b=False, c=True)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, a=True, b=True, c=False)
    
  return max(max_a, max_b, max_c)

N = int(input())
data = []
for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, a=True, b=True, c=True))

### FIXED CODE ###

import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)

def max_happiness(n, data, dp, a, b, c):
  string = str(n) + str(a) + str(b) + str(c)

  if dp[string] is not None:
    return dp[string]

  if n == 0:
    if a and b:
      dp[string] = max(data[n][0], data[n][1])
      return dp[string]
    elif b and c:
      dp[string] = max(data[n][1], data[n][2])
      return dp[string]
    elif c and a:
      dp[string] = max(data[n][2], data[n][0])
      return dp[string]

  max_a = -1
  max_b = -1
  max_c = -1

  if a:
    max_a = data[n][0] + max_happiness(n-1, data, dp, a=0, b=1, c=1)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, dp, a=1, b=0, c=1)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, dp, a=1, b=1, c=0)

  dp[string] = max(max_a, max_b, max_c)
  return dp[string]

N = int(input())
data = []
dp = defaultdict(lambda: None)

for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, dp, a=1, b=1, c=1))
### BUGGY CODE ###

k = int(input())

Queue = [i for i in range(1, 10, 1)]

cnt = 1

while(cnt <= k) : 
    x = Queue.pop(0)
    xx = x
    if len(str(xx)) >= 2 : 
        while(len(str(xx)) >= 2) : 
            xx = xx % 10
    for i in range(0, 10, 1) : 
        if abs(xx - i) <= 1 : 
            y = int("".join(map(str, [x, i])))
            Queue.append(y)
    cnt += 1
            
print(x)

### FIXED CODE ###

k = int(input())

Queue = [i for i in range(1, 10, 1)]

cnt = 0

while(cnt < k) : 
    cnt += 1
    x = Queue.pop(0)
    
    if cnt + len(Queue) >= k : 
        continue
    
    xx = x
    if len(str(xx)) >= 2 : 
        while(len(str(xx)) >= 2) : 
            xx = xx % 10

    ## 1つ目            
    if xx != 0 : 
        y = int("".join(map(str, [x, xx-1])))
        Queue.append(y)
        
    ## 2つ目            
    y = int("".join(map(str, [x, xx])))    
    Queue.append(y)

    ## 3つ目            
    if xx != 9 : 
        y = int("".join(map(str, [x, xx+1])))
        Queue.append(y)


print(x)
### BUGGY CODE ###

from itertools import accumulate
from collections import defaultdict
import sys

def input(): return sys.stdin.readline().strip()

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = [0]+[i-1 for i in A]
sumA = list(accumulate(A))
sumA = [i % K for i in sumA]
x = sumA[:K]
modmap = defaultdict(int)
ans = 0
for i in x:
    modmap[i] += 1

for i in range(K):
    t = modmap[i]
    ans += t * (t-1) // 2

for i in range(N-K+1):
    modmap[sumA[K+i]] += 1
    modmap[sumA[i]] -= 1
    ans += modmap[sumA[K+i]]-1

print(ans)

### FIXED CODE ###

import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [i-1 for i in a]
suma = [0]+list(accumulate(a))
suma = [i%k for i in suma]
rem = defaultdict(int)
ans = 0
if k > n:
    for i in range(n+1):
        x = suma[i]
        rem[x] += 1
    for s in rem.values():
        ans += s*(s-1)//2
    print(ans)
    exit()
for i in range(k):
    x = suma[i]
    rem[x] += 1
for s in rem.values():
    ans += s*(s-1)//2
for i in range(n-k+1):
    rem[suma[i]%k] -= 1
    rem[suma[i+k]%k] += 1
    ans += rem[suma[i+k]] -1
print(ans)
### BUGGY CODE ###

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

d = {}
for ai in a:
  if not ai in d:
    d[ai] = a.count(ai)

cnt = 0
for key, value in d.items():
  if key > value:
    cnt = cnt + value
  elif key < value:
    cnt = cnt + value - key

print(cnt)

### FIXED CODE ###

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

d = {}
for ai in a:
  if ai in d:
    d[ai] = d[ai] + 1
  else:
    d[ai] = 1

cnt = 0
for key, value in d.items():
  if key > value:
    cnt = cnt + value
  elif key < value:
    cnt = cnt + value - key

print(cnt)
### BUGGY CODE ###

N, K = [int(i) for i in input().split(' ')]
MOD = 10 ** 9 + 7

COUNT = {}
for i in range(K,0,-1):
    whole = (K//i)**N

    c = 2
    while i * c <= K:
        whole -= COUNT[i*c]
        c += 1

    COUNT[i] = whole % MOD

SUM = 0
for k, v in COUNT.items():
    SUM += k * v
    SUM %= MOD

print(SUM)


### FIXED CODE ###

N, K = [int(i) for i in input().split(' ')]
MOD = 10 ** 9 + 7

COUNT = {}
for i in range(K,0,-1):
    whole = pow((K//i), N, MOD)

    c = 2
    while i * c <= K:
        whole -= COUNT[i*c]
        c += 1

    COUNT[i] = whole % MOD

SUM = 0
for k, v in COUNT.items():
    SUM += k * v
    SUM %= MOD

print(SUM)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0

for r in range(3001):
    for g in range(3001):
        v = R * r + G * g
        if N >= v and (N - v) % B == 0:
            ans += 1

print(ans)


### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    if R * r <= N:
        for g in range(min(3000, 3000 // G) + 1):
            v = R * r + G * g
            if N >= v and (N - v) % B == 0:
                ans += 1

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

from collections import deque

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

    read = deque()

    while sum(read) <= K:
        if len(A) == 0 and len(B) == 0:
            break

        if len(A) == 0:
            if sum(read) + B[0] <= K:
                read.append(B[0])
            B.pop(0)
            continue

        if len(B) == 0:
            if sum(read) + A[0] <= K:
                read.append(A[0])
            A.pop(0)
            continue

        if A[0] < B[0]:
            if sum(read) + A[0] <= K:
                read.append(A[0])
            A.pop(0)
        else:
            if sum(read) + B[0] <= K:
                read.append(B[0])

            B.pop(0)

    print(len(read))


resolve()

### FIXED CODE ###

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

    ans = 10 ** 10
    t = 0

    for i in range(M):
        t += B[i]
    j = M
    ans = 0
    for i in range(N+1):
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        
        if t > K:
            break
        
        ans = max(ans, i+j)
        
        if i == N:
            break
        t += A[i]
    
    print(ans)

resolve()
### BUGGY CODE ###

def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"


### FIXED CODE ###

def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N / (N / K + 1) 
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"
### BUGGY CODE ###

N,K=map(int,input().split())
s=list(map(int,input().split()))
t=list(set(s))
ss,ans=[],0
for i in t:
    ss.append(s.count(i))
    ss=sorted(ss)
if len(ss)>K:
    for i in range(len(ss)-K):
        ans+=ss[i]
    print(ans)      
else:
    print("0")

### FIXED CODE ###

N,K=map(int,input().split())
d,ans={},0
for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
s=sorted(d.values())
for i in range(len(s)-K):
    ans+=s[i]
print(ans)
### BUGGY CODE ###

K, Q = map(int, input().split())
D = [int(a) for a in input().split()]
for _ in range(Q):
    N, X, M = map(int, input().split())
    t = X%M
    for i in range(K):
        t += ((D[i]-1) % M + 1) * ((N-i-2) // K + 1)
    print(N - 1 - t//M)

### FIXED CODE ###

K, Q = map(int, input().split())
D = [int(a) for a in input().split()]
for _ in range(Q):
    N, X, M = map(int, input().split())
    if N <= K + 1:
        A = [0] * N
        A[0] = X % M
        ans = 0
        for i in range(N-1):
            A[i+1] = (A[i] + D[i]) % M
            if A[i+1] > A[i]:
                ans += 1
        print(ans)
        continue
    ans = N - 1
    t = X%M
    for i in range(K):
        d = (D[i]-1) % M + 1
        a = (N-i-2) // K + 1
        t += d * a
    ans -= t // M
    print(ans)
### BUGGY CODE ###

from collections import deque

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque()
for i in range(H):
    a = input()
    for j in range(W):
        if a[j] == "#":
            q.append([i, j, 0])
            dist_map[i][j] = 0

max_dist = 0

while len(q) > 0:
    current_h, current_w, dist = q.popleft()
    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if dist_map[nh][nw] != INF:
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


### FIXED CODE ###

from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)
### BUGGY CODE ###

# seishin.py
import sys
sys.setrecursionlimit(10**6)
N = int(input())
*P, = map(int, input().split())
MOD = 10**9 + 7
from itertools import tee

G = [[] for i in range(N+1)]
for i, p in enumerate(P):
    G[p].append(i+1)
Q = [None]*(N+1)
E = [1, 1, 0, 1]
for i in range(N, -1, -1):
    def gen(i):
        *I, = map(Q.__getitem__, G[i])
        r = E
        while r:
            a,b,c,d=r
            yield (a+c,b,0,d)
            r = None
            for it in I:
                s = next(it, None)
                if s:
                    if r:
                        a0, a1, a2, c0 = s
                        b0, b1, b2, c1 = r
                        r = a0*b0 % MOD, (a0*b1 + a1*b0) % MOD, ((a0 + a1)*b2 + a1*b1) % MOD, c0+c1
                    else:
                        r = s
    Q[i] = gen(i)
ans = 0
for a0, a1, a2, c in Q[0]:
    ans += pow(2, N+1-c, MOD) * a1 % MOD
print(ans % MOD)

### FIXED CODE ###

# seishin.py
from collections import deque
N = int(input())
*P, = map(int, input().split())
MOD = 10**9 + 7

G = [[] for i in range(N+1)]
U = [0]*(N+1)
C = [0]*(N+1)
for i, p in enumerate(P):
    G[p].append(i+1)
    U[i+1] = u = U[p]+1
    C[u] += 1
Q = [None]*(N+1)
PP = {}
def pp(k):
    if k not in PP:
        PP[k] = p = pow(2, k, MOD)
        return p
    return PP[k]
L = [0]*(N+1)

ept = []
sz = L.__getitem__
for i in range(N, -1, -1):
    g = G[i]
    if not g:
        continue

    # 子ノードのdequeを集める
    g.sort(key=sz, reverse=1)
    k = len(g)
    e = [pp(k) - k, k, 0]

    g0 = g[0]
    L[i] = L[g0] + 1
    if L[g0] == 0:
        Q[i] = deque([e])
        continue
    Q[i] = R = Q[g0]
    if k > 1:
        # a0 <- a2
        for s, r in zip(Q[g[1]] or ept, R):
            r[0] += r[2]; r[2] = 0

        for j in g[1:]:
            S = Q[j]
            if not S:
                break

            # dequeの小さい方から大きい方へマージする処理
            for (a0, a1, a2), r in zip(S, R):
                b0, b1, b2 = r; a0 += a2
                r[0] = a0*b0 % MOD
                r[1] = (a0*b1 + a1*b0) % MOD
                r[2] = ((a0+a1)*b2 + a1*b1) % MOD
    R.appendleft(e)
print((pp(N) + sum(pp(N+1-c) * a1 % MOD for (a0, a1, a2), c in zip(Q[0], C[1:]))) % MOD)
### BUGGY CODE ###

# input
N, M = map(int, input().split())

citys = []
c_append = citys.append
prefs = []
p_append = prefs.append
for i in range(M):
    P, Y = map(int, input().split())
    if P not in prefs:
        p_append(P)

    c_append(
        {
            "birth": Y,
            "pref": P,
            "number": "0" * (6 - len(str(P))) + str(P)
        }
    )

# check
for p in prefs:
    target_citys = [
        c
        for c in citys
        if c["pref"] == p
    ]
    target_citys.sort(key=lambda x: x["birth"])
    lot_num = 1
    for c in target_citys:
        c["number"] += "0" * (6 - len(str(lot_num))) + str(lot_num)
        lot_num += 1

for c in citys:
    print(c["number"])

### FIXED CODE ###

N, M = map(int, input().split())
piys = [[] for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y, i))

ans = [None]*M
for p, iys in enumerate(piys):
    iys.sort()
    for k, (y, i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1, k+1)

for i in ans:
    print(i)
### BUGGY CODE ###

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

for i in range(n):
    a = x[:]
    del a[i]
    a.sort()
    print(a[int((len(a)+1)/2)-1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
a = x[:]
a.sort()

mid = n //2
m1 = a[mid-1]
m2 = a[mid]
for i in range(n):
    if x[i] <= m1:
        ans = m2
    else:
        ans = m1
 
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import heapq
from operator import itemgetter
from bisect import bisect_right
N, Q = map(int, input().split())
Stop = []
for i in range(N):
    S, T, X = map(int, input().split())
    Stop.append([S - X, X, 0, i])
    Stop.append([T - X, X, 1, i])
Stop.sort(key=itemgetter(0))
q = []
notClosed = [False]*N
A = [(-1, -1)]
for time, pos, lr, idx in Stop:
    if lr==0:
        heapq.heappush(q, (pos, time, idx))
    else:
        notClosed[idx] = True
        while len(q)>0 and notClosed[q[0][2]]:
            aaa = heapq.heappop(q)[2]

    if len(q):
        A.append((time, q[0][0]))
    else:
        A.append((time, -1))
for _ in range(Q):
    D = int(input())
    idx = bisect_right(A, (D, 1<<60))

    print(A[idx-1][1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
import heapq
from operator import itemgetter
from bisect import bisect_right
N, Q = map(int, input().split())
Stop = []
for i in range(N):
    S, T, X = map(int, input().split())
    Stop.append([S - X, X, 0, i])
    Stop.append([T - X, X, 1, i])
Stop.sort(key=itemgetter(0))
q = []
notClosed = [False]*N
A = [(-1, -1)]
for time, pos, lr, idx in Stop:
    if lr==0:
        heapq.heappush(q, (pos, idx))
    else:
        notClosed[idx] = True
        while len(q)>0 and notClosed[q[0][1]]:
            aaa = heapq.heappop(q)[1]

    if len(q):
        A.append((time, q[0][0]))
    else:
        A.append((time, -1))
A0 = list(map(itemgetter(0), A))
for _ in range(Q):
    D = int(input())
    idx = bisect_right(A0, D)

    print(A[idx-1][1])
### BUGGY CODE ###

N=int(input())
# N=7
A=list(map(int,input().split()))
A=sorted(A)
B=[]
for i in range(N):
    for j in A:
        if j-1==i:
            B.append(j)
    print(len(B))
    B=[]

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')