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

import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N

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

event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
working = [] #現在行われている工事のリスト

for i in range(Q):
	event.append((D[i], 2))
	
for i in range(N):
	bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
	bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
	
for l in event:
	if l[1] == 1:
		bisect.insort(working, l[2])
	elif l[1] == 0:
		del working[bisect.bisect(working, l[2]) - 1]
	else:
		if len(working) > 0:
			print(working[0])
		else:
			print(-1)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = map(int, input().split())
S, T, X = [0] * N, [0] * N, [0] * N
work = []

for i in range(N):
	S[i], T[i], X[i] = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(input()) for _ in range(Q)]

work.sort()
ans = [-1] * Q
skip = [-1] * Q

for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]					
		
for i in ans:
	print(i)
### BUGGY CODE ###

N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		for b in B[bif:]:
			ci = bsr(C, b)
			if ci < N:
				r += (N - ci)
			else:
				break
	else:
		break
print(r)


### FIXED CODE ###

N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

print(r)
### BUGGY CODE ###

from copy import deepcopy as de
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for i,b in enumerate(s):
  d=de(a)
  k=0
  for j,c in enumerate(t):
    d[j]+=k
    if b==c:
      k+=a[j]
  d[-1]+=k
  a=de(d)
print(a[-1]%1000000007)
    


### FIXED CODE ###

n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])
### BUGGY CODE ###

s = list(input())
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s = [L[2]] + s
            if L[1] == '2' :
                s = s + [L[2]]
        if head == 1:
            if L[1] == '1' :
                s = s + [L[2]]
            if L[1] == '2' :
                s = [L[2]] + s
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))


### FIXED CODE ###


from collections import deque

s = deque(list(input()))
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s.appendleft(L[2])
            if L[1] == '2' :
                s.append(L[2])
        if head == 1:
            if L[1] == '1' :
                s.append(L[2])
            if L[1] == '2' :
                s.appendleft(L[2])
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))
### BUGGY CODE ###

import bisect
N=int(input())
p_list = list(map(int,input().split()))
p_list.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1,N):
    ans+=max(0,i-bisect.bisect_right(p_list[:i],p_list[j]-p_list[i]))
print(ans)

### FIXED CODE ###

import bisect
N=int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1,N):
    m=bisect.bisect_right(l,l[j]-l[i])
    if i>m:
      ans+=i-m
print(ans)
### BUGGY CODE ###

N, M = map(int,input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

skylist = []
for i in range(M):
    key = list(range(L[i], R[i] + 1))
    skylist.append(key)

for i in range(M):
    if M != 1:
        nice_key = list(set(skylist[0])&set(skylist[1]))
        if i != M-1:
            nice_key = list(set(nice_key)&set(skylist[i+1]))
        else:
            last_key = list(set(nice_key)&set(skylist[-1]))
    elif M ==1:
        last_key = skylist[0][::]

print(len(last_key))




### FIXED CODE ###

n, m = map(int, input().split())
l_lst = [0] * m
r_lst = [0] * m
for i in range(m):
    l, r = map(int, input().split())
    l_lst[i] = l
    r_lst[i] = r

if max(l_lst) <= min(r_lst):
    print(min(r_lst) - max(l_lst) + 1)
else:
    print(0)
### BUGGY CODE ###

n = int(input())
a = input()
q = int(input())
bc = [input().split() for i in range(q)]
for f in bc:
    a = a.replace(f[0], f[1])
    b = list(map(int, a.split()))
    print(sum(b))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]
l = [0] * 100000
suml = 0
for i in a:
  l[i-1] += 1
  suml += i
for i in bc:
  suml += l[i[0]-1] * (i[1] - i[0])
  l[i[1]-1] += l[i[0]-1]
  l[i[0]-1] = 0
  print(suml)
### BUGGY CODE ###

import sys
from collections import Counter
read = sys.stdin.buffer.read
n, *lst = map(int, read().split())

def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]


al = lst[:n]
bl = lst[n:]
a = convert(al)
b = convert(bl)
if Counter(a)!=Counter(b):
  quit()
alal, aa = al + al, a + a
for k in range(n):
    tmp = aa[k:n + k]
    if tmp == b:
        x = alal[k] ^ bl[0]
        print(k, x)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())

A = list(map(int, readline().split()))
B = list(map(int, readline().split()))


def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]


C = convert(A)
D = convert(B)


