Harryxun/stf_run huggingface dataset:
from operator import itemgetter

n,q = map(int, input().split())

a = [0]*(n-1)
b = [0]*(n-1)
for i in range(n-1):
    a[i],b[i] = map(int, input().split())

p = [0]*q
x = [0]*q

for i in range(q):
    p[i],x[i] = map(int, input().split())

a,b = (list(x) for x in zip(*sorted(zip(a, b))))
p,x = (list(y) for y in zip(*sorted(zip(p,x))))


score = [0]*n

def down_tree(parent, add_score, q_start, n_start):
    global score
    for i in range(q_start, q):
        if p[i]-1 == parent:
            add_score += x[i]
        if p[i]-1 >parent:
            q_start = i
            break
    for i in range(n_start, n-1):
        if a[i]-1 == parent:
            down_tree(b[i]-1, add_score, q_start, i)
        if a[i]-1 > parent:
            break

    score[parent] += add_score

    return 0

down_tree(0, 0, 0, 0)

print(*score)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(200005)
n, q = map(int, input().split())

to = [[] for i in range(n+1)]


for i in range(n-1):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

score = [0]*(n+1)
for i in range(q):
    p, x = map(int, input().split())
    score[p] += x


def down_tree(index, parent):
    for i in to[index]:
        if i == parent:
            continue
        score[i] += score[index]
        down_tree(i, index)



down_tree(1, 1)

print(' '.join(map(str, score[1:])))
S={c:list for c in "abc"}
s="a"
while S[s]:
  s=S[s].pop(0)
print(s.upper())

### FIXED CODE ###

S={c:list(input()) for c in "abc"}
s="a"
while S[s]:
  s=S[s].pop(0)
print(s.upper())
a = input()

b = a.count('o')

if 8 - b <= 15 - len(s):
  print('YES')
else:
  print('NO')

### FIXED CODE ###

a = input()

b = a.count('o')

if 8 - b <= 15 - len(a):
    print('YES')
else:
    print('NO')
N,K = input().split()
N = int(N)
K = int(K)

have = []
result = 0

for i in range(N):
    have.append([0]*K)


for i in range(K):
    d = int(input())
    A = input().split()
    A = map(int,A)

    for a in A:
        have[a-1][d-1] = 1

for j in have:
    if j == [0,0]:
        result += 1

print(result)

### FIXED CODE ###

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

have = []
result = 0

for i in range(N):
    have.append([1]*K)


for i in range(K):
    d = int(input())
    
    A = input().split()
    A = map(int,A)

    for a in A:
        have[a-1][i-1] = 0

        
for j in have:
    if j == [1]*K:
        result += 1

print(result)
s=input()
ans=10000
for i in range(8):
    ans=min(ans,abs(int(s[i:i+3])-753))
print(ans)


### FIXED CODE ###

s=input()
ans=10000
for i in range(len(s)-2):
    ans=min(ans,abs(int(s[i:i+3])-753))
print(ans)
X = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
for k in yakusu:
    hani = int(math.log(X/k)) + 1
    for A in range(-1000, 1000):
        B = A-k
        if A**4 + (A**3)*B + (A**2)*(B**2) + A*(B**3) + B**4 == X/k:
            print(A, B)
            break

### FIXED CODE ###

X = int(input())
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort()
    return divisors

yakusu = make_divisors(X)
for k in yakusu:
    for A in range(-1000, 1000):
        B = A-k
        if A**4 + (A**3)*B + (A**2)*(B**2) + A*(B**3) + B**4 == X/k:
            print(A, B)
            break
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream')
f=1
for it in s:
    if it !='#':
        f=0
        break

if f==1:
    print("YES")
else :
    print("NO")

### FIXED CODE ###

s=input()
s=s.replace('eraser','*')
s=s.replace('erase','*')
s=s.replace("dreamer","*")
s=s.replace("dream","*")
f=1
for i in s:
    if i!='*':
        f=0
        break
if f:
    print("YES")
else:
    print("NO")
A, B = input().split()
coin = 0
for i in range(2):
    if A > B:
        coin = coin + A
        A = A - 1
    else:
        coin = coin + B
        B = B - 1
print(coin)

### FIXED CODE ###

A, B = input().split()
coin = 0
A = int(A)
B = int(B)
for i in range(2):
    if A > B:
        coin = coin + A
        A = A - 1
    else:
        coin = coin + B
        B = B - 1
print(coin)
S = input()

if S[3] ==S[4] and S[5] == S[6]:
  Print('Yes')
  else:
    Print('No')

### FIXED CODE ###

S = input()

