Harryxun/stf_run huggingface dataset:
from math import inf
n, m, x = map(int, input().split())
ca = list()
for _ in range(n):
    ca.append(list(map(int, input().split())))

money = inf
tmp = 1
for i in range(n):
    tmp += 2**i
for i in range(tmp):
    B = str(format(i, str(n).zfill(n)+'b'))
    j = 0
    cnt = 0
    a = [0]*m
    for ch in B:
        if ch == '1':
            cnt += ca[j][0]
            for k in range(1, m+1):
                a[k-1] += ca[j][k]
        j += 1
    if a[0] >= x and a[1] >= x and a[2] >= x:
        money = min(cnt, money)

print(-1 if money == inf else money)


### FIXED CODE ###

from math import inf
n, m, x = map(int, input().split())
ca = list()
for _ in range(n):
    ca.append(list(map(int, input().split())))

money = inf
tmp = 1
for i in range(n):
    tmp += 2**i
for i in range(tmp):
    B = str(format(i, str(n).zfill(n)+'b'))
    j = 0
    cnt = 0
    a = [0]*m
    for ch in B:
        if ch == '1':
            cnt += ca[j][0]
            for k in range(1, m+1):
                a[k-1] += ca[j][k]
        j += 1
    for ch in a:
        if ch < x:
            break
    else:
        money = min(cnt, money)
print(-1 if money == inf else money)
N = int(input())
edges = [[]for _ in range(N+1)]
for _ in range(N-1):
    u,v,w = map(int,input().split())
    edges[u].append((v,w%2))
    edges[v].append((u,w%2))
colors = [0]*(N+1)
def dfs(n,p,c):
    colors[n] = c
    for nx,w in edges[n]:
        if nx != p:
            if w%2 == 0:
                dfs(nx,n,c)
            else:
                dfs(nx,n,(c+1)%2)

dfs(1,0,0)
for i in range(1,N+1):
    print(colors[i])

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()
x,y=map(int,input().split())

if x==1 and y==2:
    print(1)
    exit()

c=0
while x>1 or y>1:
    if x==y*2:
        if c*y<10**9+7:
            L=[1]*y
            L[0]=0
            L2=[1]*y
            for i in range(c):
                L2[i+1]=L[i+1]+L2[i]
                print(L2[-1])
                exit()
        else:
            print(c*7%10**9+7)
            exit()
    x-=1
    y-=2
    c+=1
print(0)

### FIXED CODE ###

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

