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

import bisect
N = int(input())
A = [int(input())for _ in range(N)]
li = [-1]
for i in A[::-1]:
    if(max(li)<i):
        li.append(i)
    else:
        ind = bisect.bisect_right(li,i)
        if(ind>=len(li)):
            li.append(i)
        elif(li[ind]>i):
            li.pop(ind)
            li.insert(ind,i)
        else:
            li.pop(ind+1)
            li.insert(ind+1)
print(len(li)-1)

### FIXED CODE ###

import bisect
N = int(input())
A = [int(input())for _ in range(N)]
li = [-1]
for i in A[::-1]:
    if(li[-1]<i):
        li.append(i)
    else:
        ind = bisect.bisect_right(li,i)
        if(ind>=len(li)):
            li.append(i)
        elif(li[ind]>i):
            li.pop(ind)
            li.insert(ind,i)
        else:
            li.pop(ind+1)
            li.insert(ind+1)
print(len(li)-1)
### BUGGY CODE ###

s = input()
q = int(input())
flg = False

for i in range(q):
    x = input()
    if int(len(x)) == 1:
        a = int(x)
        s = s[::-1] 
        # print(s)
    else:
        a, b, c = map(str, x.split()) 
        if int(b) == 1:
            s = c + s
            # print(s)
        else:
            s = s + c
            # print(s)

print(s)

### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

t = deque(s)
flg = False
for _ in range(q):
    query = input()
    if query[0] == "1":
        flg = not flg
    elif query[0] == "2":
        _, f, c = query.split()
        if f == "1":
            if flg:
                t.append(c)
            else:
                t.appendleft(c)
        elif f == "2":
            if flg:
                t.appendleft(c)
            else:
                t.append(c)
result = "".join(t)
if flg:
    result = result[::-1]
print(result)
### BUGGY CODE ###

N,M = map(int,input().split())
requests = []
for _ in range(M):
        a,b = map(int,input().split())
        requests.append([a,b])

ans = 0
while requests:
        ans += 1
        bridge = min(requests, key=lambda x:x[1])[1]
        requests = sorted(requests, key=lambda x:(x[0]))
        while requests:
                if requests[0][0] < bridge:
                        del requests[0]
                else:
                        break

print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
requests = []
for _ in range(M):
        a,b = map(int,input().split())
        requests.append([a,b])

ans = 1
requests = sorted(requests, key=lambda x:x[1])
b = requests[0][1]
for i in range(M):
        if requests[i][0] < b:
                continue
        else:
                ans += 1
                b = requests[i][1]

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

#!/usr/bin/env python3
#ABC147 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [LI() for _ in range(h)]
b = [LI() for _ in range(h)]

dp = [[defaultdict(tuple) for _ in range(w)] for _ in range(h)]
dp[0][0][(a[0][0],b[0][0])] = 1
dp[0][0][(b[0][0],a[0][0])] = 1
for i in range(h):
    for j in range(w):
        for (k,l),m in dp[i][j].items():
            if m == 0:
                continue
            if i+1 < h:
                dp[i+1][j][(k+a[i+1][j],l+b[i+1][j])] = 1
                dp[i+1][j][(k+b[i+1][j],l+a[i+1][j])] = 1
            if j+1 < w:
                dp[i][j+1][(k+a[i][j+1],l+b[i][j+1])] = 1
                dp[i][j+1][(k+b[i][j+1],l+a[i][j+1])] = 1
