Harryxun/stf_run huggingface dataset:
import numpy as np
N, K = map(int, input().split(" "))
P = np.array(list(map(int, input().split(" "))))
ans = []
for i in range(N - K + 1):
    p = P[i: i + K]
    p_i = np.array([k for k in range(1, p[0] + 1)])
    for p_k in p[1:]:
        p_i = np.array([p_i + k for k in range(1, p_k + 1)]).flatten()
    ans.append(np.sum(p_i) / np.prod(p))
print(max(ans))
    

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
ex = [i + 1 for i in p]
ans = sum(ex[0: K])
max_ans = ans
for i in range(K, N):
    ans += ex[i] - ex[i - K]
    max_ans = max(ans, max_ans)
print(max_ans / 2.0)
in = int(input())
for i in list(range(10)):
     if in / i >= 10:
             print("No")
     else:
             print("Yes")

### FIXED CODE ###

k = int(input())
for i in range(1,10):
    if k // i <= 9 and k % i == 0:
       print("Yes")
       exit()
     
print("No")
#!/usr/bin/env python3
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = []
    t = 0
    for a in A:
        t += a
        B.append(t)

    i2 = bisect.bisect_left(B, B[N - 1] / 2, lo = 1, hi = N - 1)
    i1 = bisect.bisect_left(B, B[i2] / 2, hi = i2)
    i3 = bisect.bisect_left(B, B[i2] + (B[N - 1] - B[i2]) / 2, lo = i2 + 1)

    P = B[i1]
    Q = B[i2] - B[i1]
    R = B[i3] - B[i2]
    S = B[N - 1] - B[i3]

    min_d = max(P, Q, R, S) - min(P, Q, R, S)

    for i2 in range(1, N - 1):
        if min_d * 2 < abs(B[N - 1] - 2 * B[i2]):
            continue
        s0 = min(B[i2], B[N - 1] - B[i2])
        s1 = max(B[i2], B[N - 1] - B[i2])
        i1_lo = bisect.bisect_left(B, s0 / 2, hi = i2)
        if 1 <= i1_lo:
            i1_lo -= 1
        i1_hi = bisect.bisect_right(B, s1 / 2, lo = i1_lo, hi = i2)
        i3_lo = bisect.bisect_left(B, B[i2] + s0 / 2, lo = i2 + 1, hi = N - 1)
        if i2 + 1 <= i3_lo:
            i3_lo -= 1
        i3_hi = bisect.bisect_right(B, B[i2] + s1 / 2, lo = i3_lo, hi = N - 1)
        for i1 in range(i1_lo, i1_hi + 1):
            for i3 in range(i3_lo, i3_hi + 1):
                P = B[i1]
                Q = B[i2] - B[i1]
                R = B[i3] - B[i2]
                S = B[N - 1] - B[i3]
                d = max(P, Q, R, S) - min(P, Q, R, S)
                if d < min_d:
                    min_d = d


    print(min_d)


if __name__ == '__main__':
    main()



### FIXED CODE ###

#!/usr/bin/env python3
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = []
    t = 0
    for a in A:
        t += a
        B.append(t)

    T = B[N - 1]

    i2 = bisect.bisect_left(B, T / 2, lo = 1, hi = N - 2)
    i1 = bisect.bisect_left(B, B[i2] / 2, hi = i2)
    i3 = bisect.bisect_left(B, (T + B[i2]) / 2, lo = i2 + 1)

    P = B[i1]
    Q = B[i2] - B[i1]
    R = B[i3] - B[i2]
    S = T - B[i3]

    min_d = max(P, Q, R, S) - min(P, Q, R, S)
    min_half = T / 2 - min_d
    max_half = T / 2 + min_d

    i2_lo = bisect.bisect_left(B, min_half, lo = 1, hi = N - 2)
    i2_hi = bisect.bisect_left(B, max_half, lo = i2_lo, hi = N - 2) + 1

    for i2 in range(i2_lo, i2_hi):
        if min_d * 2 < abs(T - 2 * B[i2]):
            continue

        i1 = bisect.bisect_left(B, B[i2] / 2, hi = i2)
        i3 = bisect.bisect_left(B, (T + B[i2]) / 2, lo = i2 + 1)
        i1_lo, i1_hi = i1, i1 + 1
        i3_lo, i3_hi = i3, i3 + 1
        if B[i1] * 2 != B[i2] and 0 < i1:
            i1_lo -= 1
        if B[i3] * 2 != T + B[i2] and i2 + 1 < i3:
            i3_lo -= 1

        for i1 in range(i1_lo, i1_hi):
            P = B[i1]
            Q = B[i2] - B[i1]
            for i3 in range(i3_lo, i3_hi):
                R = B[i3] - B[i2]
                S = T - B[i3]
                d = max(P, Q, R, S) - min(P, Q, R, S)
                if d < min_d:
                    min_d = d


    print(min_d)


