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

import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    min_ = [[int(1e5)] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        if cost < min_[y][x]:
            min_[y][x] = cost
            ans = max(ans, cost)
            for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if board[ny][nx] == ".":
                        q.append((cost+1, nx, ny))
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

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

    print(np.max(a))

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

import heapq
import sys
input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, d, a = MAP()
xh = [LIST() for i in range(n)]

heapq.heapify(xh)
cnt = 0
while xh:
    c = heapq.heappop(xh)
    cx, ch = c[0], c[1]
    cn = (ch + a - 1) // a
    cnt += cn
    tmp = []
    while xh:
        ne = heapq.heappop(xh)
        nx, nh = ne[0], ne[1]
        if nx <= cx + 2*d:
            nh -= cn * a
            if nh > 0:
                tmp.append([nx, nh])
        else:
            tmp.append([nx, nh])
            break
    for i in range(len(tmp)):
        heapq.heappush(xh, tmp[i])
    
print(cnt)

### FIXED CODE ###

from collections import deque
import sys

input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, d, a = MAP()
xh = [LIST() for i in range(n)]

xh = sorted(xh, key=lambda x:(x[0]))
q = deque()
ca = 0
cnt = 0
for i in range(n):
    cx, ch = xh[i][0], xh[i][1]
    
    while q and q[0][0] < cx:
        qx, qa = q.popleft()
        ca -= qa
    
    if ch - ca <= 0:
        continue
    
    cn = (ch - ca + a - 1) // a
    cnt += cn
    ca += cn * a
    q.append([cx+2*d, cn*a])
    
print(cnt)
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

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

if m%2==1:
  print(-1)
  exit()

graph = defaultdict(set)
grapht = defaultdict(set)
for i in range(m):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  graph[a].add(b)
  graph[b].add(a)
  grapht[a].add(b)
  grapht[b].add(a)

graph2 = defaultdict(set)
visited = [0 for i in range(n)]
num = [1 for i in range(n)]

def dfs(x):
  visited[x] = 1

  for nx in graph[x]:
    if not visited[nx]:
      dfs(nx)

  t = set()
  if num[x]==1 and len(grapht[x])%2==0:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
  elif num[x]==-1 and len(grapht[x])%2==0:
    for j, e in enumerate(grapht[x]):
      if j==len(grapht[x])-1:
        graph2[e].add(x)
        num[e] *= -1
      else:
        graph2[x].add(e)
      t.add(e)
  elif num[x]==1 and len(grapht[x])%2==1:
    for j, e in enumerate(grapht[x]):
      if j==len(grapht[x])-1:
        graph2[e].add(x)
        num[e] *= -1
      else:
        graph2[x].add(e)
      t.add(e)
  elif num[x]==-1 and len(grapht[x])%2==1:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
  for e in t:
    grapht[x].remove(e)
    grapht[e].remove(x)

dfs(0)

for i in range(n):
  for e in graph2[i]:
    print(i+1, e+1)


### FIXED CODE ###

from collections import defaultdict
import sys

def dfs(visited, graph, grapht, graph2, num, x):
  visited[x] = 1

  for nx in graph[x]:
    if not visited[nx]:
      dfs(visited, graph, grapht, graph2, num, nx)

  t = set()
  if num[x]==1 and len(grapht[x])%2==0:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
  elif num[x]==-1 and len(grapht[x]) and len(grapht[x])%2==0:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
    tt = grapht[x].pop()
    graph2[tt].add(x)
    graph2[x].remove(tt)
    num[tt] *= -1
  elif num[x]==1 and len(grapht[x])%2==1:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
    tt = grapht[x].pop()
    graph2[tt].add(x)
    graph2[x].remove(tt)
    num[tt] *= -1
  else:
    for e in grapht[x]:
      graph2[x].add(e)
      t.add(e)
  for e in t:
    if e in grapht[x]:
      grapht[x].remove(e)
    if x in grapht[e]:
      grapht[e].remove(x)

if __name__ == "__main__":
  sys.setrecursionlimit(1000000)
  input = sys.stdin.readline
  n, m = map(int, input().split())

  if m%2==1:
    print(-1)
    exit()

  graph = defaultdict(set)
  grapht = defaultdict(set)
  for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].add(b)
    graph[b].add(a)
    grapht[a].add(b)
    grapht[b].add(a)

  graph2 = defaultdict(set)
  visited = [0]*n
  num = [1]*n

  dfs(visited, graph, grapht, graph2, num, 0)

  for i in range(n):
    if len(graph2[i])%2==1:
      print(-1)
      exit()

  for i in range(n):
    for e in graph2[i]:
      print(i+1, e+1)
