Harryxun/stf_run huggingface dataset:
N,Q = map(int,input().split())
AB = [[] for _ in range(N-1)]
for n in range(N-1):
    AB[n] = list(map(int,input().split()))
PX = [[] for _ in range(Q)]
for q in range(Q):
    PX[q] = list(map(int,input().split()))
graph = [[] for _ in range(N+1)]
for ab in AB:
    graph[ab[0]].append(ab[1])
    graph[ab[1]].append(ab[0])
val = [0] * (N+1)
for px in PX:
    val[px[0]] += px[1]
parent = [0] * (N+1)
Q  = [1]
while Q:
    q = Q.popleft()
    for c in graph[q]:
        if c == parent[q]:
            continue
        parent[c] = q
        Q.append(c)
        val[c] += val[q]
print(*val[1:])


### FIXED CODE ###

N,Q = map(int,input().split())
AB = [[] for _ in range(N-1)]
for n in range(N-1):
    AB[n] = list(map(int,input().split()))
PX = [[] for _ in range(Q)]
for q in range(Q):
    PX[q] = list(map(int,input().split()))
graph = [[] for _ in range(N+1)]
for ab in AB:
    graph[ab[0]].append(ab[1])
    graph[ab[1]].append(ab[0])
val = [0] * (N+1)
for px in PX:
    val[px[0]] += px[1]
parent = [0] * (N+1)
from collections import deque
Q  = deque([1])
while Q:
    q = Q.popleft()
    for c in graph[q]:
        if c == parent[q]:
            continue
        parent[c] = q
        Q.append(c)
        val[c] += val[q]
print(*val[1:])
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp,)
print(hp)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)
n = int(input())
sum = 0
 
for i in range(n+1):
    if i % 3 == 0:
        print(Fizz)
    elif i % 5 == 0:
        print(Buzz)
    elif i % 15 == 0:
        print(FizzBuzz)
    else:
     sum += i
 
print (sum)

### FIXED CODE ###

n = int(input())
sum = 0
 
for i in range(n+1):
    if i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    elif i % 15 == 0:
        pass
    else:
     sum += i
 
print (sum)
a=int(input())
X=int(input())
if(a*500>=X):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

if(a*500>=X):
    print('Yes')
else:
    print('No')
n, x, y = map(int, input().split())
graph = dict()
for i in range(1, n+1):
    if i not in graph.keys():
        graph[i] = set()
    if i < n:
        graph[i].add(i+1)
    if i > 1:
        graph[i].add(i-1)
graph[x].add(y)
graph[y].add(x)
dist = [[]]


def bfs(source):
    q = deque()
    q.append(source)
    d = [pow(10, 4)] * (n+1)
    d[source] = 0
    vis = [0] * (n+1)
    while len(q):
        temp = q.popleft()
        for i in graph[temp]:
            if not vis[i]:
                q.append(i)
                vis[i] = 1
            d[i] = min(d[temp]+1, d[i])
    dist.append(d)


for i in range(1, n+1):
    bfs(i)


dp = dict()
for i in range(1, n):
    for j in range(i+1, n+1):
        if dist[i][j] not in dp.keys():
            dp[dist[i][j]] = 0
        dp[dist[i][j]] += 1

for i in range(1, n):
    if i not in dp.keys():
        print(0)
    else:
        print(dp[i])

### FIXED CODE ###

"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache
from collections import defaultdict as dd
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, x, y = sp()
dp = dd(int)
for i in range(1, n):
    for j in range(i+1, n+1):
        answer = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        dp[answer] += 1
for i in range(1, n):
    outln(dp[i])
import math
N,M=map(int,input().split())
def primecheck(K):
    A=int(math.sqrt(K))+1
    for i in range(2,A+1):
        if K%i==0:
            return i
    return 1
D=dict()
while(True):
    X=int(math.sqrt(M))+1
    for i in range(2,X+1):
        if M%i==0:
            while(True):
                if i in D:
                    D[i]+=1
                else:
                    D[i]=1
                M=M//i
                if M%i!=0:
                    break
    j=primecheck(M)
    if j==1:
        if M==1:
            break
        D[M]=1
        break
    else:
        if j in D:
            D[j]=1
        else:
            D[j]+=1
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
Y=2*N
Fact=[0 for i in range(Y+1)]
Finv=[0 for i in range(Y+1)]
Fact[0]=1
Finv[0]=1
for i in range(Y):
    Fact[i+1]=(Fact[i]*(i+1))%P
    Finv[i+1]=inv(Fact[i+1])%P