mod=10**9+7
def nCr(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

if (X+Y)%3 != 0:
      print(0)
      exit()
 
n=((2*X)-Y)//3

m=((X+Y)//3)-n

if n<0 or m<0:
    print(0)
    exit()

ans = nCr(n+m,n,mod)
print(ans)
N = int(input())
K = (((8 * N + 1) ** (1/2) + 1) / 2)

def recursive(k):
    if k == 3:
        return [[1, 2], [1, 3], [2, 3]]
    else:
        before = recursive(k - 1)
        r = [_ for _ in range(1 + (k - 2) * (k - 1) // 2, 1 + k * (k - 1) // 2)]
        return ([before[_] + [r[_]] for _  in range(len(r))] + [r])

if K.is_integer() and K > 1:
    K = int(K)
    print('Yes')
    print(K)
    [print(K - 1, ' '.join(map(str, ary))) for ary in recursive(K)]
else:
    print('No')

### FIXED CODE ###

N = int(input())
K = (((8 * N + 1) ** (1/2) + 1) / 2)

def recursive(k):
    if k == 2:
        return [[1], [1]]
    else:
        before = recursive(k - 1)
        r = [_ for _ in range(1 + (k - 2) * (k - 1) // 2, 1 + k * (k - 1) // 2)]
        return ([before[_] + [r[_]] for _  in range(len(r))] + [r])

if K.is_integer():
    K = int(K)
    print('Yes')
    print(K)
    [print(K - 1, ' '.join(map(str, ary))) for ary in recursive(K)]
else:
    print('No')
import sys
n, m = map(int, sys.stdin.readline().split())
li = [[] for _ in range(m)]
for _ in range(m):
  i, k = map(str, sys.stdin.readline().split())
  i = int(i)
  li[i-1].append(k)
wa = 0
ac = 0
for i in li:
  for k in i:
    if k == 'WA':
      wa += 1
    if k == 'AC':
      ac += 1
      break
print(ac, wa)
  


### FIXED CODE ###

import sys
import math
import itertools
import numpy

rl = sys.stdin.readline

n, k= map(int, rl().split())
li = [[0, 0] for _ in range(n)]
for _ in range(k):
    a, b = rl().split()
    b = b.rstrip()
    a = int(a) - 1
    if li[a][1] == 0:
        if b == 'WA':
            li[a][0] += 1
        else:
            li[a][1] = 1
ac = 0
wa = 0
for lis in li:
    i, v = lis
    if v == 1:
        ac += 1
        wa += i
print(ac, wa)
def a(t,i):
    if i = l - 1:
        if eval(t)==7:
            print(t+"=7")
            exit()
        return
    a(t+"+"+N[i+1],i+1)
    a(t+"-"+N[i+1],i+1)

N = input()
l = len(N)
a(N[0],0)






### FIXED CODE ###

def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

s=input()
dfs(0,s[0],int(s[0]))
N = int(input())
X = N[-1]
if X == 2 or X == 4 or X == 5 or X == 7 or X == 9:
  print("hon")
if X == 3:
  print("bon")
else:
  print("pon")

### FIXED CODE ###

N = input()
X = int(N[-1])
if X == 2 or X == 4 or X == 5 or X == 7 or X == 9:
  print("hon")
elif X == 3:
  print("bon")
else:
  print("pon")
a = map(int, input().split())
b = max(a)
a.remove(b)
if sum(a) == b:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a = list(map(int, input().split()))
b = max(a)
a.remove(b)
if sum(a) == b:
  print("Yes")
else:
  print("No")
n, k, q = map(int, input().split())
a = [(int(x), i) for i, x in enumerate(input().split())]
a.sort()
m = a[q - 1][0] - a[0][0]
v = []
for i in range(1, n - q + 1):
    mi = a[q - 1 + i][0] - a[i][0]
    bis = list(range(i))
    d = 0
    for ai in range(i, i + q):
        ok = True
        for bi in bis:
            if abs(a[bi][1] - a[ai][1]) < k:
                bis.append(ai)
                ok = False
                con = False
                d += 1
                if i + q + d - 1 < n:
                    mi = a[q + i + d - 1][0] - a[i][0]
                    if mi < m:
                        con = True
                break
        if con: continue
        break
    if ok:
        m = mi
print(m)


### FIXED CODE ###

n, k, q = map(int, input().split())
a = [int(x) for x in input().split()]
m = None
for x in a:
    b = []
    c = []
    for y in a:
        if y < x:
            if len(c) >= k:
                c.sort()
                b.extend(c[:len(c) - k + 1])
            c = []
        else:
            c.append(y)
    if len(c) >= k:
        c.sort()
        b.extend(c[:len(c) - k + 1])
    if len(b) >= q:
        b.sort()
        if m is None or m > b[q - 1] - x: m = b[q - 1] - x
print(m)
s = input()
ans =='Yes'
if(s[0] == s[1] and s[2] == s[3]):
  ans =='Yes'
elif(s[0] == s[3] and s[1] == s[2]):
  ans =='Yes'
elif(s[0] == s[2] and s[1] == s[3]):
  ans =='Yes'
else:
  ans =='No'

if(s[0] == s[1] and s[1] == s[2] and s[2] == s[3]):
  ans =='No'
print(ans)


### FIXED CODE ###

s = input()
ans ='Yes'
if(s[0] == s[1] and s[2] == s[3]):
  ans ='Yes'
elif(s[0] == s[3] and s[1] == s[2]):
  ans ='Yes'
elif(s[0] == s[2] and s[1] == s[3]):
  ans ='Yes'
else:
  ans ='No'

if(s[0] == s[1] and s[1] == s[2] and s[2] == s[3]):
  ans ='No'
print(ans)
A, B, K = map(int, input().split())

risuto = []
for i in range(1, int(min(A, B) / 2) + 1):
    if (A % i == 0 & B % i == 0):
        risuto.append(i)
        
if (risuto == []):
    print("1")
else:
    print(risuto[K-1])

### FIXED CODE ###

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

if A > B:
    A, B = B, A

d = []
for i in range(1,A+1):
	if (A % i == 0 and B % i == 0):
		d.append(i)
	
d.reverse()
print(d[K-1])
def func(a_list, index_list):

    if len(a_list) == 0:
        score = 0
    else:
        i,x = a_list.pop()
        hoge = []
        for j in index_list:
            tmp = index_list.copy()
            tmp.pop(tmp.index(j))
            hoge.append(x*abs(i-j)+func(a_list.copy(), tmp))

        score = max(hoge)

    return score

def slove(n, k):
    a_list = sorted([(i, int(x)) for i,x in enumerate(k.split(), 1)],
                    key= lambda x:x[1], reverse=True)
    index_list = list(range(1,n+1))
    a = func(a_list, index_list)
    return a

if __name__ == "__main__":
    n = int(input())
    k = input()
    print(slove(n, k))

### FIXED CODE ###

def slove(n, a_list):

    dp = [[0]*(n+1) for i in range(n+1)]
    for i in range(n):
        for j in range(n-i):
            dp[i+1][j] = max(dp[i+1][j],
                         dp[i][j]+a_list[i+j][0]*abs(a_list[i+j][1]-i))
            dp[i][j+1] = max(dp[i][j+1],
                         dp[i][j]+a_list[i+j][0]*abs((n-1-j)-a_list[i+j][1]))

    return max([max(i) for i in dp])

if __name__ == "__main__":
    n = int(input())
    k = sorted([(int(x),i) for i,x in enumerate(input().split())], reverse=True)
    print(slove(n, k))
import numpy as np
import math
A, B, C, D = list(map(int, input().split()))

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E = lcm(C, D)

u = np.arange(A,B+1)
count_U = len(u)
u_c = [i for i in u if i % C == 0]
count_C = len(u_c)
u_d = [i for i in u if i % D == 0]
count_D = len(u_d)
u_e = [i for i in u if i % E == 0]
count_E = len(u_e)

answer = count_U - (count_C + count_D -count_E)
print(u)
print(u_c)
print(count_C)
print(u_d)
print(count_D)
print(u_e)
print(count_E)
print(answer)

### FIXED CODE ###

from fractions import gcd
 
a, b, c, d = map(int, input().split())
a = a - 1
 
def main():
    cd = c * d // gcd(c, d)
    print(b - a - f(c) - f(d) + f(cd))
 
def f(x):
    return b // x - a // x
 
main()
N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    s_i, c_i = map(int, input().split())
    s.append(s_i)
    c.append(c_i)
sc.sort(key = lambda x: x[0], reverse = True)
for i in range(10**(N-1), 10**N):
    for j in range(M):
        if str(i)[s[j]-1] != str(c[j]):
            break
        if j == M - 1:
            print(i)
            c = 1
            break
    if c == 1:
        break
    if i == 10**N -1:
        print(-1)


### FIXED CODE ###

N, M = map(int, input().split())
s = []
c = []
if M == 0:
    if N != 1:
        print(10**(N-1))
    else:
        print(0)
else:   
    for i in range(M):
        s_i, c_i = map(int, input().split())
        s.append(s_i)
        c.append(c_i)
    if N != 1:
        for i in range(10**(N-1), 10**N):
            for j in range(M):
                if str(i)[s[j]-1] != str(c[j]):
                    break
                if j == M - 1:
                    print(i)
                    c = 1
                    break
            if c == 1:
                break
            if i == 10**N -1:
                print(-1)
    else:
        for i in range(0, 10):
            for j in range(M):
                if str(i)[s[j]-1] != str(c[j]):
                    break
                if j == M - 1:
                    print(i)
                    c = 1
                    break
            if c == 1:
                break
            if i == 10**N -1:
                print(-1)
#input an interget
k=int(input())
#input an string
s=str(input())
#get the length of the string
x=int(len(s))
#get the difference in length between k and s
i=k-x

#if statement about how the string will function
#if the string is the same length as k then print it
if i==0:
    print(s)
#if not, append it
else:
    for i in range(x):
        s=s[0 : i : ] + s[i+1 : : ]
        for i in range(x):
            fix=str('.')
            lenfix=int(len(fix))=x

    print(s.append(fix))

### FIXED CODE ###

# Take both input K & S, then compare the length of S with K and assign it to length
# If the length is <= K print all
# And if length is >K print some of the character

K = int(input())
S = input()

x = 0

length = len(S)

if length <= K:
    print(S)
else:
    while x < K:
        print(S[x], end=(""))
        x += 1
    print("...")
import sys

N = int(sys.stdin.readline())


def dev(x):
    global cnt
    if x % 2 == 0:
        cnt += 1
        dev(x / 2)
    return cnt


sorted_list = sorted([2, 4, 8, 16, 32, 64, N], reverse=True)
min_index = sorted_list[sorted([2, 4, 8, 16, 32, 64, N], reverse=True).index(N) + 1]

cnt = 0
min_cnt = dev(min_index)
for i in range(min_index, N + 1, 2):
    cnt = 0
    result = dev(i)
    if min_cnt < result:
        print(i)
        exit()
print(min_index)

### FIXED CODE ###

m = int(input())
a = 1
for c in range(7):
  if (2 ** c) > m:
    break
  a = (2 ** c)
 
print(a)
import numpy as np

N = int(input())  
a = np.array(input().split(), dtype=np.int64)
b = copy.deepcopy(A)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if (np.sum(A) + a[i]) % 2  == 0:
        b[i] = a[i]
    else:
        b[i] = (a[i] + 1) % 2
        
ans = np.where(b == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))

### FIXED CODE ###

import numpy as np
import copy

N = int(input())  
a = np.array(input().split(), dtype=np.int32)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[i::i+1]
    if np.sum(A) % 2  == 0:
        a[i] = 0
    else:
        a[i] = 1
        
ans = np.where(a == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))
A, B, X = map(int, raw_input().split(" "))
if A==X or (X-A)<=B: print("YES")
else: print("NO")

### FIXED CODE ###

A, B, X = map(int, input().split(" "))
if X==A: print("YES")
elif X<A: print("NO")
else:
  if (X-A)<=B: print("YES")
  else: print("NO")
def lis(n):
    if n == 2:
        return [[10,1], [1,1]]
    else:
        l = lis(n-1)
        for i in range(len(l)):
            for j in range(len(l[i])):
                l[i][j] *= 10
                l[i].append(1)
        l.append([1 for i in range(len(l[0]))])
        return l
s = input()
li = lis(len(s))
sum = 0
for i in range(len(li)):
    for j in range(len(li[i])):
        sum += int(s[i])*li[i][j]
print(sum)

### FIXED CODE ###

s = input()

result = []

def spstr(made, left):
    for x in range(1, len(left)+1):
        new_made = made.copy()
        new_made.append(int(left[0:x]))
        new_left = left[x:]
        if new_left == "":
            result.append(new_made)
        else:
            spstr(new_made, new_left)
spstr([], s)

count = 0
for r in result:
    for n in r:
        count += n
print(count)
N = int(input())
return 0 if N[0] < N[1] else 10

### FIXED CODE ###

X,A = map(int,input().split())
 
print(0 if X<A else 10)
import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = tuple(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append(y)
    edge[y].append(x)

ans = [-1] * (N + 1)
inf = 10**8
LIS = [inf] * (N + 1)


def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in edge[s]:
        if t == parent:
            continue
        DFS(t, s)
    # 頂点sでの結果をもとに戻す
    LIS[i] = v
    return


DFS(1)
print(*ans[1:], sep="\n")

### FIXED CODE ###

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

N = int(input())
A = tuple(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append(y)
    edge[y].append(x)

ans = [-1] * (N + 1)
inf = 10**18
LIS = [inf] * (N + 10)


def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in edge[s]:
        if t == parent:
            continue
        DFS(t, s)
    # 頂点sでの結果をもとに戻す
    LIS[i] = v
    return


DFS(1)
print(*ans[1:], sep="\n")
n, *A = map(int, open(0).input().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])

### FIXED CODE ###

n, *A = map(int, open(0).read().split())
A = [0] + A + [0]
B = [abs(a1-a0) for a0, a1 in zip(A, A[1:])]
s = sum(B)
for i in range(1, n+1):
    print(s + abs(A[i-1]-A[i+1]) - B[i-1] - B[i])
N, M = map(int, input().split())
x = sorted([int(x) for x in input().split()])

diff = sorted([i - j for i, j in zip(x[1:], x[:-1])], reverse=True)
diff0 = diff[:N-1]
diff1 = set(diff[:N-1])


if N == 1:
    print(max(x)-min(x))
else:
    j = 0
    ans = 0
    for i in range(M-1):
        a = x[i+1] - x[i]
        if a in diff1 and len(diff0) != 0:
            if i - j >= 1:
                ans += x[i] - x[j]
            diff0.remove(a)
            j = i+1
            if len(diff0) == 0:
                ans += x[-1] - x[i+1]
                break
    print(ans)
    



### FIXED CODE ###

import sys

N, M = map(int, input().split())
x = sorted(map(int, input().split()))

if N >= M:
    print(0)
    sys.exit()
diff = [0]*(M-1)
for i in range(M-1):
    diff[i] = x[i+1] - x[i]
diff.sort()
ans = sum(diff[:M-N])
print(ans)
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

N, C = map(int,input().split())
Mx = 10**5
sch = [0]*Mx
plist = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int,input().split())
    plist[c-1].append((s,t))
for p in plist:
    if len(p)==0:
        continue
    p.sort()
    prevt = -1
    for s, t in p:
        if prevt == s:
            sch[prevt] += 1
        else:
            sch[s-1] += 1
        sch[t] -= 1
        prevt = t

for i in range(1,Mx):
    sch[i]+=sch[i-1]

print(max(sch))


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

N, C = map(int,input().split())
Mx = 10**5+1
sch = [[0]*Mx for _ in range(C)]
scht = [0]*Mx
plist = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int,input().split())
    plist[c-1].append((s,t))
for c, p in enumerate(plist):
    p.sort()
    prevt = 0
    for s, t in p:
        if prevt == s:
            sch[c][prevt] = 0
        else:
            sch[c][s] = 1
        sch[c][t] = -1
        prevt = t
    for i in range(1, Mx):
        if sch[c][i]==1:
            scht[i-1]+=1
        if sch[c][i]==-1:
            scht[i]-=1

for i in range(1, Mx):
    scht[i] += scht[i-1]

print(max(scht))
n=int(input())
s=str(input())
if s[:n//2]==s[n//2:]:
  print("Yes")
 else:
  print("No")

### FIXED CODE ###

n=int(input())
s=str(input())
if n%2!=0:
    print("No")
else:
    if s[:n//2]==s[n//2:]:
        print("Yes")
    else:
        print("No")
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    M = int(input())
    # d = [0] * M
    # c = [0] * M
    digits = []
    # d = sorted(d)

    for i in range(M):
        d, c = list(map(int, input().split()))

        if d == 0 and i == 0:
            continue

        for i in range(c):
            digits.append(d)

    if len(digits) == 1:
        print(0)
        return

    if len(digits) == 2:
        if digits[0] == 0:
            print(0)
        else:
            print(1)
        return

    # print(digits)
    ith = 1
    nxt = digits[i] + digits[i+1]
    # print(nxt)
    for i in range(2, len(digits)):
        if nxt + digits[i] >= 10:
            nxt = nxt % 10
            ith += 2
        else:
            nxt = nxt + digits[i]
            ith += 1

    print(ith)


if __name__ == '__main__':
    main()


### FIXED CODE ###

INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    M = int(input())
    N = 0
    S = 0

    for i in range(M):
        d, c = list(map(int, input().split()))

        if d == 0 and i == 0:
            continue

        S += d * c
        N += c

    print((N - 1) + (S - 1) // 9)


if __name__ == '__main__':
    main()
n,m=map(int,input().split())
print((n-1)*(m-1))

### FIXED CODE ###

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

cnt1,cnt2=0,0
for i in a:
    if i%2!=0:
        cnt1+=1
    if i%4==0:
        cnt2+=1
print('Yes' if cnt2>=cnt1 or (len(a)%2!=0 and cnt2+1>=cnt1) else 'No')
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2)*(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1: 
        if exlarge[k][l-1]== exlarge[k][l+1]==exlarge[k-1][l]==exlarge[k+1][l]==0:
          ans='No'
 
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2) for _ in range(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1 and exlarge[k][l-1]== exlarge[k][l+1]==exlarge[k-1][l]==exlarge[k+1][l]==0:
          ans='No'
 
print(ans)
n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reversed=True)
if a[m - 1] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

a.sort(reverse=True)
if a[m - 1] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")
import random
import sys
input = sys.stdin.readline
n = int(input())
stone = [0]+list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
dp = [[] for i in range(n+1)]
deg = [0]*(n+1)
stack = []
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
  deg[a] += 1
  deg[b] += 1
root = 0
for i in range(1,n+1):
  if deg[i] == 1:
    stack.append(i)
  elif root == 0:
    root = i
if root == 0:
  print(2/0)
  if stone[0] == stone[1]:
    print("YES")
  else:
    print("NO")
  exit()
deg[root] += 1
flg = 1
while stack:
  x = stack.pop()
  if x == root:
    if sum(dp[x]) != 2*stone[x] or max(dp[x]) > stone[x]:
      flg = 0
    break
  elif dp[x]:
    if max(max(dp[x])*2,sum(dp[x])) > stone[x]*2 or stone[x] > sum(dp[x]):
      flg = 0
      break
    stone[x] = 2*stone[x]-sum(dp[x])
  for y in graph[x]:
    if deg[y] > 1:
      dp[y].append(stone[x])
      deg[y] -= 1
      if deg[y] == 1:
        stack.append(y)
if flg:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
stone = [0]+list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
dp = [[] for i in range(n+1)]
deg = [0]*(n+1)
stack = []
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
  deg[a] += 1
  deg[b] += 1
root = 0
for i in range(1,n+1):
  if deg[i] == 1:
    stack.append(i)
  elif root == 0:
    root = i
if root == 0:
  if stone[1] == stone[2]:
    print("YES")
  else:
    print("NO")
  exit()
deg[root] += 1
flg = 1
while stack:
  x = stack.pop()
  if x == root:
    if sum(dp[x]) != 2*stone[x] or max(dp[x]) > stone[x]:
      flg = 0
    break
  elif dp[x]:
    if max(max(dp[x])*2,sum(dp[x])) > stone[x]*2 or stone[x] > sum(dp[x]):
      flg = 0
      break
    stone[x] = 2*stone[x]-sum(dp[x])
  for y in graph[x]:
    if deg[y] > 1:
      dp[y].append(stone[x])
      deg[y] -= 1
      if deg[y] == 1:
        stack.append(y)
if flg:
  print("YES")
else:
  print("NO")