### BUGGY CODE ###

class UnionFind:
    #n個の要素を初期化
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    #木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    #xとyの属する集合を併合
    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.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    #xとyが同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)


N, K, L = map(int, input().split())
roads = [list(map(int, input().split())) for i in range(K)]
trains = [list(map(int, input().split())) for i in range(L)]

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for road in roads:
    x, y = road
    uf_road.unite(x-1, y-1)

for train in trains:
    x, y = train
    uf_train.unite(x-1, y-1)

ans = []
for i in range(N):
    res = 0
    for j in range(N):
        if uf_road.same(i, j) and uf_train.same(i, j):
            res += 1
    ans.append(res)

print(*ans)

### FIXED CODE ###

from collections import Counter

class UnionFind:
    #n個の要素を初期化
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    #木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    #xとyの属する集合を併合
    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.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    #xとyが同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    #要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]


N, K, L = map(int, input().split())
roads = [list(map(int, input().split())) for i in range(K)]
trains = [list(map(int, input().split())) for i in range(L)]

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for road in roads:
    x, y = road
    uf_road.unite(x-1, y-1)

for train in trains:
    x, y = train
    uf_train.unite(x-1, y-1)

pairs = []
for i in range(N):
    pairs.append((uf_road.find(i), uf_train.find(i)))

cnt = Counter(pairs)

ans = [cnt[pair] for pair in pairs]
print(*ans)
### BUGGY CODE ###

n,k=map(int,input().split())
H=list(map(int,input().split()))
add=[0]*(2*n)
H=H+add
#配るDPでやってみる
#dp[i]をi番目の足場まで行くときの最小コストとする。
dp=[float('inf')]*(2*n)
dp[0]=0
dp[1]=0
for i in range(1,n+1):
    for a in range(1,min(k+1,n-i+1)):
            dp[i+a]=min(dp[i+a], dp[i]+abs(H[i+a-1]-H[i-1]))
print(dp[n])


### FIXED CODE ###

n,k=map(int,input().split())
H=list(map(int,input().split()))
#配るDPでやってみる
#dp[i]をi番目の足場まで行くときの最小コストとする。
dp=[float('inf')]*(2*n)
dp[0]=0
dp[1]=0
for i in range(1,n+1):
    for a in range(1,min(k+1,n-i+1)):
            dp[i+a]=min(dp[i+a], dp[i]+abs(H[i+a-1]-H[i-1]))
print(dp[n])
### BUGGY CODE ###

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

ans = 0

for x in range(n):
  for y in range(n):
    if not x < y:
      continue
    if s[x] == s[y]:
      continue
    for z in range(n):
      if not y < z:
        continue

      if not x < y < z:
        # print("SKIP: ", x, y, z)
        continue

      if y-x == z-y:
        # print("SKIP: ", x, y, z)
        continue

      if not ((s[x] != s[y]) and (s[x] != s[z]) and (s[y] != s[z])):
        # print("SKIP: ", x, y, z)
        continue

      ans += 1
      # print(x, y, z)
      # print(s[x], s[y], s[z])

print(ans)


### FIXED CODE ###

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

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
  for j in range(n):
    if not i < j:
      continue
    k = j + (j-i)
    if k < n and "".join(sorted([s[i], s[j], s[k]])) == "BGR":
      ans -= 1

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

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

A = []
point = []
for i in range(N):
    point.append(K)

for i in range(Q):
    A.append(int(input()))


for a in A:
    for i in range(N):
        if i == a-1:
            pass
        else:
            point[i] -= 1

# result
for i in range(N):
    if point[i] > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

A = []
point = []
border = 0
for i in range(N):
    point.append(K)

for i in range(Q):
    A.append(int(input()))


for a in A:
    point[a-1] += 1
    border += 1

# result
for i in range(N):
    if point[i] > border:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N = int(input())
card = list(map(int,input().split(' ')))