def C(n,k):
    return (Fact[n]*(Finv[k]*Finv[n-k])%P)%P
ans=1
for p in D:
    e=D[p]
    ans=ans*C(e+N-1,N-1)
    ans=ans%P
print(ans)

### FIXED CODE ###

#http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759
N,M=map(int,input().split())
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
Z=2*10**5
Fact=[0 for i in range(Z+1)]
Finv=[0 for i in range(Z+1)]
Fact[0]=1
Finv[0]=1
for i in range(Z):
    Fact[i+1]=(Fact[i]*(i+1))%P
    Finv[i+1]=inv(Fact[i+1])%P
def C(n,k):
    return (Fact[n]*(Finv[k]*Finv[n-k])%P)%P
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
D=factorize(M)
ans=1
for seq in D:
    k=seq[1]
    ans=ans*C(k+N-1,N-1)
    ans=ans%P
print(ans)
n = input()
xs = input().split(' ')
xs = [int(x) for x in xs]
xs = set(xs)
xs = list(xs)
xs.sort()
a = [x for x in xs if x % 2 == 1]
if len(a) > 0:
    print(0)
else:
    m = 10 ** 9
    for x, y in zip(xs[:-1], xs[1:]):
        q = y - x
        if q < m:
            m = q
    if m > xs[0]:
        m = xs[0]
    count = 0
    while m % 2 == 0:
        count += 1
        m = m / 2
    print(count)

### FIXED CODE ###

xs = input()
count = 0
for x in xs:
    if x == '1':
        count += 1
print(count)
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
    if flg:
        break
print(sum(A))

### FIXED CODE ###

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

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
            if a_ind == N:
                flg = 1
                break
    if flg:
        break
print(sum(A))
if(int(input())<=int(input())):print(10)
else:print(0)

### FIXED CODE ###

n=[int(i) for i in input().split()]
if(n[0]>=n[1]):
  print(10)
else:
  print(0)
N, W = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
DP=[[0]*(W+1) for i in range(N+1)]
for i in range(1, W+1):
    DP[0][i] = float("-inf")
for i in range(1, N+1):
    for j in range(W+1):
        if j-X[i-1][0] >= 0:
            DP[i][j] = max(DP[i-1][j], DP[i-1][j-X[i-1][0]]+X[i-1][1])
        else:
            DP[i][j] = DP[i-1][j]
print(max(DP[N]))
                    
#最後から2行目。
#ありえないのは-INFで選ばれないように


### FIXED CODE ###

N, W = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
DP=[[float("inf")]*(N*10**3+1) for i in range(N+1)]
DP[0][0] = 0
for i in range(1, N+1):
    for j in range(N*10**3+1):
        if j-X[i-1][1] >= 0:
            DP[i][j]=min(DP[i-1][j], DP[i-1][j-X[i-1][1]]+X[i-1][0])
        else:
            DP[i][j] = DP[i-1][j]
ans = 0
for i in range(N+1):
    for j in range(N*10**3+1):
        if DP[i][j] <= W:
            ans = max(ans, j)
print(ans)
# -*- coding: utf-8 -*-

import sys
import math

args = sys.argv

hp = int(args[1])
attack = int(args[2])

if(hp <= attack):
    ans = "1"
else:
    ans = str(math.floor(hp / attack))

print(str(ans))

### FIXED CODE ###

import math

hp , attack = map(int,input().split())

if(hp <= attack):
    ans = "1"
else:
    ans = str(math.ceil(hp / attack))

print(int(ans))
A, B, N = map(int,input().split())

x = N
for x in reversed(range(1,N+1)):
  if x % B != 0:
    print(int(A*x/B)-A*int(x/B))
    exit()


### FIXED CODE ###

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

for i in range(A,B+1):
  if i % K == 0:
    print("OK")
    exit()
    
print("NG")
import math
n,k=map(int,input().split()) 
lst=list()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1, k+1):
    if n-k>i:
        lst.append(combinations_count(n-k+1, i) * combinations_count(k-i+(i-1), i-1))  
    elif n-k==i:
        lst.append(combinations_count(K-1,i-1))
    else:
        lst.append(int(0))