if S[2]==S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')
#include<iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    if (n%2==0){
        cout<< n << endl;
    }else{
        cout << 2*n <<endl;
    }
}


### FIXED CODE ###

N = int(input())
if N%2==0:
  print(N)
else:
  print(2*N)
def main():
    a,b,c,d,e,f= map(int,input().split())

    # 100gあたりE [g]溶ける
    # ビーカーにF [g]いれられる
    # 濃度は100*砂糖 / (水＋砂糖)


    mizu=[]
    sato=[]


    x = int(f/100/a) +1
    y = int(f/100/b) +1

    for i in range(x):
        for j in range(y):
            mizu.append(i*100*a + j*100*b)

    mizu = [i for i in mizu if i <= f]
    mizu = list(set(mizu))
    mizu.sort()

    tokeru = int(f/100) * e
    x = int(tokeru / c) +1
    y = int(tokeru / d) +1

    for i in range(x):
        for j in range(y):
            sato.append(i*c + j*d)

    sato = [i for i in sato if i < tokeru]
    sato = list(set(sato))
    sato.sort()
    sato.remove(0)
    mizu.remove(0)

    tmp =0

    for i in mizu:
        for j in sato:
            if i + j <= f:
                if int(i/100)*e >=j:
                    if tmp <= (100*j) / (i + j):
                        tmp = (100*j) / (i + j)
                        ans = str(i+j) + " " + str(j)

    print(ans)


if __name__ == "__main__":
        main()


### FIXED CODE ###


def main():
    a,b,c,d,e,f= map(int,input().split())

    # 100gあたりE [g]溶ける
    # ビーカーにF [g]いれられる
    # 濃度は100*砂糖 / (水＋砂糖)


    mizu=[]
    sato=[]


    x = int(f/100/a) +1
    y = int(f/100/b) +1

    for i in range(x):
        for j in range(y):
            mizu.append(i*100*a + j*100*b)

    mizu = [i for i in mizu if i <= f]
    mizu = list(set(mizu))
    mizu.sort()

    tokeru = int(f/100) * e
    x = int(tokeru / c) +1
    y = int(tokeru / d) +1

    for i in range(x):
        for j in range(y):
            sato.append(i*c + j*d)

    sato = [i for i in sato if i < tokeru]
    sato = list(set(sato))
    sato.sort()
#    sato.remove(0)
#    mizu.remove(0)

    tmp =0

    for i in mizu:
        for j in sato:
            if i + j <= f and i + j !=0:
                if int(i/100)*e >=j:
                    if tmp <= (100*j) / (i + j):
                        tmp = (100*j) / (i + j)
                        ans = str(i+j) + " " + str(j)

    print(ans)


if __name__ == "__main__":
        main()
ans=list(input())
a=int(ans[0])
b=int(ans[1])
c=int(ans[2])
d=int(ans[3])
    pass=int(ans[3])
if b+c+d+e==7:
    print(str(a)+"+"str(b)+"+"+str(c)+"+"+str(d)=="7")
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')


### FIXED CODE ###

a=list(map(int,input()))
if a[0]+a[1]+a[2]+a[3]==7:
    print(str(a[0])+"+"+str(a[1])+"+"+str(a[2])+"+"+str(a[3])+"=7")
    exit()
elif a[0]+a[1]+a[2]-a[3]==7:
    print(str(a[0])+"+"+str(a[1])+"+"+str(a[2])+"-"+str(a[3])+"=7")
    exit()
elif a[0]+a[1]-a[2]+a[3]==7:
    print(str(a[0])+"+"+str(a[1])+"-"+str(a[2])+"+"+str(a[3])+"=7")
    exit()
elif a[0]+a[1]-a[2]-a[3]==7:
    print(str(a[0])+"+"+str(a[1])+"-"+str(a[2])+"-"+str(a[3])+"=7")
    exit()
elif  a[0]-a[1]+a[2]+a[3]==7:
    print(str(a[0])+"-"+str(a[1])+"+"+str(a[2])+"+"+str(a[3])+"=7")
    exit()
elif a[0]-a[1]+a[2]-a[3]==7:
    print(str(a[0])+"-"+str(a[1])+"+"+str(a[2])+"-"+str(a[3])+"=7")
    exit()
elif a[0]-a[1]-a[2]+a[3]==7:
    print(str(a[0])+"-"+str(a[1])+"-"+str(a[2])+"+"+str(a[3])+"=7")
    exit()
elif a[0]-a[1]-a[2]-a[3]==7:
    print(str(a[0])+"-"+str(a[1])+"-"+str(a[2])+"-"+str(a[3])+"=7")
    exit()
import sys
sys.setrecursionlimit(20000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)