ans = inf
for (i,j),_ in dp[-1][-1].items():
    ans = min(ans,abs(i-j))
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC147 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [LI() for _ in range(h)]
b = [LI() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
lst = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        lst[i][j] = abs(a[i][j] - b[i][j])

dp[0][0] |= 1 << (6400+lst[0][0])
dp[0][0] |= 1 << (6400-lst[0][0])
for i in range(h):
    for j in range(w):
        t = dp[i][j]
        if i+1 < h:
            dp[i+1][j] |= t << lst[i+1][j]
            dp[i+1][j] |= t >> lst[i+1][j]
        if j+1 < w:
            dp[i][j+1] |= t << lst[i][j+1]
            dp[i][j+1] |= t >> lst[i][j+1]

x = dp[-1][-1]
for i in range(6401)[::-1]:
    if (x >> i) & 1:
        print(6400 - i)
        break
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
if N > 10000:
    A = A[5050:] + A[:5050]
    B = B[5050:] + B[:5050]
ans = -1

D = [0] * N
L = [i-1 for i in range(N)]
R = [i+1 for i in range(N)]

def calc():
    i = 0
    c = 0
    ans = 0
    while c < N:
        while i < N:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = R[i]
        i = N-1
        while i >= 0:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = L[i]
    return ans

print(calc())


### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
if N > 10000:
    A = A[5050:] + A[:5050]
    B = B[5050:] + B[:5050]
ans = -1

D = [0] * N
L = [i-1 for i in range(N)]
R = [i+1 for i in range(N)]

def calc():
    i = 0
    c = 0
    ans = 0
    while c < N:
        while i < N:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = R[i]
        i = N-1
        while i >= 0:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = L[i]
    return ans

print(calc())
### BUGGY CODE ###

n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000000000
i=1
while i**2<n:
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
print(minn)

### FIXED CODE ###

n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000000000
for i in range(1,int(math.sqrt(n))+2):
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
print(minn)
### BUGGY CODE ###

from collections import deque
from typing import List


def main():
    h, w = map(int, input().split())
    g = [input() for _ in range(h)]
    print(mm(h, w, g))


def mm(h: int, w: int, g: List[List[str]]) -> int:
    ret = 0
    for i in range(h):
        for j in range(w):
            if (g[i][j] == '#'):
                continue
            cnt = 0
            q = deque([(i, j, cnt)])
            v = set()
            while q:
                ii, jj, cnt = q.popleft()
                v.add((ii, jj))
                ret = max(ret, cnt)
                # ↓
                if ii < h - 1 and g[ii + 1][jj] == '.' and (ii + 1, jj) not in v:
                    q.append((ii + 1, jj, cnt + 1))
                # →
                if jj < w - 1 and g[ii][jj + 1] == '.' and (ii, jj + 1) not in v:
                    q.append((ii, jj + 1, cnt + 1))
                # ↑
                if ii > 0 and g[ii - 1][jj] == '.' and (ii - 1, jj) not in v:
                    q.append((ii - 1, jj, cnt + 1))
                # ←
                if jj > 0 and g[ii][jj - 1] == '.' and (ii, jj - 1) not in v:
                    q.append((ii, jj - 1, cnt + 1))
    return ret


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque
from typing import List


def main():
    h, w = map(int, input().split())
    g = []
    for _ in range(h):
        r = list(input())
        g.append(r)
    print(mm(h, w, g))


def mm(h: int, w: int, g: List[List[str]]) -> int:
    ret = 0
    for i in range(h):
        for j in range(w):
            if (g[i][j] == '#'):
                continue
            v = set()
            q = deque([(i, j, 0)])
            v.add((i, j))
            while q:
                ii, jj, cnt = q.popleft()
                ret = max(ret, cnt)
                # ↓
                if ii < h - 1 and g[ii + 1][jj] == '.' and (ii + 1, jj) not in v:
                    q.append((ii + 1, jj, cnt + 1))
                    v.add((ii + 1, jj))
                # →
                if jj < w - 1 and g[ii][jj + 1] == '.' and (ii, jj + 1) not in v:
                    q.append((ii, jj + 1, cnt + 1))
                    v.add((ii, jj + 1))
                # ↑
                if ii > 0 and g[ii - 1][jj] == '.' and (ii - 1, jj) not in v:
                    q.append((ii - 1, jj, cnt + 1))
                    v.add((ii - 1, jj))
                # ←
                if jj > 0 and g[ii][jj - 1] == '.' and (ii, jj - 1) not in v:
                    q.append((ii, jj - 1, cnt + 1))
                    v.add((ii, jj - 1))
    return ret


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

import bisect

N = int(input())
S = sorted([int(x) for x in input().split()])

Slimes = [[S.pop(-1)]]

flag = True
for i in range(1, N + 1):
    Slimes.append([])
    for j in range(i):
        for k in Slimes[j]:
            idx = bisect.bisect_left(S, k)
            if idx == 0:
                flag = False
                break
            Slimes[i].append(S.pop(idx-1))
        if not flag:
            break
    if not flag:
        break

print('Yes' if flag else 'No')

### FIXED CODE ###

N = int(input())
N2 = 1 << N

S = sorted([int(x) for x in input().split()])

s = []
s.append(S[-1])
S[-1] = -1

flag = True
for i in range(N):
    p = sorted([x for x in s])

    Si = N2 - 1
    while len(p) > 0 and Si >= 0:
        if S[Si] == -1:
            Si -= 1
            continue

        if S[Si] < p[-1]:
            s.append(S[Si])
            del p[-1]
            S[Si] = -1
        
        Si -= 1
    
    if len(p) > 0:
        flag = False

print('Yes' if flag else 'No')
### BUGGY CODE ###

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = sorted([x+y for x in a for y in b])[:-k-1:-1]
abc = sorted([x+y for x in ab[:k] for y in c])[:-k-1:-1]
print(*abc, sep='\n')

### FIXED CODE ###

x, y, z, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

N = int(input())
s = input()
dp = [[0 for _ in range(N+1)]for _ in range(N+1)]
now = 0
ans = 0

for i in range(N-1,-1,-1):
    for j in range(N-1,-1,-1):
        if s[i] != s[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1]+1
            if i >= j:
              continue
            now = min(dp[i][j],j-i)
            ans = max(ans,now)
print(ans)

### FIXED CODE ###

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

import numpy as np

N = int(input())
S = np.array([ord(x) for x in input().rstrip()],dtype=np.int64)

MOD = 10**9 + 7
base = 1234

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

x = np.full(N,base,np.int64); x[0] = 1
power = cumprod(x)
x = np.full(N,pow(base,MOD-2,MOD),np.int64); x[0] = 1
power_inv = cumprod(x)

H = S * power % MOD
Hcum = H.cumsum() % MOD

def test(n):
    x = (Hcum[n-1:N] - Hcum[:N-n+1] + H[:N-n+1]) % MOD
    x *= power_inv[:N-n+1]
    x %= MOD
    ind = np.lexsort((np.arange(N-n+1),x))
    x = x[ind]
    is_left_end = np.zeros(N-n+1,np.bool)
    is_left_end[1:] = (x[1:] != x[:-1])
    is_left_end[0] = 1
    is_right_end = np.zeros(N-n+1,np.bool)
    is_right_end[:-1] = (x[:-1] != x[1:])
    is_right_end[-1] = 1
    gap = ind[is_right_end] - ind[is_left_end]
    return gap.max() >= n

left = 0 
right = N+1 
while left + 1 < right:
    mid = (left + right)//2
    if test(mid):
        left = mid
    else:
        right = mid

answer = left
print(answer)
### BUGGY CODE ###

n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            flag=False
            for i in range(0,n-2):
                if p==s[i]:
                    for j in range(i+1,n-1):
                        if q==s[j]:
                            for k in range(j+1,n):
                                if r==s[k]: 
                                    count+=1
                                    flag=True
                                    break
                        if flag: break
                if flag: break
print(count)

### FIXED CODE ###

N = int(input())
S = [int(c) for c in input()]

count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)
### BUGGY CODE ###