for i in range(k):
    print(lst[i]%(10**9+7))

### FIXED CODE ###

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

mod_num = 10 ** 9 + 7
for i in range(1, k+1):
    if i > n - k + 1:
        print(0)
    else:
        print(comb(n-k+1, i) * comb(k-i+(i-1), i-1) % mod_num)
N = int(input())
x = list(map(int, input().split()))
mn_lst = [0 for i in range(N)]
for i in x:
    cnt = 0
    while i % 2 == 0:
        cnt += 1
        i >>= 1
    mn_lst.append(cnt)
    
print(min(mn_list))

### FIXED CODE ###

N = int(input())
x = list(map(int, input().split()))
mn_lst = []
for i in x:
    cnt = 0
    while i % 2 == 0:
        cnt += 1
        i >>= 1
    mn_lst.append(cnt)
    
print(min(mn_lst))
s = input()
ans = 104206969
for i in range(len(s)-2):
  ans = min(ans, abs(753-int(s[i:i+2])))
print ans


### FIXED CODE ###

s = input()
ans = 104206969
for i in range(len(s)-2):
  ans = min(ans, abs(753-int(s[i:i+3])))
print(ans)
n, k, s = map(int, input().split())
ans = [s] * k
ex = [s//2+1] * (n-k) if s != 1 else 2
ans.extend(ex)

for e in ans:
    print(e, end=' ')
print()

### FIXED CODE ###

n, k, s = map(int, input().split())
ans = [s] * k
if s // 2 + 1 == s:
    ss = s // 2 + 10
else:
    ss = s // 2 + 1
ex = [ss] * (n-k)
ans.extend(ex)

for e in ans:
    print(e, end=' ')
print()
from collections import deque
q=deque()
def MI(): return map(int, input().split())
N,M=MI()
g=[[] for _ in range(M+1)]
for _ in range(M):
  a,b=MI()
  g[a].append(b)
  g[b].append(a)
check=[0]*(N+1)
check[1]=1
ans=[0]*(N+1)
q.append(1)
while len(q)>0:
  v=q.popleft()
  for u in g[v]:
    if check[u]==0:
      check[u]=1
      ans[u]=v
      q.append(u)
print('Yes')
for i in range(2,N+1):
  print(ans[i])

### FIXED CODE ###

from collections import deque
N,M=map(int,input().split())
ab=[[] for i in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  ab[a].append(b)
  ab[b].append(a)
ans=[-1]*(N+1)
que=deque([1])
while que:
  q=que.popleft()
  for i in ab[q]:
    if ans[i]==-1:
      que.append(i)
      ans[i]=q
print('Yes')
for i in range(2,N+1):
  print(ans[i])
a = list(input())
count = 0
for i in a:
  if a[i] == 1: count += 1
print(count)

### FIXED CODE ###

a = list(input())
count = 0
for i in a:
    if i == "1": count += 1
print(count)
def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True  

def resolve():
    A, B = list(map(int, input().split()))
    import sympy
    divs = sympy.divisors(A)
    i = 1
    cnt = 0
    while i < len(divs):
        if B%divs[i]==0 and is_prime(divs[i]):
            cnt += 1
        i += 1
    print(cnt+1)
    

if '__main__' == __name__:
    resolve()


### FIXED CODE ###

def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True  

def divisors(n):
    lower_divs , upper_divs = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divs.append(i)
            if i != n // i:
                upper_divs.append(n//i)
        i += 1
    return lower_divs + upper_divs[::-1]

def resolve():
    A, B = list(map(int, input().split()))
    divs = divisors(A)
    i = 1
    cnt = 0
    while i < len(divs):
        if B%divs[i]==0 and is_prime(divs[i]):
            cnt += 1
        i += 1
    print(cnt+1)
    

if '__main__' == __name__:
    resolve()
N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    s, c = map(int, input().split())
    d = a[s-1]
    if s == 1 and c == 0:
        print("-1")
        break
    if d != 0:
        a[s-1] = min(c, d)
    else:
        a[s-1] = c
if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)
else:
    if a[0] == 0:
        a[1] == 1
        print(*a, sep="") 
    else:
        print(*a, sep="") 

### FIXED CODE ###

N, M = map(int, input().split())
A=[]
for j in range(M):
    s, c = map(int, input().split())
    A.append([s-1, str(c)])
if N == 1:
    b = 0
elif N == 2:
    b= 10
else:
    b = 100
ans=[]
for i in range(b, 1000):
    a = 0
    for j in range(M):
        x=str(i)
        if len(x) < N:
            break 
        if A[j][1] == x[A[j][0]]:
            a += 1
    if a == M:
        ans.append(i)
if ans == []:
    print(-1)
else:
    print(min(ans))
import sys
import numpy as np

def main():
    n, w = map(int, sys.stdin.buffer.readline().split())
    dp = np.zeros(w+1, dtype = int)

    for x in sys.stdin.buffer.readlines():
        w, v = map(int, x.split())
        np.maximum(dp[w:] , dp[:-w] + v, out = dp[w:])
    print(dp.max())

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

def main():
    n, w = map(int, input().split())
    a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
    dp = [[0]*(w+1) for _ in range(n+1)]

    for i in range(n):
        for j in range(w+1):
            if j - a[i][0] >= 0:
                dp[i+1][j] = max(dp[i+1][j] , dp[i][j - a[i][0]] + a[i][1])

            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    print(dp[n][w])

if __name__ == '__main__':
    main()
from collection import deque

D = deque() 
N = int(input())
for i in range(N):
	c, s = input().split()
	if c == "insert":
		d.append(s)
	elif c == "find":
		if (s in d):
			print(Yes)
		else:
			print(No)

### FIXED CODE ###

from collections import deque

D = set()
N = int(input())

for i in range(N):
	c, s = input().split()
	if c == "insert":
		D.add(s)
	elif c == "find":
		if (s in D):
			print("yes")
		else:
			print("no")
n,k = [int(x) for x in input().split()]
s = input()

k -= 1

if s[k] == "A":
  s[k] = "a"
elif s[k] == "B":
  s[k] = "b"
elif s[k] == "C":
  s[k] = "c"

print(s)

### FIXED CODE ###

n,k = [int(x) for x in input().split()]
s = input()
 
k -= 1
s = list(s)

if s[k] == "A":
  s[k] = "a"
elif s[k] == "B":
  s[k] = "b"
elif s[k] == "C":
  s[k] = "c"
 
print("".join(s))
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if L[-1] >=A[-1]:
        x=L.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
    else:
        x=A.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
print(sum(L)+sum(A))

### FIXED CODE ###

n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))
n,k=map(int,input().split())
x=list(map(int,input().split()))