### FIXED CODE ###

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

if K < len(A):
    ans = A[:K-1] + A[K-1].lower() + A[K:]
else:
    ans = A[:K-1] + A[K-1].lower()
print(ans)
import copy


class Line:
    def __init__(self, a, b):
        self.a = a
        self.b = b


def generate_patterns(remains, current_pattern, patterns):
    if len(remains) == 0:
        patterns.append(current_pattern)
        return
    for remain in remains:
        _current_pattern = copy.copy(current_pattern)
        _current_pattern.append(remain)
        _remains = copy.copy(remains)
        _remains.remove(remain)
        generate_patterns(_remains, _current_pattern, patterns)
    return patterns


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

m = {}
for line in lines:
    m.setdefault(line.a, {})
    m.setdefault(line.b, {})
    m[line.a][line.b] = True
    m[line.b][line.a] = True

remains = []
for i in range(2, N+1):
    remains.append(i)
patterns = generate_patterns(remains, [1], [])

cnt = 0
for pattern in patterns:
    countable = True
    for i in range(len(pattern)-1):
        current = pattern[i]
        next = pattern[i+1]
        if next not in m[current]:
            countable = False
            break
    if countable:
        cnt += 1

print(cnt)


### FIXED CODE ###

import copy


class Line:
    def __init__(self, a, b):
        self.a = a
        self.b = b


def generate_patterns(remains, current_pattern, patterns):
    if len(remains) == 0:
        patterns.append(current_pattern)
        return
    for remain in remains:
        _current_pattern = copy.copy(current_pattern)
        _current_pattern.append(remain)
        _remains = copy.copy(remains)
        _remains.remove(remain)
        generate_patterns(_remains, _current_pattern, patterns)
    return patterns


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

m = {}
for i in range(1, N+1):
    m[i] = {}
    for j in range(1, N+1):
        m[i][j] = False

for line in lines:
    m[line.a][line.b] = True
    m[line.b][line.a] = True

remains = []
for i in range(2, N+1):
    remains.append(i)
patterns = generate_patterns(remains, [1], [])

cnt = 0
for pattern in patterns:
    countable = True
    for i in range(len(pattern)-1):
        current = pattern[i]
        next = pattern[i+1]
        if not(m[current][next]):
            countable = False
            break
    if countable:
        cnt += 1

print(cnt)
S = input()
 if S == Sunny:
     print(Cloudy)
 elif S == Cloudy:
     print(Rainy)
 else :
     print(Sunny)

### FIXED CODE ###

def main():
    S = input()
    if S[0] == 'S':
        print("Cloudy")
    elif S[0] == 'R':
        print("Sunny")
    else:
        print("Rainy")
    pass
 
 
if __name__ == "__main__":
    main()
from collections import deque

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_upper = []

for i in reversed(x):
    if i<0:
        break
    if i>=0:
        x_upper.append(i)
        x.pop()
        
#絶対値昇順へソート
x.reverse()
x_upper.reverse()

lenXu = len(x_upper)
lenX = len(x)

if K>lenXu:
    min = K-lenXu-1
    max = lenXu-1
else:
    min = -1
    max = K-1


S = 10**8
differ = -1

while differ<0:
    S_stock = S
    if min>=0:
        if (x[min]*(-1))<x_upper[max]:
            S = (x[min]*(-1))*2 + x_upper[max]
        else:
            S = (x[min]*(-1)) + x_upper[max]*2
    else:
        S = x_upper[max]
    differ = S - S_stock
    min += 1
    max -= 1

print(S_stock)


### FIXED CODE ###

from collections import deque

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_upper = []

for i in reversed(x):
    if i<0:
        break
    if i>=0:
        x_upper.append(i)
        x.pop()
        
#絶対値昇順へソート
x.reverse()
x_upper.reverse()

lenXu = len(x_upper)
lenX = len(x)

if K>lenXu:
    l = K-lenXu-1
    h = lenXu-1
else:
    l = -1
    h = K-1

S = []
while l<K and l<lenX:
    if h<0:
        S.append(x[l]*(-1))
    elif l<0:
        S.append(x_upper[h])
    else:
        if (x[l]*(-1))<x_upper[h]:
            S.append((x[l]*(-1))*2 + x_upper[h])
        else:
            S.append((x[l]*(-1)) + x_upper[h]*2)
    l += 1
    h -= 1

print(min(S))
h,w,a,b=map(int,input().split())
if h==1:
    print('0'*a+'1'*(w-a))
elif w==1:
    for _ in [0]*b:
        print(0)
    for _ in [0]*(h-b):
        print(1)