n, m, k = map(int, input().split())
MOD = 998244353


def power(n, k, mod):
    if k == 0:
        return 1
    elif k % 2 == 1:
        return (n * power(n, k - 1, mod)) % mod
    else:
        return power((n ** 2) % mod, k // 2, mod)


lp = [1]  # (m - 1) ** i
p = 1
for i in range(n - 1):
    p = (p * (m - 1)) % MOD
    lp.append(p)


lf = [1]  # i!
f = 1
for i in range(n - 1):
    f = (f * (i + 1)) % MOD
    lf.append(f)

fn = lf[-1]


# lc = []  # n - 1 C i
answer = 0
for i in range(k + 1):
    d = (lf[i] * lf[n - 1 - i]) % MOD
    dinv = power(d, MOD - 2, MOD)
    c = (fn * dinv) % MOD
    # lc.append(c)
    n_pattern = (c * m * lp[n - 1 - i]) % MOD

    answer = (answer + n_pattern) % MOD


# def n_pattern(n_pair):
#     return (lc[n_pair] * m * power(m - 1, n - 1 - n_pair, MOD)) % MOD


# answer = 0
# for i in range(k + 1):
#     answer = (answer + n_pattern(i)) % MOD


print(answer)






### FIXED CODE ###

n, m, k = map(int, input().split())
MOD = 998244353


class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod

        self.f = self._get_f()
        self.fi = self._get_fi()

    def __call__(self, k):
        if not 0 <= k <= self.n:
            return 0
        else:
            num = self.f[self.n]
            deninv = (self.fi[k] * self.fi[self.n - k]) % self.mod
            return (num * deninv) % self.mod

    def _get_f(self):
        f = 1
        lf = [1]

        for i in range(1, self.n + 1):
            f = (f * i) % self.mod
            lf.append(f)

        return lf

    def _get_fi(self):
        ii = 1
        lii = [0, 1]  # [i^-1 modulo mod for i in 0, ..., n]
        fi = 1
        lfi = [1, 1]

        for i in range(2, self.n + 1):
            ii = (-lii[self.mod % i] * (self.mod // i)) % self.mod
            lii.append(ii)

            fi = (fi * ii) % self.mod
            lfi.append(fi)

        return lfi


c = Combination(n - 1, MOD)


def n_pattern(i):
    result = m
    result *= c(i)
    result %= MOD
    result *= pow(m - 1, n - i - 1, MOD)
    result %= MOD
    return result


answer = sum(n_pattern(i) for i in range(k + 1)) % MOD
print(answer)
### BUGGY CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))+[float("inf") for i in range(k)]
dp=[0]+[float("inf") for i in range(n+k)]
for i in range(n-1):
    for j in range(k):
        dp[j+i+1]=min(dp[j+i+1],dp[i]+abs(h[j+i+1]-h[i]))
print(dp[n-1])

### FIXED CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp=[0]+[float("inf") for i in range(n+k)]
for i in range(n-1):
    for j in range(k):
        if j+i+1>n-1:break
        dp[j+i+1]=min(dp[j+i+1],dp[i]+abs(h[j+i+1]-h[i]))
print(dp[n-1])
### BUGGY CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
ans=sum(a)
for i in range(n//2):
  a[i*2]*=-1
  a[i*2+1]*=-1
  ans=max(ans,sum(a))
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)


if ind==0 :
  print(sum(a))
  
elif ind==n:
  if ind%2==1:
    print(-sum(a)+2*a[-1])
  else:
    print(abs(sum(a)))

elif ind%2==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

def main():
    mod = 998244353
    N, K = map(int, input().split())
    L = [0] * K
    R = [0] * K
    for i in range(K):
        L[i], R[i] = map(int, input().split())

    S = set()
    for i in range(K):
        for j in range(L[i], R[i] + 1):
            S.add(j)

    dp = [0] * N
    dp[0] = 1
    for i in range(1, N):
        for s in S:
            if i - s >= 0:
                dp[i] += dp[i - s]
        dp[i] %= mod
    print(dp[N - 1] % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)


def main():
    MOD = 998244353
    N, K = map(int, input().split())
    L = [0] * K
    R = [0] * K
    for i in range(K):
        L[i], R[i] = map(int, input().split())

    dp = [0] * (N + 1)
    dpsum = [0] * (N + 1)
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2, N + 1):
        for j in range(K):
            li = i - R[j]
            li = max(li, 1)
            ri = i - L[j]
            if ri < 0:
                continue
            dp[i] += (dpsum[ri] - dpsum[li - 1]) % MOD
        dpsum[i] += (dpsum[i - 1] + dp[i]) % MOD
    print(dp[N] % MOD)


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

from itertools import combinations

N = int(input())
Sn = [input() for _ in range(N)]

Ln = []
for i in range(N):
    if Sn[i][0] not in {"M", "A", "R", "C", "H"}:
        continue
    Ln.append(Sn[i])


ans = 0
for a, b, c in combinations(Ln, 3):
    if len({a[0], b[0], c[0]}) != 3:
        continue
    ans += 1

print(ans)

### FIXED CODE ###

from itertools import combinations

N = int(input())
Sn = [input() for _ in range(N)]

march = ["M", "A", "R", "C", "H"]
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
cnt = 0
for i in range(N):
    if Sn[i][0] not in march:
        continue
    d[Sn[i][0]] += 1
    cnt += 1

ans = 0
for a, b, c in combinations(march, 3):
    ans += d[a] * d[b] * d[c]

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

a,b,k=map(int,input().split())
l=[i for i in range(a,b+1)]
#print(l)
s=[]
for i in range(len(l)):
    if i<=k-1 or len(l)-k<=i:
        print(l[i])

### FIXED CODE ###

a,b,k=map(int,input().split())
c=[i for i in range(a,min(a+k,b+1))]
d=[i for i in range(max(a,b-k+1),b+1)]
e=c+d
e=list(set(e))
e.sort()
for i in range(len(e)):
    print(e[i])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
AB = [[x for x in map(int,input().split())] for _ in range(N-1)]
PX = [[x for x in map(int,input().split())] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

cnt = [0]*N
for p,x in PX:
    cnt[p-1] += x

def dfs(v):
    for w in graph[v]:
        cnt[w-1] += cnt[v-1]
        graph[w].remove(v)
        if len(graph[w]) > 0:
            dfs(w)

dfs(1)

print(*cnt)

### FIXED CODE ###

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

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)