sum_card = sum(card)
dif_list = []
min_value = 1000000000
for i in range(1,N,1):
  sunuke = sum(card[:i])
  if abs(sum_card/2 - sunuke) < min_value:
    min_value = abs(sum_card/2 - sunuke)
  
print(int(2*min_value))

### FIXED CODE ###

N = int(input())
card = list(map(int,input().split(' ')))

sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))
### BUGGY CODE ###

n, m = map(int, input().split(' '))
submits = [input().split(' ') for i in range(m)]

WAs = [0] * n
ACs = []
penalty = 0
for submit in submits:
    p, s = submit
    p = int(p) - 1
    if p in ACs:
        continue
    if s == 'AC':
        penalty += WAs[p]
        ACs.append(p)
    else:
        WAs[p] += 1

print(len(ACs), penalty)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split(' '))

WAs = [0] * n
correct = 0
penalty = 0
for i in range(m):
    p, s = input().strip().split(' ')
    p = int(p) - 1
    if WAs[p] == -1:
        continue
    if s == 'AC':
        penalty += WAs[p]
        correct += 1
        WAs[p] = -1
    else:
        WAs[p] += 1

print(correct, penalty)
### BUGGY CODE ###

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

ans = sum(A)
for i in range(N):
  if A[i] < 0:
    if i != N-1:
      A[i] = A[i] * -1
      A[i+1] = A[i+1] * -1
  ans = max(ans, sum(A))

print(ans)


### FIXED CODE ###

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

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

if 0 in A:
  ans = sum(A)
else:
  if count%2 == 0:
    ans = sum(A)
  else:
    ans = sum(A) - 2*min(A)

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

from math import gcd

def get_loop(a, m):
  count = 1
  while a ** count % m != 1:
    count += 1
  return count

while True:
  a1, m1, a2, m2, a3, m3 = map(int, input().split())
  if not a1:
    break
  loop_a = get_loop(a1, m1)
  loop_b = get_loop(a2, m2)
  loop_c = get_loop(a3, m3)
  loop_ab = loop_a * loop_b // gcd(loop_a, loop_b)
  loop_abc = loop_ab * loop_c // gcd(loop_ab, loop_c)
  print(loop_abc)


### FIXED CODE ###

from math import gcd

def get_loop(a, m):
  count = 1
  acc = a
  while acc != 1:
    count += 1
    acc *= a
    acc %= m
  return count

while True:
  a1, m1, a2, m2, a3, m3 = map(int, input().split())
  if not a1:
    break
  loop_a = get_loop(a1, m1)
  loop_b = get_loop(a2, m2)
  loop_c = get_loop(a3, m3)
  loop_ab = loop_a * loop_b // gcd(loop_a, loop_b)
  loop_abc = loop_ab * loop_c // gcd(loop_ab, loop_c)
  print(loop_abc)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Limit = dict()
    for i in range(N):
        A, B = map(int, input().split())
        New = not B in Limit.keys()
        Limit[B] = Limit.get(B,0) + A
        if Limit[B] > B:
            return 'No'
        else:
            tk = 0
            for k in Limit.keys():
                if New and k < B:
                    tk = max(tk, k)

                if k > B:
                    Limit[k] += A
                    if Limit[k] > k:
                        return 'No'
            Limit[B] += Limit.get(tk,0)
            if Limit[B] > B:
                return 'No'

    return 'Yes'

if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

# -*- coding: utf-8 -*-
from heapq import heappush, heappop

def solve():
    N = int(input())
    hq = []
    for i in range(N):
        A, B = map(int, input().split())
        heappush(hq, (B,A))

    time = 0
    cost = 0
    while hq:
        l, c = heappop(hq)
        if time == l:
            cost += c
        else:
            time = l
            cost += c
        if cost > time:
            return 'No'
    return 'Yes'
if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

class Node:

    def __init__(self, i):
        self.index = i
        self.parent = self

    def root(self):
        if self.parent == self:
            return self.parent
        else:
            self.parent = self.parent.root()
            return self.parent

    def unite(self, other):
        self.root().parent = other.root()

    def is_unite(self, other):
        return self.root() == other.root()