elif h%b!=0 or w%a!=0 or h//b!=w//a:
    print('No')
else:
    ans=[[0]*w for _ in [0]*h]
    for i in range(h):
        for j in range(a*(i//b),a*(i//b)+a):
            ans[i][j]=1
    for x in ans:
        print(*x,sep='')

### FIXED CODE ###

h,w,a,b=map(int,input().split())
for _ in [0]*b:
    print('0'*a+'1'*(w-a))
for _ in [0]*(h-b):
    print('1'*a+'0'*(w-a))
from sys import stdin
readline = stdin.buffer.readline

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * W for _ in range(H)]
    HB = [0] * H
    WB = [0] * W
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        h -= 1
        w -= 1
        HW[h][w] = 1
        HB[h] += 1
        WB[w] += 1
    hb = max(HB)
    max_h = [i for i, x in enumerate(HB) if x == hb]
    wb = max(WB)
    max_w = [i for i, x in enumerate(WB) if x == wb]
    ch = False
    for mh in max_h:
        for mw in max_w:
            if HW[mh][mw] == 0:
                ch = True
                break
        if ch:
            break

    ans = hb + wb
    if not ch:
        ans -= 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    import sys
    from collections import defaultdict
    readline = sys.stdin.readline

    H, W, M = map(int, readline().rstrip().split())
    HB = [0] * H
    WB = [0] * W
    HW = defaultdict(lambda : False)
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        h -= 1
        w -= 1
        HW[(h,w)] = True
        HB[h] += 1
        WB[w] += 1
    hb = max(HB)
    max_h = [i for i, x in enumerate(HB) if x == hb]
    wb = max(WB)
    max_w = [i for i, x in enumerate(WB) if x == wb]
    
    ans = hb + wb
    for mh in max_h:
        for mw in max_w:
            if HW[(mh, mw)] == False:
                print(ans)
                sys.exit(0)
    print(ans - 1)

if __name__ == "__main__":
    main()
from collections import deque
order = int(input())
llist = [input().split() for _ in range(order)]
ans = deque([])
for lst in llist:
    if lst[0] == 'insert':
        ans.appendleft(lst[1])
    
    elif lst[0] == 'delete':
        ans.remove(lst[1])
   
    elif lst[0] == 'deleteFirst':
        ans.popleft()
    
    elif lst[0] == 'deleteLast':
        ans.pop()

print(*ans)

### FIXED CODE ###

from collections import deque
order = int(input())
llist = [input().split() for _ in range(order)]
ans = deque([])
count = 0
for lst in llist:
    if lst[0] == 'insert':
        ans.appendleft(lst[1])
    
    elif lst[0] == 'delete':
        if lst[1] in ans:
            ans.remove(lst[1])
   
    elif lst[0] == 'deleteFirst':
        ans.popleft()
    
    elif lst[0] == 'deleteLast':
        ans.pop()
        
    count += 1

print(*ans)
a,b,c = map(int,input().split())
min = a+b
if min >= a+c:
    min = a+c
elif min >= b+c:
    min = b+c
print(str(min)

### FIXED CODE ###

a,b,c = map(int,input().split())
print(min(a+b,b+c,c+a))
H, W = sorted(map(int,input().split()))
C = [input() for _ in range(H)]

ans = "Yes"
for i in range(H):
  for j in range(W):
    if(C[i][j] == "."):
      continue
    if(i > 0 and C[i-1][j] == "#"):
      continue
    if(i+1 < H and C[i+1][j] == "#"):
      continue
    if(j > 0 and C[i][j-1] == "#"):
      continue
    if(j+1 < W and C[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)

### FIXED CODE ###

H, W = map(int,input().split())
HW = [input() for _ in range(H)]

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(HW[i][j] == "."):
      continue
    if(i != 0 and HW[i-1][j] == "#"):
      continue
    if(j != 0 and HW[i][j-1] == "#"):
      continue
    if(j != H and HW[i+1][j] == "#"):
      continue
    if(j != W and HW[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)
import sys

input = sys.stdin.readline


def acinput():
    return list(map(int, input()[:-1].split(" ")))


class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x, y: x+y, default=0):
        self.size = 2**(size-1).bit_length()  # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2)  # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                # モノイドでは可換律は保証されていないので演算の方向に注意
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


def acinput():
    return list(map(int, input()[:-1].split(" ")))


N, K = acinput()

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

st = SegmentTree(N+10, f=max)

res = 0
for sa in A:
    L = max(sa-K, 0)
    R = min(sa+K, N+2)

    tmp = st.query(L, R+1)+1
    st.update(sa, tmp)
    res = max(tmp, res)

print(res)


### FIXED CODE ###



class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x, y: x+y, default=0):
        self.size = 2**(size-1).bit_length()  # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2)  # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                # モノイドでは可換律は保証されていないので演算の方向に注意
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


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

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

st = SegmentTree(300000+10, f=max)

res = 0
for sa in A:
    L = max(sa-K, 0)
    R = min(sa+K, 300001)

    tmp = st.query(L, R+1)+1
    st.update(sa, tmp)
    res = max(tmp, res)

print(res)
def acinput():
    return list(map(int,input().split(" ")))


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 

def lcm(x,y):
    return math.floor(x*y /gcd(x, y))

a,b,c,d=acinput()


l=lcm(c,d)
n_CandD=int(b/l)-int((a-1)/l)
n_C=int(b/c)-int((a-1)/c)
n_D=int(b/d)-int((a-1)/d)

print(int(b-a+1-(n_C+n_D-n_CandD)))


### FIXED CODE ###

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a


def acinput():
    return list(map(int, input().split(" ")))
def lcm(x, y):
    return x*y //gcd(x, y)

a, b, c, d = acinput()
l = lcm(c, d)
CD = b//l-(a-1)//l
nC = b//c-(a-1)//c
nD = b//d-(a-1)//d

res = b-a+1-(nC+nD-CD)
print(int(res))
K=int(input())

if(K%2==0):
    print(-1)
else:
    seven=7
    seven=seven%K
    for i in range(K+1):
        if(seven==0):
            ans=i+1
            break
        seven=(seven*10+7)%K
    
    print(ans)

### FIXED CODE ###


K=int(input())

if(K%2==0 or K%5==0):
  print("-1")

else:
  ans = 1
  s = 7
  while True:
    if s%K==0:
      print(ans)
      break
    else:
      s=(s%K)*10+7
      ans += 1
import sys
N = int(input())
t0, x0, y0 = 0, 0, 0

for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
        print('No')
	sys.exit()
    elif (dist -	dt)%2 ==1:
	print('No')
	sys.exit()

    else:
        t0, x0, y0 = t1, x1, y1



print('Yes')

### FIXED CODE ###

import sys

def main():
    N = int(input())
    t, x, y = 0, 0, 0

    for _ in range(N):
        next_t, next_x, next_y = [int(__) for __ in input().split()]

        delta_t = next_t - t
        distance = abs(next_x - x) + abs(next_y - y)

        if distance > delta_t:
            print("No")
            sys.exit()

        if (delta_t - distance) % 2 != 0:
            print("No")
            sys.exit()

        t, x, y = next_t, next_x, next_y

    print("Yes")

main()
n=int(input())
a=list(map(int,input().split()))
g = [[]for _ in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)
import copy
import queue
import bisect
check = [False]*n
check[0] = True
li = [a[0]]
import collections
q= collections.deque()
q.append([0,li])
ans = [0]*n
ans[0] = 1
while q:
    now,lisOrigin= q.popleft()
    for ne in g[now]:
        if check[ne]:
            continue
        check[ne] = True
        lis = copy.deepcopy(lisOrigin)
        if a[ne] > lis[-1]:
            lis.append(a[ne])
        else:
            lis[bisect.bisect_left(lis,a[ne])] = a[ne]
        q.append([ne,lis])
        ans[ne] = len(lis)n=int(input())
a=list(map(int,input().split()))
g = [[]for _ in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)
import copy
import queue
import bisect
check = [False]*n
check[0] = True
li = [a[0]]
import collections
q= collections.deque()
q.append([0,li])
ans = [0]*n
ans[0] = 1
while q:
    now,lisOrigin= q.popleft()
    for ne in g[now]:
        if check[ne]:
            continue
        check[ne] = True
        lis = copy.deepcopy(lisOrigin)
        if a[ne] > lis[-1]:
            lis.append(a[ne])
        else:
            lis[bisect.bisect_left(lis,a[ne])] = a[ne]
        q.append([ne,lis])
        ans[ne] = len(lis)

for i in range(n):
    print(ans[i])

for i in range(n):
    print(ans[i])

### FIXED CODE ###

from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)

n=int(input())
a=list(map(int,input().split()))
g = [[]for _ in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)

lis = [float('inf')]*n
ans = [0]*n

def dfs(now, pre):
    idx = bisect_left(lis, a[now])
    tmp = lis[idx]
    lis[idx] = a[now]
    ans[now] = bisect_left(lis, float('inf'))
    for to in g[now]:
        if to == pre:
            continue
        dfs(to, now)
    lis[idx] = tmp

dfs(0,-1)
for x in ans:
    print(x)