if x[n-1]<0 :
    t=x[-k]
    print(t)
elif x[n-1]==0 :
    t=x[-k+1]
    print(t)

elif x[0]>0:
    t=x[k-1]
    print(t)
elif x[0]==0:
    t=x[k-1]
    print(t)

else:
    for i in range(n-1):
        if x[i]<0 and x[i+1]>=0 :
            i0=i+1
            break
#    print(i0)
    tmin=10**9
    for i in range(i0,k):
        kt=i
        t=x[kt]*2-x[kt-k+1]
#        print("1",kt,kt-k+1,t,x[kt],x[kt-k+1])
        if t<tmin:
            tmin=t
    for i in range(i0-1,i0+1-k-1,-1):
        kt=i
        t=-x[kt]*2+x[kt+k-1]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
        if t<tmin:
            tmin=t
    print(tmin)

### FIXED CODE ###

from bisect import bisect_right
from bisect import bisect_left

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

#n=100000
#k=100000
x=list(map(int,input().split()))

if x[n-1]<0 :
    t=-x[-k]
#    print(1)
    print(t)
elif x[n-1]==0 :
    t=-x[-k+1]
#    print(2)
    print(t)

elif x[0]>0:
    t=x[k-1]
#    print(3)
    print(t)
elif x[0]==0:
    t=x[k-1-1]
#    print(4)
    print(t)

else:
    iz=bisect_left(x,0)
    if x[iz+1]==0:
        k=k-1
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    else:
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    print(tmin)
    
#  299993628 
# 1000000000        
#   99990701
#d-even relation
#ふかさ優先探索の実装
#再起関数の実装を行う
n=int(input())
visitedlist=[-1 for  i in range(n)]
lists=[tuple(map(int,input().split())) for i in range(n-1)]
kilist=[[] for i in range(n)]
for i in lists:
    kilist[i[0]-1].append(i[1:])
    kilist[i[1]-1].append(i[0:3:2])
