Harryxun/stf_run huggingface dataset:
n,m = list(map(int,input().split()))
votes = list(map(int,input().split())

s_vote = sum(vote)
st = 1 // 4 * s_vote
count = 0
for v in votes :
    if v >= st:
        count += 1
print("Yes" if count >= m else "No")

### FIXED CODE ###

n,m = list(map(int,input().split()))
votes = [int(x) for x in input().split()]
votesum = sum(votes)
st = votesum / (4 * m)
count = 0
for v in votes :
    if v >= st:
        count += 1
print("Yes" if count >= m else "No")
from collections import defaultdict


def dfs(u, add):
    cnt[u] += add
    for nu in graph[u]:
        dfs(nu, add)


n, q = map(int, input().split())
graph = defaultdict(list)

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

cnt = [0] * (n + 1)


for _ in range(q):
    p, x = map(int, input().split())
    dfs(p, x)

print(*cnt[1:])

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

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

graph = defaultdict(set)

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

arr = [0] * (n + 1)

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


def solve():
    stack = [1]
    visited = [True] * 2 + [False] * (n - 1)

    while stack:
        curr = stack.pop()
        for leaf in graph[curr]:
            if visited[leaf]:
                continue
            stack.append(leaf)
            visited[leaf] = True
            arr[leaf] += arr[curr]

    return arr


arr = solve()

print(*arr[1:])
import sys
from operator import itemgetter
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
E = [None]*2*N
for n in range(N):
	a,b,c = map(int,inputs().split())
	E[2*n] = (a - c, 1, c)
	E[2*n + 1] = (b - c, -1, c)
E.sort(key=itemgetter(0))
tuple(E)
mini = 1000000001
kouho = {1000000001}
my_add = kouho.add
my_discard = kouho.remove
q = 0
d = int(inputs())
flag = False
cont = False
for e in E:
	while(e[0] > d):
		print(kouho)
		if cont == True:
			if mini < 1000000001:
				print(mini)
			else:
				print(-1)
		else:
			mini = min(kouho)
			if mini < 1000000001:
				print(mini)
			else:
				print(-1)
		cont = True
		if q < Q-1:
			q = q + 1
			d = int(inputs())
		else:
			flag = True
			q = q + 1
			break
	if flag == True:
		break
	if e[1] == 1:
		my_add(e[2])
		if mini > e[2]:
			mini = e[2]
	elif e[1] == -1:
		my_discard(e[2])
		cont = False
for t in [None]*(Q-q):
	print(-1)

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
import sys

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

p=list(map(int,input().split()))
c=list(map(int,input().split()))

check=[0 for i in range(n)]

if max(c)<0:
    print(max(c))
    sys.exit()

ans=0

for i in range(n):
    if check[i]==0:
        cnt=0
        check[i]=1
        li=[i]
        pc=p[i]-1
        while pc!=i:
            check[pc]=1
            li.append(pc)
            pc=p[pc]-1
        sumli=0
        for j in li:
            sumli+=c[j]
        add=0
        ki=k
        if sumli>0:
            add=sumli*(k//len(li))
        if ki>len(li):
            ki=ki%len(li)
        for w in range(1,ki+1):
            sumwmax=0
            sumw=0
            for j in range(w):
                sumw+=c[li[j]]
            for j in range(len(li)):
                sumw=sumw-c[li[j]]+c[li[(j+w)%len(li)]]
                print(sumw)
                sumwmax=max(sumw,sumwmax)
            cnt=max(cnt,sumwmax)
    ans=max(ans,cnt+add)

print(ans)

### FIXED CODE ###

import sys

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

p=list(map(int,input().split()))
c=list(map(int,input().split()))

check=[0 for i in range(n)]

if max(c)<0:
    print(max(c))
    sys.exit()

ans=0

for i in range(n):
    if check[i]==0:
        cnt=0
        check[i]=1
        li=[i]
        pc=p[i]-1
        while pc!=i:
            check[pc]=1
            li.append(pc)
            pc=p[pc]-1
        sumli=0
        for j in li:
            sumli+=c[j]
        add=0
        ki=k
        if k>len(li):
            if sumli>0:
                ki=(ki-1)%len(li)+1
                add=sumli*((k-ki)//len(li))
            else:
                ki=len(li)
        for w in range(1,ki+1):
            sumwmax=0
            sumw=0
            for j in range(w):
                sumw+=c[li[j]]
            for j in range(len(li)):
                sumw=sumw-c[li[j]]+c[li[(j+w)%len(li)]]
                sumwmax=max(sumw,sumwmax)
            cnt=max(cnt,sumwmax)
        ans=max(ans,cnt+add)

print(ans)
n, k = map(int, input().split())
s = input()
s[k - 1] = s[k - 1].lower()
print(s)

### FIXED CODE ###

n, a = list(map(int, input().split()))
s = input()
print(s[:a - 1] + s[a - 1].lower() + s[a:])
X,N = map(int,input().split())
if N == 0:
	print(X)
else:
	p = list(map(int,input().split()))
	p.sort()

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)

	for x in range(0,diff+1):
		if X-x not in p
			print(X-x)
			break
		if X+x not in p
			print(X+x)
			break

### FIXED CODE ###

X,N = map(int,input().split())
if N == 0:
	print(X)
else:
	p = list(map(int,input().split()))
	p.sort()

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)


	for x in range(diff+2):
		if X-x not in p:
			print(X-x)
			break
		if X+x not in p:
			print(X+x)
			break
N = int(input())
array = []
for i in range(N):
    array.append(list(map(str, input().split())))
array_new = sorted(array, key=lambda x: (x[0], -x[1]))
for i in range(N):
    print(int(array.index(array_new[i])+1))

### FIXED CODE ###

N = int(input())
array = []
for i in range(N):
    array.append(list(map(str, input().split())))
array_new = sorted(array, key=lambda x: (x[0], -int(x[1])))
for i in range(N):
    print(int(array.index(array_new[i])+1))
A,B = map(int,input().split())

if (A % 3 == 0) or(B%3==0) or((A+B)%3==):
  print("Possible")
else:
  print("Impossible")

### FIXED CODE ###

A,B = map(int,input().split())
 
if (A%3==0) or(B%3==0) or((A+B)%3==0):
  print("Possible")
else:
  print("Impossible")
N, X = map(int, input().split())
L = list(map(int, input().split()))

ans = 1
sum = 0

for i in range(N):
    sum += L[i]
    if sum <= X:
        num += 1
    else:
        break

print(ans)



### FIXED CODE ###

N,X = map(int,input().split())
L = list(map(int,input().split()))

ans = 1 #位置0も1にカウントするから
p = 0 #今のポジション
for i in range(N):
    p += L[i]
    if p <= X:
         ans += 1
    else:
        break

print(ans)
from networkx.drawing.nx_pylab import draw_networkx
import networkx as nx
import matplotlib.pyplot as plt

n,x,y = map(int,input().split())
G = nx.Graph()
G.add_nodes_from(list(range(n)))
inf = 10**10
D = [[inf]*n for i in range(n)]
for i in range(n-1):
    #G[i].append(i+1)
    #G[i+1].append(i)
    G.add_edge(i,i+1)
    D[i][i+1] = 1
    D[i+1][i] = 1
G.add_edge(x-1,y-1)
D[x-1][y-1] = 1
D[y-1][x-1] = 1

for i in range(n):
    D[i][i] = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            D[i][j] = min(D[i][j],D[i][k]+D[k][j])

s = set()
ans = [0]*(n-1)
paths = nx.shortest_path(G)
for i in range(n):
    for j in range(n):
        if (min(i,j),max(i,j)) in s:
            pass
        else:
            s.add((min(i,j),max(i,j)))
            c = len(paths[i][j])-1
            if c:
                ans[c-1] += 1
for ai in ans:
    print(ai)

### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0] * (n - 1)

x -= 1
y -= 1
for i in range(n):
    for j in range(n):
        c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        if c:
            ans[c-1] += 1

for ai in ans:
    print(ai//2)
s=input()
l=len(s)
x,y=0
for i in range(l):
  if s[i]=='A':
    x=i
    break
for j in range(l-1,0,-1):
  if s[j]=='Z':
    y=j
    break
print(y-x+1)

### FIXED CODE ###

s=input()
l=len(s)
x=0
y=0
for i in range(l):
  if s[i]=='A':
    x=i
    break
for j in range(l-1,0,-1):
  if s[j]=='Z':
    y=j
    break
print(y-x+1)
import math
s = input()
k = int(input())
s = list(s)
ind = 0
anss = [[] for i in range(100)]
for i in range(len(s)-1):
  anss[ind].append(s[i])
  if s[i] != s[i+1] and i != len(s)-2:
    ind += 1
  elif i == len(s)-2:
    ind += 1
#print(ind)
#print(anss)
for i in range(100-ind):
  anss.remove([])
#print(anss)
f = 0
pf = 0
if len(anss) == 0:
  anss.append([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-1] and len(anss)>1 and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1:
    f = 1
elif s[0] == s[len(s)-1] and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1:
    #print(len(anss[0]),pf)
    f = 1
elif s[len(s)-2] == s[len(s)-1] and k > 1:
  anss[len(anss)-1].append(s[len(s)-1])
else:
  anss.append([s[len(s)-1]])
pans = 0
#print(anss)
for i in anss:
  pans += math.floor(len(i) / 2)
#print(f)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print(math.floor(len(list(s*k))/2))
elif f == 1:
  print(pans*k-1)
else:
  print(pans*k)

### FIXED CODE ###

s = input()
k = int(input())
s = list(s)
ind = 0
anss = [[] for i in range(100)]
for i in range(len(s)-1):
  anss[ind].append(s[i])
  if s[i] != s[i+1] and i != len(s)-2:
    ind += 1
  elif i == len(s)-2:
    ind += 1
#print(ind)
#print(anss)
for i in range(100-ind):
  anss.remove([])
#print(anss)
f = 0
pf = 0
if len(anss) == 0:
  anss.append([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-1] and len(anss)>1 and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    f = 1
elif s[0] == s[len(s)-1] and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    #print(len(anss[0]),pf)
    f = 1
elif s[len(s)-2] == s[len(s)-1] and k > 1:
  anss[len(anss)-1].append(s[len(s)-1])
else:
  anss.append([s[len(s)-1]])
pans = 0
#print(anss)
for i in anss:
  pans += len(i) // 2
#print(f)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print((len(s)*k)//2)
elif f == 1:
  print(pans*k-1)
else:
  print(pans*k)
a,b,c,d = map(int, input().split())

if a = b or a = c or a = d or b = c or b = d or c =d:
  print('Good')
else:
  print('Bad

### FIXED CODE ###

n = int(input())
 
a = int(n/1000)
b = int(n/100) -a*10
c = int(n/10)-a*100 - b*10
d = n -a*1000-b*100-c*10
 
if a == b  or b ==c or c == d :
  print("Bad")
else:
  print("Good")
# -*- coding: utf-8 -*-
# D_ans.pyからコメントなど不要部分削除したもの

class UnionFindbySize:
    def __init__(self, n):
        self.parent = [-1 for i in range(n)]

    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def issame(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        else:
            self.parent[y] += self.parent[x]    # yの要素数を増やす
            self.parent[x] = y
            return True

    def size(self, x):
        return -self.parent[self.root(x)]

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1

uf = UnionFindbySize(N)
res = [0] * (M)
res[-1] = N*(N-1)//2

i = 1
for a, b in zip(A[1::-1], B[1::-1]):
    if uf.issame(a, b):
        res[-1-i] = res[-i]
    else:
        sa = uf.size(a)
        sb = uf.size(b)
        res[-1-i] = res[-i] - sa*sb
        uf.unite(a, b)
    i+=1

for r in res[1:]:
    print(r)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# D_ans.pyからコメントなど不要部分削除したもの
import sys
sys.setrecursionlimit(10**6) 

class UnionFindbySize:
    def __init__(self, n):
        self.parent = [-1 for i in range(n)]

    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def issame(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        else:
            self.parent[y] += self.parent[x]    # yの要素数を増やす
            self.parent[x] = y
            return True

    def size(self, x):
        return -self.parent[self.root(x)]

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1

uf = UnionFindbySize(N)
res = [0] * (M)
res[-1] = N*(N-1)//2

i = 1
for a, b in zip(A[::-1], B[::-1]):
    id = M - 1 - i
    if id < 0:
        break
    if uf.issame(a, b):
        res[id] = res[id+1]
    else:
        sa = uf.size(a)
        sb = uf.size(b)
        res[id] = res[id+1] - sa*sb
        uf.unite(a, b)
    i+=1

for r in res:
    print(r)
L,R=map(int, input().split())

if R-L+1>=2019:
    print(0)
else:
    L %= 2019
    R %= 2019
    if L<R:
        k=L*(L+1)
        print(k)
    else:
        print(0)


### FIXED CODE ###

#スペース区切りの整数の入力
N, A, B  = map(int, input().split())

Train = A * N
Taxi = B

if Train > Taxi:
    print(Taxi)
else:
    print(Train)
import sys
input = sys.stdin.readline

i = list(map(int,input().split()))
n = i[0]
l = i[1]
 
alist = []
i = 1
 
for i in range(n):
  x = l + i - 1
  alist.append(x)
  
  
  
 
k = 0
m = 0
for k in range(n):
  if abs(alist[k]) >= abs(alist[k+1]):
    m = k+1
  
  
  
  
print(sum(alist) - alist[m])
 

### FIXED CODE ###

i = list(map(int,input().split()))
n = i[0]
l = i[1]
 
alist = []
j = 0
 
for j in range(n):
  x = l + j
  alist.append(x)
  
   
k = 0
m = 0
for k in range(n-1):
  if abs(alist[k]) >= abs(alist[k+1]):
    m = k+1
  
  
print(sum(alist) - alist[m])
N = int(input())
A = input().split()
A.sort()
B = A[0::1]
b = sum(B)
C = A[1::1]
c = sum(C)
if b >= c:
  print(b-c)
else:
  print(c-b)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
B = A[0::2]
b = sum(B)
C = A[1::2]
c = sum(C)
if b >= c:
  print(b-c)
else:
  print(c-b)
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

def solve(x,y):
    if y<0:
        return False
    elif y==0:
        return True
    elif x==n:
        return False
    else:
        return solve(x+1,y) or solve(x+1,y-A[x])
    
for i in range(m):
    if solve(0,B[i]):
        print("yes")
    else:
        print("no")


### FIXED CODE ###

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

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1,n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - A[i] >=0) and (T[i-1][j-A[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1: print("yes")
    else: print("no")
import math

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

if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数

    assert r % 3 == 0
    
    print(114514)


### FIXED CODE ###

input_line = input().split()

num_array = int(input_line[0])
num_equal = int(input_line[1])

input_line = input() # 無視

equalized = 1
i = 0
while equalized < num_array:
    equalized += (num_equal - 1)
    # print(i, equalized)
    i += 1

print(str(i))
A, B = map(int, input())
print(max([A + B, A - B, A * B]))

### FIXED CODE ###

A, B = map(int, input().split())
print(max(A + B, A - B, A * B))
n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
#print(ab)
k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    print([k,answer])
    if k>ab[t][1]:
        #answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
#print(ab)
k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    #print([k,answer])
    if k>ab[t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    n,m,k=map(int, sys.stdin.readline().strip().split())
    #list(map(int,input().strip().split()))

    uf = UnionFind(n)

    res=[[] for i in range(n)]
    frd=[0 for i in range(n)]
    blk=[0 for i in range(n)]

    for i in range(m):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        uf.Unite(a,b)
        frd[a]+=1
        frd[b]+=1
    
    for i in range(k):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        if uf.isSameGroup(a,b):
            blk[a]+=1
            blk[b]+=1
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1-blk[i]-frd[i]
        rescnt.append(str(ri))
        ##rescnt.append(str(n-uf.size(i)-len(blk[i])))
    
    print(" ".join(rescnt))

resolve()

### FIXED CODE ###

import sys
from io import StringIO
import unittest
import math

def resolve():
    n = int(input().strip())

    n = round(n/2 + 0.1)
    print(int(n))
    return

resolve()
h, w = map(int, input().split())
mp = [list(input()) for i in range(h)]
dp = [[0]*105 for _ in range(105)]
if mp[0][0]=='#':
    dp[0][0]+=1
for i in range(w-1):
    plus=0
    if mp[0][i+1]=='#':
        plus=1
    dp[0][i+1] = dp[0][i]+plus
for i in range(h-1):
    plus=0
    if mp[i+1][0]=='#':
        plus=1
    dp[i+1][0] = dp[i][0]+plus

for i in range(1,w):
    for j in range(1,h):
        plus=0
        if mp[i][j]=='#':
            plus=1
        dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + plus

print(dp[h-1][w-1])
    




### FIXED CODE ###


h, w = map(int, input().split())
mp = [list(input()) for i in range(h)]
dp = [[0]*105 for _ in range(105)]
if mp[0][0]=='#':
    dp[0][0]+=1
for i in range(w-1):
    plus=0
    if mp[0][i+1]!=mp[0][i] and mp[0][i+1] == '#':
        plus=1
    dp[0][i+1] = dp[0][i]+plus
for i in range(h-1):
    plus=0
    if mp[i+1][0]!=mp[i][0] and mp[i+1][0] == '#':
        plus=1
    dp[i+1][0] = dp[i][0]+plus

for i in range(1,h):
    for j in range(1,w):
        plus=0
        plus2=0
        if mp[i][j]!=mp[i-1][j] and mp[i][j]=='#':
            plus=1
        if mp[i][j]!=mp[i][j-1] and mp[i][j]=='#':
            plus2=1
        dp[i][j] = min(dp[i-1][j]+plus, dp[i][j-1]+plus2)

print(dp[h-1][w-1])
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

sumlist1 = [[0]*N for _ in range(N)]
walist = [[0]*N for _ in range(N)]
loopcount = [0]*N

for h in range(N):
    sumlist1[h][0] = C[h]
    walist[h][0] = C[h]
    now = h
    l = 0
    for i in range(1,N):
        now = P[now]-1

        if sumlist1[h][i-1] < 0:
            sumlist1[h][i] = C[now]
        else:
            sumlist1[h][i] += sumlist1[h][i-1] + C[now]
        walist[h][i] += walist[h][i-1] + C[now]
        
        l += 1
        if now == h:
            break
    else:
        l += 1
    loopcount[h] = l
#print(sumlist1)

maxlist = [0]*N
for i in range(N):
    T = loopcount[i]
    wa = walist[i][T-1]
    #print(wa)

    loop = K//T
    amari = K%T

    if wa >= 0:
        if loop == 0:
            if amari != 0:
                maxlist[i] = wa*loop + max(sumlist1[i][:amari])
            else:
                maxlist[i] = wa*loop
        else:
            if amari != 0:
                maxlist[i] = max(wa*loop + max(sumlist1[i][:amari], wa*(loop-1) + max(sumlist1[i])))
            else:
                maxlist[i] = max(wa*loop, wa*(loop-1) + max(sumlist1[i]))
            

    else:
        if loop == 0:
            maxlist[i] = max(sumlist1[i][:amari])
        else:
            maxlist[i] = max(sumlist1[i])

print(max(maxlist))
#print(sumlist1)

### FIXED CODE ###

import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

sumlist1 = [[0]*N for _ in range(N)]
walist = [[0]*N for _ in range(N)]
loopcount = [0]*N

for h in range(N):
    sumlist1[h][0] = C[h]
    walist[h][0] = C[h]
    now = h
    l = 0
    for i in range(1,N):
        now = P[now]-1

        if sumlist1[h][i-1] < 0:
            sumlist1[h][i] = C[now]
        else:
            sumlist1[h][i] += sumlist1[h][i-1] + C[now]
        walist[h][i] += walist[h][i-1] + C[now]
        
        l += 1
        if now == h:
            break
    else:
        l += 1
    loopcount[h] = l
#print(sumlist1)

maxlist = [0]*N
for i in range(N):
    T = loopcount[i]
    wa = walist[i][T-1]
    #print(wa,T)

    loop = K//T
    amari = K%T

    if wa >= 0:
        if loop == 0:
            if amari != 0:
                maxlist[i] = wa*loop + max(sumlist1[i][:amari])
            else:
                maxlist[i] = max(sumlist1[i][:amari])
        else:
            if amari != 0:
                maxlist[i] = max(wa*loop + max(sumlist1[i][:amari]), wa*(loop-1) + max(sumlist1[i]))
            else:
                maxlist[i] = max(wa*loop, wa*(loop-1) + max(sumlist1[i][:T]))
            

    else:
        if loop == 0:
            maxlist[i] = max(sumlist1[i][:amari])
        else:
            maxlist[i] = max(sumlist1[i])

print(max(maxlist))
#print(sumlist1)
n, l = map(int, input().split())
if n == l:
  print("Yes")
 else:
  print("No")

### FIXED CODE ###

n, l = map(int, input().split())
if n == l:
  print("Yes")
else:
  print("No")
import sys
import io
import re
import math

i = [0]*255
#n = raw_input()
for x in sys.stdin.read().lower:
    i[ord(x)]+=1
for y in xrange(ord('a'), ord('z')+1):
    print chr(y)+ ' : ' +i[y]

### FIXED CODE ###

import time
import sys
import io
import re
import math
#start = time.clock()
i = [0]*127
#n = raw_input()
for x in sys.stdin.read().lower():
    i[ord(x)]+=1
for y in range(ord('a'), ord('z')+1):
    print chr(y)+ ' : ' + str(i[y])