if __name__ == '__main__':
    main()
import itertools

N, M = map(int, input().split())
adj_matrix = [[0]*N for _ in range(N)]

# 隣接行列を作る
for i in range(N):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0

for each in itertools.permutations(range(N)):
    if each[0] != 0:  # 始点は1でないといけないから
        break
    factor = 1
    for i in range(N-1):
        factor *= adj_matrix[each[i]][each[i+1]]
    cnt += factor

print(cnt)

### FIXED CODE ###

import itertools

N, M = map(int, input().split())
adj_matrix = [[0]* N for _ in range(N)]

for i in range(M): #隣接行列
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0

for each in itertools.permutations(range(N)):
    if each[0] != 0:
        break
    factor = 1
    for i in range(N-1):
        factor *= adj_matrix[each[i]][each[i+1]]
    cnt += factor

print(cnt)
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
if rev == 1:
  S = S[::-1]
print("".join(S))
           
  

### FIXED CODE ###

from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)
S, T = input().split()
A, B= map(int, input().split())
U = input()
if S == U:
    print(A - 1, B)
elif:
    print(A, B - 1)

### FIXED CODE ###

S, T = input().split()
A, B= map(int, input().split())
U = input()
if S == U:
    print(A - 1, B)
else:
    print(A, B - 1)
# coding: utf-8

n = int(row_input())

print n*(n+1)/2

### FIXED CODE ###

# coding: utf-8
import sys
     
n = int(raw_input())
     
print n*(n+1)/2
n=int(input())
p=map(int, input().split())
q=map(int, input().split())

import math
a=0
for i in range(n-1):
  a+=(p[i]-1)*math.factorial(n-1-i)
b=0
for i in range(n-1):
  b+=(p[i]-1)*math.factorial(n-1-i)
  
print(abs(a-b))


### FIXED CODE ###

from itertools import permutations
n=int(input())
v=list(permutations(range(1,n+1),n))
print(abs(v.index(tuple(map(int,input().split())))-v.index(tuple(map(int,input().split())))))
n, m = map(int,input().split())

l = [[0 for _ in range(2)] for _ in range(m)]

f = 0
con = ""

for i in range(n):
    s, c = map(int,input().split()))
    if l[s-1][1] == 0 or l[s-1][0] == c:
        if s == 1 and c == 0:
            f = 1
            break
        l[s-1][0] = c
        l[s-1][1] = 1
    else:
        f = 1
        break
else:
    for j in range(m):
        if l[j][0] != 0:
            break
        else:
            f = 1
            break

if f:
    print(-1)
else:
    for i in range(m):
        con += str(l[i][0])
    print(int(con))
    


### FIXED CODE ###

# n = int(input())
n, m = map(int,input().split())
# l = [[0 for _ in range(n)] for _ in range(n)]
l = []
f = 0

for i in range(m):
    l.append(list(map(int,input().split())))

# print(l)

for i in range(1000):
    si = str(i)
    if len(si) == n:
        for j in range(m):
            # print(si, l)
            if si[l[j][0]-1] == str(l[j][1]):
                # print('OK')
                f = 0
            else:
                f = 1
                break
    else:
        continue
    if f == 0:
        print(si)
        exit()

print(-1)
#XY = [[1,1],[1,2],[2,2],[2,1]]
#N = len(XY)
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)


### FIXED CODE ###

N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
if N==1:
    print(1)
    exit()
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)
def main():
    count = 0
    ans = []
    N, K = map(int, input().split())
    for _ in range(K):
        d = int(input())
        a = [input() for _ in range(d)]
        ans.append(a)
    for _ in range(1, N + 1):
        if _ not in ans:
            count += 1

    print(count)
    return

main()

### FIXED CODE ###

def main():
    ans = []
    N, K = map(int, input().split())

    for i in range(K):
        d = int(input())
        a = map(int, input().split())
        for j in a:
            ans.append(j)

    count = 0
    for i in range(1, N + 1):
        if not i in ans:
            count += 1

    print(count)
    return

main()
def counter(n, x):
    count = 0
    for i in range(n-2):
        for j in range(1, n-1):
            for k in range(2, n):
                if i + j + k == x:
                    count += 1
    return count