visitedlist[0]=1
anslist=[0 for i in range(n)]
#開始地点1のところは0を基準としている
#1には初めに訪れる
def search(i):
        flag=False
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag=True
                if j[1]%2==0:
                    anslist[j[0]-1]=anslist[i-1]
                elif j[1]%2!=0:
                    anslist[j[0]-1]=1-anslist[i-1]      
            else:
                pass  
        if flag:    
            for j in kilist[i-1]:
                return search(j[0])
        if not flag:
            pass
            
search(1)
for k in anslist:
    print(k)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n=int(input())
visitedlist=[-1 for  i in range(n)]
kilist=[[] for i in range(n)]
anslist=[0 for i in range(n)]
searchedlist=[-1 for i in range(n)]
for i in range(n-1):
        a,b,c=map(int,input().split())
        kilist[a-1].append((b,c))
        kilist[b-1].append((a,c))
def search(i):
        searchedlist[i-1]=1
        visitedlist[i-1]=1
        flag=0
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag+=1
                anslist[j[0]-1]=anslist[i-1]+j[1]
        else:
            pass

        if flag>0:    
            for k in kilist[i-1]:
                if searchedlist[k[0]-1]==-1:
                    search(k[0])
search(2)
for i in anslist:
    print(i%2)
def main():
    h, w, k = map(int, input().split())
    o = [[0]*w for _ in range(h)]
    s = [list(input()) for i in range(h)]
    n, mn = 0, 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                mn += 1
                n = mn
                o[i][j] = n
            else:
                o[i][j] = n
        n = 0
    for i in range(h):
        for j in range(w-1, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i][j+1]

    for i in range(h):
        print(*o[i])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    h, w, k = map(int, input().split())
    o = [[0]*w for _ in range(h)]
    s = [list(input()) for i in range(h)]
    n, mn = 0, 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                mn += 1
                n = mn
                o[i][j] = n
            else:
                o[i][j] = n
        n = 0
    for i in range(h):
        for j in range(w-2, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i][j+1]
    for j in range(w):
        for i in range(1, h):
            if o[i][j]==0:
                o[i][j] = o[i-1][j]
    for j in range(w):
        for i in range(h-2, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i+1][j]
    for i in range(h):
        print(*o[i])

if __name__ == "__main__":
    main()
import sys

n, m = map(int, input().rstrip().split())
dist = [[500000 for i in range(n)]for j in range(n)]

for i in range(n):
    for j in range(n):
        if (i==j):
            dist[i][j]=0

a = []
b = []
c = []

for i in range(m):
    x, y, z = map(int, input().rstrip().split())
    dist[x-1][y-1] =  min(dist[x-1][y-1], z)
    dist[y-1][x-1] =  min(dist[x-1][y-1], z)
    a.append(x-1)
    b.append(y-1)
    c.append(z)
    
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
print(dist)
result = m

for i in range(m):
    for j in range(m):
        if dist[j][a[i]] + c[i] == dist[j][b[i]]:
            result -= 1
            break

print(result)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000001)

n, m = map(int, input().rstrip().split())
dist = [[500000 for i in range(n)]for j in range(n)]

for i in range(n):
    for j in range(n):
        if (i==j):
            dist[i][j]=0

a = []
b = []
c = []

for i in range(m):
    x, y, z = map(int, input().rstrip().split())
    dist[x-1][y-1] =  min(dist[x-1][y-1], z)
    dist[y-1][x-1] =  min(dist[x-1][y-1], z)
    a.append(x-1)
    b.append(y-1)
    c.append(z)
    
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
#print(dist)
result = m

for i in range(m):
    for j in range(n):
        if dist[j][a[i]] + c[i] == dist[j][b[i]]:
            result -= 1
            break

print(result)
a = int(input())
b = int(input())
c = int(input())
d = int(input())

if abs(a - c) <= d:
    print('Yes')
elif (a < b and b < c) or (a > b and b > c) :
    if abs(a - b) <= d and abs(b - c) <= d:
        print('Yes')
    else:
        print('No')
else:
     print('No')

### FIXED CODE ###

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

if abs(a - c) <= d:
    print('Yes')
elif (a < b and b < c) or (a > b and b > c):
    if abs(a - b) <= d and abs(b - c) <= d:
        print('Yes')
    else:
        print('No')
else:
    print('No')