def solve(N, K, L, PQs, RSs):
    road_cities = [Node(i) for i in range(N + 1)]
    train_cities = [Node(i) for i in range(N + 1)]

    for p, q in PQs:
        road_cities[p].unite(road_cities[q])

    # print("road")
    # for c in road_cities[1:]:
    #     print(c.index, "-> ", c.root().index)

    for r, s in RSs:
        train_cities[r].unite(train_cities[s])

    # print("train")
    # for c in train_cities[1:]:
    #     print(c.index, "-> ", c.root().index)
    road_roots = {i: [] for i in range(1, N + 1)}
    train_roots = {i: [] for i in range(1, N + 1)}
    for i in range(1, N + 1):
        road_roots[road_cities[i].root().index].append(i)
        train_roots[train_cities[i].root().index].append(i)

    counts = {i: 0 for i in range(1, N + 1)}
    for n1 in range(1, N + 1):
        for n2 in road_roots[road_cities[n1].root().index]:
            if n1 > n2:
                continue
            if train_cities[n1].is_unite(train_cities[n2]):
                counts[n1] += 1
                if n1 != n2:
                    counts[n2] += 1

    return " ".join([str(c) for i, c in counts.items() if i > 0])


if __name__ == "__main__":
    N, K, L = map(int, input().split(" "))
    PQs = []
    RSs = []
    for _ in range(K):
        PQs.append(tuple(map(int, input().split(" "))))
    for _ in range(L):
        RSs.append(tuple(map(int, input().split(" "))))
    print(solve(N, K, L, PQs, RSs))


### FIXED CODE ###

from collections import Counter


class UnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n + 1)]

    def root(self, i):
        if self.parents[i] == i:
            return i
        else:
            self.parents[i] = self.root(self.parents[i])
            return self.parents[i]

    def unite(self, i, j):
        self.parents[self.root(self.parents[i])] = self.root(j)

    def is_unite(self, i, j):
        return self.root(i) == self.root(j)


def solve(N, K, L, PQs, RSs):
    road_cities = UnionFind(N)
    train_cities = UnionFind(N)

    for p, q in PQs:
        road_cities.unite(p, q)
    for r, s in RSs:
        train_cities.unite(r, s)

    counts = Counter([
        (road_cities.root(i), train_cities.root(i))
        for i in range(1, N + 1)
    ])

    ans = [
        counts[(road_cities.root(i), train_cities.root(i))]
        for i in range(1, N + 1)
    ]

    return " ".join([str(c) for c in ans])


if __name__ == "__main__":
    N, K, L = map(int, input().split(" "))
    PQs = []
    RSs = []
    for _ in range(K):
        PQs.append(tuple(map(int, input().split(" "))))
    for _ in range(L):
        RSs.append(tuple(map(int, input().split(" "))))
    print(solve(N, K, L, PQs, RSs))
### BUGGY CODE ###

s = input()
n = int(input())
query_li = [input().split() for i in range(n)]

for query in query_li:
    if int(query[0]) == 1:
        s = s[::-1]
    else:
        if int(query[1]) == 1:
            s = query[2] + s
        else:
            s = s + query[2]

print(s)

### FIXED CODE ###

from collections import deque

s = deque(input().split())
n = int(input())
query_li = (input().split() for i in range(n))

flag = 1

for query in query_li:
    if int(query[0]) == 1:
        flag = flag * -1
    else:
        if int(query[1]) == 1:
            if flag == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if flag == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])

s = ''.join(s)
if flag == -1:
    s = s[::-1]

print(s)
### BUGGY CODE ###

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

# print(a)
# li = []
for i in range(1, n + 1):
    # li.append(a.index(i) + 1)

    print(a.index(i) + 1, end=" ")
    

### FIXED CODE ###

import numpy as np

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

npa = np.array(a)
print(*(np.argsort(npa) + 1))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
n=int(input())
h=list(map(int,input().split()))
def cst(n):
    if n==1:
        return 0
    elif n==2:
        return abs(h[1]-h[0])   
    else:
        return min(cst(n-1)+abs(h[n-1]-h[n-2]),cst(n-2)+abs(h[n-1]-h[n-3]))

A=cst(n)
print(A)

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
D=[10**0 for i in range(n)]

for i in range(n):
    if i==0:
        D[i]=0
    elif i==1:
        D[i]=abs(h[1]-h[0])  
    else:
        D[i]=min(D[i-1]+abs(h[i]-h[i-1]),D[i-2]+abs(h[i]-h[i-2]))