while True:
    n, x = map(int, input().split())
    print(counter(n, x))
    

### FIXED CODE ###

def counter(n, x):
    count = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    count += 1
    return count

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    print(counter(n, x))
inp = map(int, input().split(' '))

l = []
for fst in inp:
    for sec in inp:
        if fst == sec:
            pass
        else:
            l.append(fst + sec)

print(min(l))


### FIXED CODE ###

inp = list(map(int, input().split(' ')))

l = []
for fst in inp:
    inp.remove(fst)
    for sec in inp:
        l.append(fst + sec)

print(min(l))
n=int(input())-1

nodes = {1: (None, 0, 0)}
for _ in range(n):
    [a, b, c] = map(int, input().split())
    if a > b:
        a,b=b,a
    nodes[b] = nodes[a], c, c + nodes[a][2]

def dist(a, b):
    if a == b:
        return 0
    if a[2] < b[2]:
        return b[1] + dist(a, b[0])
    if a[2] > b[2]:
        return a[1] + dist(a[0], b)

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

for _ in range(q):
    [x, y] = map(int, input().split())
    print(dist(nodes[x], nodes[k]) + dist(nodes[k], nodes[y]))


### FIXED CODE ###

n=int(input())-1

edges = {}
lens = {}
for _ in range(n):
    [a, b, c] = map(int, input().split())
    if a > b:
        a,b=b,a
    edges.setdefault(a, []).append(b)
    edges.setdefault(b, []).append(a)
    lens[(a,b)] = c

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

dists = {}
def build(x, d=0):
    ss = [(x, 0)]
    while ss:
        x, d = ss.pop()
        if x not in dists:
            dists[x] = d
            for c in edges.get(x, []):
                ss.append((c, d + lens[(min(x,c), max(x,c))]))

build(k)

for _ in range(q):
    [x, y] = map(int, input().split())
    print(dists[x] + dists[y])
a,b=map(int,input().split())
if a-2b>=0:
   print(a-2b)
else:
  print(0)

### FIXED CODE ###

a,b=map(int,input().split())
if a-2*b<0:
  print(0)
else:
  print(a-2*b)
s = input()
n = len(n)
aind = 0
for i , c in enumerate(s):
  if c == "A":
    aind =  i
    break
zind = 0
for i,c in enumerate(s):
  if c == "Z":
    zind = i
    
print(zind-aind)

### FIXED CODE ###

s = input()
 
aind = 0
for i , c in enumerate(s):
  if c == "A":
    aind =  i
    break
zind = 0
for i,c in enumerate(s):
  if c == "Z":
    zind = i
    
print(zind-aind + 1)
c1=input()[0]
c2=input()[1]
c3=input()[2]
print(c1+c2+c3)

### FIXED CODE ###

s=input()
t=input()
ans=0
for i in range(3):
    if s[i]==t[i]:
        ans+=1
print(ans)
def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def _get_base_x(n, x):
  a = [
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
      'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  ]
  b = []
  while True:
    s = n // x
    y = n % x
    b = b + [y]
    if s == 0:
      break
    n = s
  b.reverse()
  ret = []
  for i in b:
    ret.append(a[i - 1])
  print(''.join(ret))


def C(x):
  _get_base_x(x, 26)


def main():
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)

  # n, k = map(int, input().split())
  # p_list = map(int, input().split())
  # B(n, k, p_list)
  C(bignum(input()))
  # C(475255)


if __name__ == '__main__':
  main()


### FIXED CODE ###

def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def C(N):
  for i in range(99):
    if N < 26**i:
      ans = []
      for j in range(i):
        ans += chr(ord('a') + N % 26)
        N //= 26
      return ''.join(ans[::-1])
    else:
      N -= 26**i


def main():
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)

  # n, k = map(int, input().split())
  # p_list = map(int, input().split())
  # B(n, k, p_list)
  print(C(int(input())))
  #for i in range(1, 27):
  #  print(C(26 + i))
  # C(703)
  # C(18279)
  # C(475254)


if __name__ == '__main__':
  main()
k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

c = a[0] + (k - a[n - 1])

d = max(c,[a[i] - a[i - 1] for i in range(1, n)])

print(k - d)


### FIXED CODE ###

k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = a[0] + (k - a[n-1])
for i in range(1,n):
  c = max(c,a[i] - a[i-1])