def Z_algorithm(S):
    # 共通接頭辞の長さを返す
    N = len(S)
    arr = [0] * N
    arr[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        arr[i] = j
        if not j:
            i += 1
            continue
        k = 1

        while i + k < N and k + arr[k] < j:
            k += 1
        i += k
        j -= k

    return arr


Z = Z_algorithm(D + [-1] + C + C)[N + 1:N + N + 1]

K = [i for i, x in enumerate(Z) if x == N]
X = [A[k] ^ B[0] for k in K]

print('\n'.join('{} {}'.format(k, x) for k, x in zip(K, X)))
### BUGGY CODE ###

from collections import deque
n,m,k = map(int,input().split()) 
g = [[] for _ in range(n)]
bl = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

for _ in range(k):
    c,d = map(int,input().split())
    c,d = c-1,d-1
    bl[c].append(d)
    bl[d].append(c)


def bfs(u):
    q = deque([u])
    d = [None]*n
    d[u] = 0
    while q:
        v = q.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                q.append(i)
    return d


for i in range(n):
    ans = 0
    d = bfs(i)
    for j in range(len(d)):
        if j != i and d[j] != None and j not in g[i]:
            if j not in bl[i]:
                ans += 1
    print(ans,end = " ")


### FIXED CODE ###

n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")
### BUGGY CODE ###


def g(n):
    c = 0
    while n > 0:
        p = 0
        n2 = n
        while n2 > 0:
            if n2%2 == 1:
                p += 1

            n2 //= 2

        n %= p
        c += 1

    return c


def h(b, m):
    x = 1
    for _ in range(b):
        x = x*2%m

    return x


def f(N, X):
    b = sum(1 if x == '1' else 0 for x in X)

    Xplus = 0
    Xminus = 0

    for x in X:
        Xplus = (Xplus*2 + (1 if x == '1' else 0))%(b+1)
        
        if b > 1:
            Xminus = (Xminus*2 + (1 if x == '1' else 0))%(b-1)

    for i in range(N):
        if X[i] == '0':
            X2 = (Xplus + h(N-i-1, b+1))%(b+1)
            print(g(X2) + 1)
        elif b > 1:
            X2 = (Xminus - h(N-i-1, b-1))%(b-1)
            print(g(X2) + 1)
        else:
            print(0)


N = int(input())
X = input()
f(N, X)



### FIXED CODE ###

def g(n):
    c = 0
    while n > 0:
        p = 0
        n2 = n
        while n2 > 0:
            if n2%2 == 1:
                p += 1

            n2 //= 2

        n %= p
        c += 1

    return c


def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


# def h(b, m):
#     x = 1
#     for _ in range(b):
#         x = x*2%m

#     return x


def f(N, X):
    b = sum(1 if x == '1' else 0 for x in X)

    Xplus = 0
    Xminus = 0

    for x in X:
        Xplus = (Xplus*2 + (1 if x == '1' else 0))%(b+1)
        
        if b > 1:
            Xminus = (Xminus*2 + (1 if x == '1' else 0))%(b-1)

    for i in range(N):
        if X[i] == '0':
#            X2 = (Xplus + h(N-i-1, b+1))%(b+1)
            X2 = (Xplus + modPow(2, N-i-1, b+1))%(b+1)
            print(g(X2) + 1)
        elif b > 1:
#            X2 = (Xminus - h(N-i-1, b-1))%(b-1)
            X2 = (Xminus - modPow(2, N-i-1, b-1))%(b-1)
            print(g(X2) + 1)
        else:
            print(0)


N = int(input())
X = input()
f(N, X)
### BUGGY CODE ###

import sys,collections;sys.setrecursionlimit(10**7)
import itertools
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
Q = I()
for q in range(Q):
    l,r = Is()
    maho = 0
    for k in range(l,r,D):
        maho += abs(d[k+D][0] - d[k][0]) + abs(d[k+D][1] - d[k][1])
    print(maho)

### FIXED CODE ###

import sys
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
m = [0]*(H*W+1)
for i in range(D+1,H*W+1):
    m[i] = m[i-D] + abs(d[i-D][0] - d[i][0]) + abs(d[i-D][1] - d[i][1])

Q = I()
for q in range(Q):
    l,r = Is()
    print(m[r]-m[l])
### BUGGY CODE ###

#!/usr/bin/env python3
# 整数の入力
k = int(input())

x = 7%k
s=[]
i = 1
while(s.count(x) == 0):
    if x == 0:
        print(i)
        exit(0)
    s.append(x)
    x=(10*x+7)%k
    i += 1

print(-1)







### FIXED CODE ###

#!/usr/bin/env python3
# 整数の入力
k = int(input())

x = 7%k
for i in range(1, k+1):
    if x == 0:
        print(i)
        exit(0)
    x=(10*x+7)%k

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

n = int(input())
r = 1
for i in range(n):
	r = r * (i + 1)
r = r % (10**9 + 7)
print(r)

### FIXED CODE ###

n = int(input())
r = 1
for i in range(n):
	r = (r * (i + 1)) % (10**9 + 7)
print(r)
### BUGGY CODE ###

K, S = map(int, input().split())
ans =0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k == S:
        ans += 1
print(ans)

### FIXED CODE ###

K, S = map(int, input().split())
ans =0
for i in range(K+1):
  for j in range(K+1):
    if S-i-j<=K and S-i-j>=0:
      ans += 1
print(ans)
### BUGGY CODE ###

class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


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


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

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
def compute_mst_kruskal(N, edges):#N = 頂点数、edges 0-indexed
    edges = sorted(edges, key = lambda x:x[2])
    UF = UnionFind(N)
    cost = 0
    for edge in edges:
        x, y, w = edge
        if not UF.same(x, y):
            UF.unite(x, y)
            cost+=w
    return cost
N = int(input())
ixy = []
for i in range(N):
    x, y = map(int, input().split())
    ixy.append((i, x, y))
xy_x = sorted(ixy, key = lambda x:x[1])
xy_y = sorted(ixy, key = lambda x:x[2])
edges = []
for i in range(N-1):
    i1, x1, y1 = xy_x[i]
    i2, x2, y2 = xy_x[i+1]
    edges.append((i1, i2, x2-x1))
    i1, x1, y1 = xy_y[i]
    i2, x2, y2 = xy_y[i+1]
    edges.append((i1, i2, y2-y1))
ans = compute_mst_kruskal(N, edges)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


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


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

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
def compute_mst_kruskal(N, edges):#N = 頂点数、edges 0-indexed
    edges = sorted(edges, key = lambda x:x[2])
    UF = UnionFind(N)
    cost = 0
    for edge in edges:
        x, y, w = edge
        if not UF.same(x, y):
            UF.unite(x, y)
            cost+=w
    return cost
N = int(input())
ixy = []
for i in range(N):
    x, y = map(int, input().split())
    ixy.append((i, x, y))
xy_x = sorted(ixy, key = lambda x:x[1])
xy_y = sorted(ixy, key = lambda x:x[2])
edges = []
for i in range(N-1):
    i1, x1, y1 = xy_x[i]
    i2, x2, y2 = xy_x[i+1]
    edges.append((i1, i2, x2-x1))
    i1, x1, y1 = xy_y[i]
    i2, x2, y2 = xy_y[i+1]
    edges.append((i1, i2, y2-y1))
ans = compute_mst_kruskal(N, edges)
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

S = input()
N = int(input())
rev_flg=False
head = []
tail = []
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not rev_flg:
			rev_flg = True
		else:
			rev_flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not rev_flg:
				head.append(Q[2])
			else:
				tail.append(Q[2])
		if Q[1] == "2":
			if not rev_flg:
				tail.append(Q[2])
			else:
				head.append(Q[2])
S = "".join(head[::-1])+S+"".join(tail)
#print(head,tail)
#print(S)
if rev_flg:
	S =S[::-1]
print(S)
### BUGGY CODE ###

MOD = 10 ** 9 + 7

def solve():
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    
    if N == 1 and M == 0:
        return 1
    elif N == 1 and M == 1 and A[0] == 0:
        return 0

    dp = [0] * (N+1)
    dp[1] = 0 if 1 in A else 1
    dp[2] = 0 if 2 in A else dp[1] + 1

    for i in range(3, N+1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD

    return dp[N] % MOD

print(solve())

### FIXED CODE ###

MOD = 10 ** 9 + 7

def solve():
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    
    if N == 1 and M == 0:
        return 1
    elif N == 1 and M == 1 and A[0] == 0:
        return 0

    l = [1 for _ in range(N+1)]
    for a in A:
        l[a] = 0
        
    dp = [0 for i in range(N+1)]
    dp[1] = 0 if 1 in A else 1
    dp[2] = 0 if 2 in A else dp[1] + 1

    for i in range(3, N+1):
        if l[i] == 0:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD

    return dp[N] % MOD

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

def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    # print(A)
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    # print(N, i1, i2)

    # N+1_C_l
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    pow2 = [1, 1]
    for i in range(2, N+2):
        j = powquick(i, div-2, div)
        pow2.append(pow2[-1]*j % div)

    # pow2 = [1, 1]
    # inv = [0, 1]
    # for i in range(2, N+2):
    #     inv.append((-inv[div % i]) *(div // i) % div)
    #     pow2.append(pow2[-1] * inv[-1] % div)

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        # print(v)
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)

def powquick(x, y, div):
        if y == 0: return 1
        if y == 1: return x % div
        if y % 2 == 0: return pow(powquick(x, y // 2, div), 2) % div
        if y % 2 == 1: return pow(powquick(x, y// 2, div), 2) * x % div


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    # print(A)
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    # print(N, i1, i2)

    # N+1_C_l
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    # pow2 = [1, 1]
    # for i in range(2, N+2):
    #     j = powquick(i, div-2, div)
    #     pow2.append(pow2[-1]*j % div)

    pow2 = [1, 1]
    inv = [0, 1]
    for i in range(2, N+2):
        inv.append((-inv[div % i]) *(div // i) % div)
        pow2.append(pow2[-1] * inv[-1] % div)

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        # print(v)
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)

def powquick(x, y, div):
        if y == 0: return 1
        if y == 1: return x % div
        if y % 2 == 0: return pow(powquick(x, y // 2, div), 2) % div
        if y % 2 == 1: return pow(powquick(x, y// 2, div), 2) * x % div


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

def solve():
  n,m = (int(i) for i in input().split())
  a = []
  b = []
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a.append(a1)
    b.append(b1)
  ans = 'YES'
  for i in range(1,n+1):
   if (a.count(i)+b.count(i))%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())

### FIXED CODE ###

def solve():
  n,m = (int(i) for i in input().split())
  a = [0]*n
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a[a1-1]+=1
    a[b1-1]+=1
  ans = 'YES'
  for i in range(n):
   if a[i]%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())
### BUGGY CODE ###

import copy

count = int(input())

ls = []

for i in range(count):
    ls.append(input())

buff = copy.copy(ls)
ls2 = set(buff)

max = 0
ans = []

for s in ls2:
    if ls.count(s) >= max:
        if ls.count(s) > max:
            ans.clear()

        ans.append(s)
        max = ls.count(s)

print('\n'.join(sorted(ans)))

### FIXED CODE ###

count = int(input())

ls = {}

for i in range(count):
    s = input()
    if s in ls:
        ls[s] += ls[s] + 1
    else:
        ls.setdefault(s, 1)

m = max(ls.values())

ans = [k for k, v in ls.items() if v == m]

print('\n'.join(sorted(ans)))
### BUGGY CODE ###

from collections import deque

class Tree:
    def __init__(self, n, init_list, root=1):
        self.num = (n + 1)
        self.parents = [-1] * self.num
        self.first_child = [-1] * self.num
        self.next_child = [-1] * self.num
        self.check = [-1] * self.num
        self.g = {i: [] for i in range(1, self.num)}
        self.make_g(init_list, root)

    def make_g(self, con, root):
        m = len(con)
        for i in range(m):
            self.g[con[i][0]].append(con[i][1])
            self.g[con[i][1]].append(con[i][0])
        q = deque([root])
        while q != deque():
            node = q.pop()
            self.check[node] = 1
            cnt = 0
            for i, sub_node in enumerate(self.g[node]):
                if self.check[sub_node] != -1:
                    continue
                if cnt == 0:
                    self.first_child[node] = sub_node
                self.parents[sub_node] = node
                if i != len(self.g[node])-1:
                    self.next_child[sub_node] = self.g[node][i+1]
                q.append(sub_node)
                cnt += 1

    def childs(self, node):
        child_list = []
        if self.first_child[node] != -1:
            child_list.append(self.first_child[node])
            node = self.first_child[node]
            while 1:
                if self.next_child[node] == -1:
                    break
                else:
                    child_list.append(self.next_child[node])
                node = self.next_child[node]
        return child_list

    def parent(self, n):
        return self.parents[n]

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N-1)]
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

tr = Tree(N, AB)
# 800ms

q = deque()
q.extend(tr.childs(1))
while q:
    node = q.pop()
    V[node] += V[tr.parent(node)]
    tmp = tr.childs(node)
    if tmp:
        q.extend(tmp)

print(*V[1:])

### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
AB = {i: set() for i in range(1, N+1)}
for i in range(N - 1):
    tmpA, tmpB = map(int, input().split())
    AB[tmpA].add(tmpB)
    AB[tmpB].add(tmpA)
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

check = [0]*(N + 1)
q = deque()
q.append(1)
check[1] = 1
while q != deque():
    node = q.pop()
    for i in AB[node]:
        if check[i] == 1:
            continue
        V[i] += V[node]
        check[i] = 1
        q.appendleft(i)
print(*V[1:])