print(D[n-1])
### BUGGY CODE ###

N = int(input())
S = input()

ans, tmp = 0, 0
for i in range(N):
    for j in range(N - i):
        if S[j] == S[i + j]:
            tmp += 1
        else:
            ans, tmp = max(ans, min(tmp, i)), 0
    ans, tmp = max(ans, min(tmp, i)), 0

print(ans)


### FIXED CODE ###

N = int(input())
S = input()

ans, tmp = 0, 0
for i in range(N):
    for j in range(N - i):
        if S[j] == S[i + j]:
            tmp += 1
        else:
            ans, tmp = max(ans, min(tmp, i)), 0
    ans, tmp = max(ans, min(tmp, i)), 0

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

import sys
sys.setrecursionlimit(2000000)
n = int(input())
a=[[]for i in range(n)]
for i in range(n-1):
  x = int(input())
  x-=1
  a[x].append(i+1)
  
dp=[0]*n
huka = [0]*n
def dfs(x,y):
  huka[x]=y
  for i in a[x]:
    dfs(i,y+1)
dfs(0,0)
ya = []
for i in range(n):
  ya.append([huka[i],i])
ya.sort(key=lambda x:-x[0])
for i in range(n):
  bb=ya[i][1]
  tmp=[]
  for j in a[bb]:
    tmp.append(dp[j])
  tmp.sort(key=lambda x:-x)
  dai =0
  for i in range(1,len(tmp)+1):
    tmp[i-1]+=i
    dai=max(dai,tmp[i-1])
  dp[bb]=dai
print(dp[0])

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
n = int(input())
a=[[]for i in range(n)]
for i in range(n-1):
  x = int(input())
  x-=1
  a[x].append(i+1)
  
dp=[0]*n
ya = [[0,i] for i in range(n)]
def dfs(x,y):
  ya[x][0]=y
  for i in a[x]:
    dfs(i,y+1)
dfs(0,0)
ya.sort(key=lambda x:-x[0])
tmp=[]
for i in range(n):
  bb=ya[i][1]
  for j in a[bb]:
    tmp.append(dp[j])
  tmp.sort(key=lambda x:-x)
  dai =0
  for j in range(len(tmp),0,-1):
    cc=tmp.pop()
    cc+=j
    dai=max(dai,cc)
  dp[bb]=dai
print(dp[0])
### BUGGY CODE ###

import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics

sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

data1 = getInputListInt()
n = data1[0]
q = data1[1]

data2 = getSomeInputListInt(n-1)

data3 = getSomeInputListInt(q)

ans = np.zeros(n)

for i in range(len(data3)):
    ans[data3[i][0]-1] += data3[i][1]

treeList = [[] for _ in range(n)]

for i in range(len(data2)):
    treeList[data2[i][0]-1].append(data2[i][1]-1)
    treeList[data2[i][1]-1].append(data2[i][0]-1)

def treeTrace(crnt, prnt):
    for i in range(len(treeList[crnt])):
        if prnt == treeList[crnt][i]:
            continue
        ans[treeList[crnt][i]] += ans[crnt]

        treeTrace(treeList[crnt][i], crnt)

treeTrace(0, -1)

for s in ans:
    print(int(s), end =" ")


### FIXED CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)
### BUGGY CODE ###

l,r=map(int,input().split())
i=1
temp=0
while r>2019*i:
  if l<=2019*i:
    temp=1
    break
  i=i+1
i=1
temp1=0
while r>3*i:
  if l<=3*i:
    temp1=1
    break
  i=i+1
i=1
temp2=0
while r>673*i:
  if l<=673*i:
    temp2=1
    break
  i=i+1

if temp==1:
  print(0)
elif temp1==1 and temp2==1:
  print(0)
else:
  print(l%2019*(l+1)%2019)

### FIXED CODE ###

l,r=map(int,input().split())
i=1
temp=0
while r>2019*i:
  if l<=2019*i:
    temp=1
    break
  i=i+1

count=2019
r=r%2019
l=l%2019
for i in range(l,r+1):
  for j in range(i+1,r+1):
    temp1=(i*j)%2019
    count=min(count,temp1)

if temp==1:
  print(0)
else:
  print(count)