print(k-c)
def main():
	N, M = map(int, input().split())
	A = list(map(int, input().split()))
	sums = [0]*(N+1)
	ans = 0
	mod = [0]*M
	mod[0] = 1
	for i in range(1, N+1):
		sums[i] = (sums[i-1] + A[i-1]) % M
		ans += mod[sums[i]]
		mod[sums[i]] += 1

	print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict
def main():
	N, M = map(int, input().split())
	A = list(map(int, input().split()))
	sums = [0]*(N+1)
	ans = 0
	mod = defaultdict(int)
	mod[0] = 1
	for i in range(1, N+1):
		sums[i] = (sums[i-1] + A[i-1]) % M
		ans += mod[sums[i]]
		mod[sums[i]] += 1

	print(ans)

if __name__ == '__main__':
    main()
a=input()
if a[1]=="+":
  print(a+b)
else:
  print(a-b)

### FIXED CODE ###

a=input().split()
if a[1]=="+":
  print(int(a[0])+int(a[2]))
else:
  print(int(a[0])-int(a[2]))
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


### FIXED CODE ###

n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
sx=0
for i in l[2:]:
    sx^=i
if sx>l[0]+l[1]:
    print(-1)
    quit()
if (l[0]+l[1]-sx)%2==1:
    print(-1)
    quit()
if sx^l[0]^l[1]==0:
    print(0)
    quit()
x=(l[0]+l[1]-sx)//2
y=x
if x&sx>0:
    print(-1)
    quit()
if x>l[0]:
    print(-1)
    quit()
for i in range(45,-1,-1):
    if sx>>i&1:
        if l[0]>=(x+(1<<i)):
            x+=(1<<i)
if x==0:
    print(-1)
    quit()
if 
print(l[0]-x)

### FIXED CODE ###

import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
sx=0
for i in l[2:]:
    sx^=i
if sx>l[0]+l[1]:
    print(-1)
    quit()
if (l[0]+l[1]-sx)%2==1:
    print(-1)
    quit()
if sx^l[0]^l[1]==0:
    print(0)
    quit()
x=(l[0]+l[1]-sx)//2
y=x
if x&sx>0:
    print(-1)
    quit()
if x>l[0]:
    print(-1)
    quit()
for i in range(45,-1,-1):
    if sx>>i&1:
        if l[0]>=(x+(1<<i)):
            x+=(1<<i)
if x==0:
    print(-1)
    quit()
print(l[0]-x)
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

### FIXED CODE ###

NK = input()
NK = NK.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)

print(dfs('0'))

### FIXED CODE ###

N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))
R = input()
G= input()
print ( G + (G - R))

### FIXED CODE ###

R = input()
G = input()
R = int(R)
G = int(G)
print ( 2*G - R)
def main():
    import numpy as np
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)

    a,b,q=map(int,input().split())
    S=np.array([int(input()) for _ in range(a)])
    T=np.array([int(input()) for _ in range(b)])
    
    for _ in range(q):
        x=int(input())
        s=np.searchsorted(S,x)
        t=np.searchsorted(T,x)
        if s==0 and t==0:
            print(max(S[0],T[0])-x)
        elif s==0 and t==b:
            print(S[0]-T[-1]+min(S[0]-x,x-T[-1]))
        elif s==0:
            print(min(max(S[0],T[t])-x,min(S[0]-x,x-T[t-1])+S[0]-T[t-1]))
                  
        elif s==a and t==0:
            print(T[0]-S[-1]+min(T[0]-x,x-S[-1]))
        elif s==a and t==b:
            print(x-min(S[-1],T[-1]))
        elif s==a:
            print(min(x-min(S[-1],T[t-1]),min(T[t]-x,x-S[-1])+T[t]-S[-1]))
                  
        elif t==0:
            print(min(max(T[0],S[s])-x,min(T[0]-x,x-S[s-1])+T[0]-S[s-1]))
        elif t==b:
            print(min(x-min(T[-1],S[s-1]),min(S[t]-x,x-T[-1])+S[s]-T[-1]))
        else:
            print(min(max(T[t],S[s])-x,x-min(T[t-1],S[s-1])))   
  
if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    INF=10**11
    from bisect import bisect_left
    a,b,q=map(int,input().split())
    S=[-INF]+[int(input()) for _ in range(a)]+[INF]
    T=[-INF]+[int(input()) for _ in range(b)]+[INF]

    for _ in range(q):
        x=int(input())
        s=bisect_left(S,x)
        t=bisect_left(T,x)
        ans=max(T[t],S[s])-x
        ans=min(ans,S[s]-T[t-1]+min(S[s]-x,x-T[t-1]))
        ans=min(ans,x-min(S[s-1],T[t-1]))
        ans=min(ans,T[t]-S[s-1]+min(T[t]-x,x-S[s-1]))
        print(ans)
if __name__=='__main__':
    main()
"\n".join(sort([input() for i in range(10)])[:-3:-1])

### FIXED CODE ###

print "\n".join([str(x) for x in (sorted([input() for i in range(10)])[:-4:-1])])
def isRTri(a, b, c):
    return a * a + b * b == c * c

a = [0, 0, 0]
n = input()
for k in range(n):
    a = map(int, raw_input().split())
    r = isRTri(a[0], a[1], a[2])
    print "YES" if r else "NO"

### FIXED CODE ###

def isRTri(a, b, c):
    return a * a + b * b == c * c

a = [0, 0, 0]
n = input()
for k in range(n):
    a = map(int, raw_input().split())
    a.sort()
    r = isRTri(a[0], a[1], a[2])
    print "YES" if r else "NO"
A = int(input())
B = int(input())
C = int(input())

if B < A:
    A, B = B, A

if C < A:
    A ,C = C, A

if C < B:
    B, C = C, B

if A != 5 or B != 5 or C != 7:
    print("NO")
else:
    print("YES")

### FIXED CODE ###

A, B, C = map(int, input().split())
if B < A:
    A, B = B, A

if C < A:
    A ,C = C, A

if C < B:
    B, C = C, B

if A != 5 or B != 5 or C != 7:
    print("NO")
else:
    print("YES")
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    tree = [list() for _ in range(N)]
    for _ in range(N-1):
        u, v = [int(x) for x in input().split()]
        u -= 1
        v -= 1
        tree[u].append(v)
        tree[v].append(u)

    # print(tree)

    ans = [1] * N
    # dfs
    from bisect import bisect_left
    def dfs(u, par, dp: list):
        if A[u] > dp[-1]:
            dp.append(A[u])
        else:
            dp[bisect_left(dp, A[u])] = A[u]
        ans[u] = max(ans[u], len(dp))
        for v in tree[u]:
            if v != par:
                dfs(v, u, dp)
                val = dp.pop()
                if val < A[u]:
                    dp.append(A[u])

    dfs(0, -1, [A[0]])

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



if __name__ == '__main__':
    main()


### FIXED CODE ###

from bisect import bisect_left


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    tree = [list() for _ in range(N)]
    for _ in range(N-1):
        u, v = [int(x) for x in input().split()]
        u -= 1
        v -= 1
        tree[u].append(v)
        tree[v].append(u)

    ans = [1] * N

    # dfs
    def dfs(u, par):
        nonlocal ans
        nonlocal dp
        pos = bisect_left(dp, A[u])
        old = dp[pos]
        dp[pos] = A[u]

        ans[u] = bisect_left(dp, float("inf")) - 1

        for v in tree[u]:
            if v == par:
                continue
            dfs(v, u)

        dp[pos] = old

    dp = [float("inf")] * (N+1)
    dp[0] = float("-inf")
    dfs(0, -1)

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


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10**6)
    main()
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n-1:
      memo=d[n-1]
    if cnt==n:
      #正のループがある
      if d[n-1]>memo:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n])
  print(d[n-1])
  
Bellmanford(n,m,0,es)  
    
    
      
  
  

  

### FIXED CODE ###

#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n-1:
      memo=d[n-1]
    if cnt==n:
      #正のループがある
      if d[n-1]>memo:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n-1])
        sys.exit()
  print(d[n-1])
  
Bellmanford(n,m,0,es)
S = input()
if len(S) == 1:
  print("No")
else:
  while (len(S) != 0):
    if S[0] == 'h' and S[1] == 'i':
      S = S[2:]
    else:
      break
  if len(S) != 0:
    print("No")
  else:
    print("Yes")

### FIXED CODE ###

S = input()
if len(S) % 2 == 1:
  print("No")
else:
  while (len(S) != 0):
    if S[0] == 'h' and S[1] == 'i':
      S = S[2:]
    else:
      break
  if len(S) != 0:
    print("No")
  else:
    print("Yes")
list = map(int,raw_input().split())

if x-r < 0:
    print "No"
elif x + r > W:
    print "No"
elif y-r < 0:
    print "No"
elif y+r > H:
    print "No"
else:
    print "Yes"


### FIXED CODE ###

W,H,x,y,r = map(int, input().split())
if x-r < 0 or x+r > W or y-r < 0 or y+r > H:
    print("No")
else:
    print("Yes")