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

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)

ok, ng = a[-1]*f[0], -1
while ok-ng > 1:
	x = (ok+ng)//2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x//f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)


### FIXED CODE ###

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)

ok, ng = a[-1]*f[0], -1
while ok-ng > 1:
	x = (ok+ng)//2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x//f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)
### BUGGY CODE ###

def hoge():
  from itertools import permutations
  N, M, R = map(int, input().split())
  r = map(int, input().split())
  inf = float('inf')
  d = [[inf] * N for i in range(N)]

  for i in range(N):
      d[i][i] = 0

  for i in range(M):
      a, b, c = map(int, input().split())
      a -= 1
      b -= 1
      t = min(c, d[a][b])
      if d[a][b] > c:
          d[a][b], d[b][a] = t, t


  for k in range(N):
      for i in range(N):
          for j in range(N):
              t = d[i][k] + d[k][j]
              d[i][j] = min(d[i][j], t)


  ans = inf
  for i in permutations(r):
      tmphoge = len(i) - 1
      temp = 0
      for j in range(tmphoge):
          temp += d[i[j]-1][i[j+1]-1]
          if temp > ans:
              break
      ans = min(ans, temp)

  print(ans)
hoge()


### FIXED CODE ###

from itertools import permutations

def input_list():
    return list(map(int, input().split()))

def main():
    n, m, r = input_list()
    rlist = input_list()
    rlist = [r-1 for r in rlist]
    d = [[float('inf')]*n for i in range(n)]
    for i in range(n):
        d[i][i] = 0
    
    for i in range(m):
        a, b, c = input_list()
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                distance = d[i][k]+d[k][j]
                if d[i][j] > distance:
                    d[i][j] = distance

    ans = float('inf')
    for p in permutations(rlist):
        distance = 0
        for i in range(r-1):
            distance += d[p[i]][p[i+1]]

        if ans > distance:
            ans = distance

    print(ans)

main()
### BUGGY CODE ###

n=list(map(int,input()))
d={}
d[0]=1
a=0
for i in reversed(range(len(n))):
    a+=(n[i]*10**(len(n)-i-1))
    a%=2019
    if not a in d:
        d[a]=1
    else:
        d[a]+=1

ans=0

for s,v in d.items():
    if v>=2:
        ans+=v*(v-1)//2
        
print(ans)

### FIXED CODE ###

n=list(map(int,input()))
d=[0]*2019
d[0]=1
a=0
b=len(n)
for i in reversed(range(b)):
    a+=(n[i]*pow(10,(b-i-1),2019))
    a%=2019
    d[a]+=1

ans=0

for i in range(2019):
    c=d[i]
    ans+=c*(c-1)//2
        
print(ans)
### BUGGY CODE ###

d1 = int(input())
d = input().split()
d2 = [int(x) for x in d]
count=0
for n in range(d1):

    for m in range(d1):
        if d2[n] == d2[m]:
            if n != m:
                count+=1


if count!=2 :
    print("YES")
else:
    print("NO")


### FIXED CODE ###

N = int(input())
A = map(int, input().split())
if N == len(set(A)):
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

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

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

for i in range(min(k,len(a))):
	for j in range(min(k,len(b))):
		for l in range(min(k,len(c))):
			great_list.append(a[i] + b[j] + c[l])

great_list.sort(reverse=True)
for i in great_list[:k]:
    print(i)


### FIXED CODE ###

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

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

for i in range(min(k,len(a)))[:k]:
	for j in range(min(k // (i+1),len(b)))[:k]:
		for l in range(min(k // ((i+1) * (j+1)),len(c)))[:k]:
			great_list.append(a[i] + b[j] + c[l])

great_list.sort(reverse=True)
for i in great_list[:k]:
    print(i)
### BUGGY CODE ###

import bisect
n,w_max=map(int,input().split())
W,V=[],[]
for i in range(n):
  w,v=map(int,input().split())
  W.append(w)
  V.append(v)
DP=[[float("inf") for i in range(10**5+1)] for j in range(n+1)]
DP[0][0]=1
for i in range(1,n+1):
  for j in range(i*(10**3)+1):
    if j>V[i-1]:
      DP[i][j]=min(DP[i-1][j],DP[i-1][j-V[i-1]]+W[i-1])
    else:
      DP[i][j]=min(DP[i-1][j],W[i-1])
ans=bisect.bisect_right(DP[n],w_max)-1
print(ans)

### FIXED CODE ###

import bisect
n,w_max=map(int,input().split())
W,V=[],[]
for i in range(n):
  w,v=map(int,input().split())
  W.append(w)
  V.append(v)
DP=[[float("inf") for i in range(10**5+1)] for j in range(n+1)]
DP[0][0]=1
for i in range(1,n+1):
  for j in range(i*(10**3)+1):
    if j>V[i-1]:
      DP[i][j]=min(DP[i-1][j],DP[i-1][j-V[i-1]]+W[i-1])
    else:
      DP[i][j]=min(DP[i-1][j],W[i-1])
ans=bisect.bisect_right(DP[n],w_max)-1
print(ans)
### BUGGY CODE ###

import numpy as np
H,W,A,B = (int(n) for n in input().split())

S = np.array([[0 for i in range(W)] for j in range(H)])
S = S.astype(int)

if A > W/2 or B > H/2:
    print('No')
else:
    for i in range(H):
        for j in range(W):
            if (i<B and j<A) or (B<=i and A<=j):
                S[i,j] = 0
            else:
                S[i,j] = 1
#    for i in range(H):
#        print(' '.join(map(str,S[i])))
    for s in S:
        print(''.join(map(str,s)))

### FIXED CODE ###

H,W,A,B = (int(n) for n in input().split())

S = [[0 for i in range(W)] for j in range(H)]

if A > W/2 or B > H/2:
    print('No')
else:
    for i in range(H):
        for j in range(W):
            if (i<B and j<A) or (B<=i and A<=j):
                S[i][j] = 1

#    for i in range(H):
#        print(' '.join(map(str,S[i])))
    for s in S:
        print(''.join(map(str,s)))
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
    geta = 32
    inf = 1<<geta
    dist = [inf] * N
    Q = [s]
    decided = set()
    for _ in range(N):
        while True:
            k = hpp(Q)
            dn = k>>geta
            vn = k^(dn<<geta)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, ((dn + df)<<geta)+vf)
    return dist

MOD = 10**9+7
N, M = map(int, readline().split())

S, T = map(int, readline().split())
S -= 1
T -= 1

Edge = [[] for _ in range(N)]
for _ in range(M):
    u, v, d = map(int, readline().split())
    u -= 1
    v -= 1
    Edge[u].append((v, d))
    Edge[v].append((u, d))


dists = dijkstra(N, S, Edge)
distt = dijkstra(N, T, Edge)
st = dists[T]

onpath = [i for i in range(N) if dists[i] + distt[i] == st]
oset = set(onpath)
Ls = sorted(onpath, key = lambda x: dists[x])
Lt = sorted(onpath, key = lambda x: distt[x])

dps = [0]*N
dpt = [0]*N
dps[S] = 1
dpt[T] = 1
for v in Ls[:-1]:
    for vf, cost in Edge[v]:
        if dists[v] + cost + distt[vf] == st:
            dps[vf] = (dps[vf] + dps[v])%MOD
for v in Lt[:-1]:
    for vf, cost in Edge[v]:
        if distt[v] + cost + dists[vf] == st:
            dpt[vf] = (dpt[vf] + dpt[v])%MOD

ans = dps[T]**2%MOD
for i in onpath:
    if dists[i] == distt[i]:
        ans = (ans - dps[i]**2*dpt[i]**2)%MOD
    
    for vf, cost in Edge[i]:
        if dists[i] + cost + distt[vf] == st:
            if dists[i] < st//2 and distt[vf] < st//2:
                ans = (ans - dps[i]**2*dpt[vf]**2)%MOD
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline

from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
    inf = geta
    dist = [inf] * N
    dist[s] = 0
    Q = [(0, s)]
    dp = [0]*N
    dp[s] = 1
    while Q:
        dn, vn = hpp(Q)
        if dn > dist[vn]:
            continue
        for df, vf in Edge[vn]:
            if dist[vn] + df < dist[vf]:
                dist[vf] = dist[vn] + df
                dp[vf] = dp[vn]
                hp(Q, (dn + df,vf))
            elif dist[vn] + df == dist[vf]:
                dp[vf] = (dp[vf] + dp[vn]) % MOD
    return dist, dp

MOD = 10**9+7
N, M = map(int, readline().split())
S, T = map(int, readline().split())
S -= 1
T -= 1

geta = 10**15
Edge = [[] for _ in range(N)]
for _ in range(M):
    u, v, d = map(int, readline().split())
    u -= 1
    v -= 1
    Edge[u].append((d, v))
    Edge[v].append((d, u))
    

dists, dps = dijkstra(N, S, Edge)
distt, dpt = dijkstra(N, T, Edge)
st = dists[T]

onpath = [i for i in range(N) if dists[i] + distt[i] == st]

ans = dps[T]**2%MOD
for i in onpath:
    if 2*dists[i] == 2*distt[i] == st:
        ans = (ans - pow(dps[i]*dpt[i], 2, MOD))%MOD
    
    for cost, vf in Edge[i]:
        if dists[i] + cost + distt[vf] == st:
            if 2*dists[i] < st < 2*dists[vf]:
                ans = (ans - pow(dps[i]*dpt[vf], 2, MOD))%MOD
print(ans)
### BUGGY CODE ###

n,q = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

from collections import defaultdict
d = defaultdict(int)
for i in range(q):
    tmp = list(map(int,input().split()))
    d[tmp[0]-1]+=tmp[1]

from collections import deque
ans =[0]*n
finish  = {0}
Q = deque()
Q.append([0,0])
while Q:
    node= Q.popleft()
    finish.add(node[0])

    val = node[1] + d[node[0]]
    ans[node[0]]+=val

    for nxt in link[node[0]]:
        if not nxt in finish:
            Q.append([nxt,val])

print(*ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

n,q = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

from collections import defaultdict
d = defaultdict(int)
for i in range(q):
    tmp = list(map(int,input().split()))
    d[tmp[0]-1]+=tmp[1]

from collections import deque
ans =[0]*n
finish  = {0}
Q = deque()
Q.append([0,0])
while Q:
    node= Q.popleft()
    finish.add(node[0])

    val = node[1] + d[node[0]]
    ans[node[0]]+=val

    for nxt in link[node[0]]:
        if nxt in finish:
            pass
        else:
            Q.append([nxt,val])

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

N = int(input())
P = list(map(int,input().split()))
result = 0
for i in range(N):
    miss = 0
    for j in range(i+1):
        if P[i]>P[i-j]:
            miss = 1
            break
    if miss == 0:
        result+=1
print(result)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)
### BUGGY CODE ###

def warshall_floyd(cost, num_v):
    """
    ワーシャルフロイド法
    :param cost: 隣接行列
    :param num_v: 頂点数
    :return: 各頂点からの最短距離
    """
    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    return cost


import itertools


def abc073_d():
    n, m, r = map(int, input().split())
    *r, = map(int, input().split())
    inf = float("inf")
    cost = [[inf] * n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c
    for i in range(n):
        cost[i][i] = 0

    cost = warshall_floyd(cost, n)
    ans = inf
    for permutation in itertools.permutations(r):
        c = 0
        b = permutation[0]
        for i in permutation[1:]:
            c += cost[b - 1][i - 1]
            b = i
        ans = min(ans, c)
    print(ans)


if __name__ == '__main__':
    abc073_d()


### FIXED CODE ###

def warshall_floyd(cost, num_v):
    """
    ワーシャルフロイド法
    :param cost: 隣接行列
    :param num_v: 頂点数
    :return: 各頂点からの最短距離
    """
    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    return cost


import itertools


def abc073_d():
    n, m, r = map(int, input().split())
    *r, = map(int, input().split())
    inf = float("inf")
    cost = [[inf] * n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c
    for i in range(n):
        cost[i][i] = 0

    cost = warshall_floyd(cost, n)
    ans = inf
    for permutation in itertools.permutations(r):
        c = 0
        b = permutation[0]
        for i in permutation[1:]:
            c += cost[b - 1][i - 1]
            b = i
        ans = min(ans, c)
    print(ans)


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


from collections import defaultdict

# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    return fact[a] * ifact[b] * ifact[a-b]


K = int(input())
S = input().strip()
N = len(S)

# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, N+K+1):
    fact[i] = fact[i-1] * i
    fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[N+K] = pow(fact[N+K], MOD-2, MOD)
for i in reversed(range(1, N+K+1)):
    ifact[i-1] = ifact[i] * i
    ifact[i-1] %= MOD

ans = 0
for i in range(K+1):
    now = pow(26, K-i, MOD)
    now *= pow(25, i, MOD)
    now %= MOD
    now *= combination(i+N-1, N-1)
    now %= MOD
    ans += now
    ans %= MOD

print(ans)


### FIXED CODE ###


from collections import defaultdict

# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    return fact[a] * ifact[b] * ifact[a-b]


K = int(input())
S = input().strip()
N = len(S)

# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, N+K+1):
    fact[i] = fact[i-1] * i
    fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[N+K] = pow(fact[N+K], MOD-2, MOD)
for i in reversed(range(1, N+K+1)):
    ifact[i-1] = ifact[i] * i
    ifact[i-1] %= MOD

ans = 0
for i in range(K+1):
    now = pow(26, K-i, MOD)
    now *= pow(25, i, MOD)
    now %= MOD
    now *= combination(i+N-1, N-1)
    now %= MOD
    ans += now
    ans %= MOD

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

import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]


    seen = [None]*n
    sys.setrecursionlimit(1000000)
    def dfs(graph,s):
        seen[s] = s+1
        for i in range(len(graph[s])):
            if seen[graph[s][i]-1]:
                continue
            dfs(graph, graph[s][i]-1)

    for i in range(m):
        a,b = map(int, input().split())

        fgraph[a-1].append(b)
        fgraph[b-1].append(a)

    for i in range(k):
        c,d = map(int, input().split())
        bgraph[d-1].append(c)
        bgraph[c-1].append(d)

    # print(fgraph)
    #print(bgraph)
    rk = [list()]*n
    for i in range(n):
        seen = [None]*n
        dfs(fgraph, i)
        rk[i] = seen
    
    # print(rk)
    # print(fgraph)
    for i in range(n):
        non = {None}
        me = {i+1}
        srk = set(rk[i])-non
        bg = set(bgraph[i])
        fg = set(fgraph[i])

        print(len(srk-bg-fg-me))
        
    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    is_all_seen = [False]*n
    cnt = 0
    seen = [None]*n
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    def dfs(graph,s,r):
        seen[s] = s+1
        if rks[s] is None:
            rks[s] = r

        for i in range(len(graph[s])):
            if seen[graph[s][i]-1]:
                continue
            dfs(graph, graph[s][i]-1,r)

    for i in range(m):
        a,b = map(int, input().split())

        fgraph[a-1].append(b)
        fgraph[b-1].append(a)

    # print(fgraph)
    #print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):

        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

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

N,K = map(int, input().split())
V = [int(v) for v in input().split()]


def f(L, i, n):
    if i == 0 or len(L) == 0:
        return 0
    if L[n] >= 0:
        t = L[n]
        if n >= 0:
            n += 1
        else:
            n -= 1
        return t+f(L,i-1,n)
    else:
        t = L[n]
        if n >= 0:
            n += 1
        else:
            n -= 1
        if i >= 2:
            return max(f(L, i-2, n), t+f(L, i-1, n))
        else:
            return t+f(L, i-1, n)
    
V_sort = sorted(V)
s = sum(V)
ans = 0
for i in range(1, K+1):
    if i >= N:
        c = s
        j = 0
        while j < N:
            if V_sort[j] < 0:
                c -= V_sort[j]
            else:
                j = N
            j += 1
        ans = max(ans, c)
    else:
        c = 0
        for j in range(i+1):
            c = max(c, f(V, j, 0)+f(V, i-j, -1))
        ans = max(ans, c)
        
print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
V = [int(v) for v in input().split()]

ans = 0
for i in range(K+1):
    if i < N:
        for j in range(i+1):
            temp1 = V[:j]
            temp2 = V[N-(i-j):]
            temp = temp1 + temp2
            temp.sort()
            s = sum(temp)
            k = 0
            while k < len(temp) and k < K-i:
                if temp[k] < 0:
                    s -= temp[k]
                k += 1
            ans = max(ans, s)
    else:
        temp = sorted(V)
        s = sum(temp)
        j = 0
        while j < min(N, i-N):
            if temp[j] < 0:
                s -= temp[j]
            j += 1
        ans = max(ans, s)
        
print(ans)
### BUGGY CODE ###

# import numpy as np
# import scipy as sp
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
# import sys ; sys.exit() # プログラム終了
# from copy import deepcopy ; b=deepcopy(a)
# chr(ord('a') + 1)
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#
from copy import deepcopy
from pprint import pprint
h, w = map(int, input().split())
ss = [list(map(str, list(input()))) for i in range(h)]
flag = False
for i in range(h):
    for j in range(w):
        if (ss[i][j] == "."):
            flag = True

ans = 0
while (flag):
    ans += 1
    s = deepcopy(ss)
    for i in range(h):
        for j in range(w):
            if (ss[i][j] == "#"):
                if i+1 < h:
                    s[i+1][j] = "#"
                if i-1 >= 0:
                    s[i-1][j] = "#"
                if j+1 < w:
                    s[i][j+1] = "#"
                if j-1 >= 0:
                    s[i][j-1] = "#"
    ss = deepcopy(s)
    flag = False
    for i in range(h):
        for j in range(w):
            if (ss[i][j] == "."):
                flag = True

print(ans)


### FIXED CODE ###

# import numpy as np
# import scipy as sp
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
# import sys ; sys.exit() # プログラム終了
# from copy import deepcopy ; b=deepcopy(a)
# chr(ord('a') + 1)
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#
from copy import deepcopy
from collections import deque

d = deque()
h, w = map(int, input().split())
s = [list(map(str, list(input()))) for i in range(h)]
used = [[True for j in range(w)] for i in range(h)]
# used = [[True]*w]*h
for i in range(h):
    for j in range(w):
        if (s[i][j] == "#"):
            d.append([i, j])
            used[i][j] = False


ans = -1
while (d):

    tmp = deque()
    while(d):
        i, j = d.popleft()

        if i+1 < h and used[i+1][j]:
            s[i+1][j] = "#"
            tmp.append([i+1, j])
            used[i+1][j] = False

        if i-1 >= 0 and used[i-1][j]:
            s[i-1][j] = "#"
            tmp.append([i-1, j])
            used[i-1][j] = False

        if j+1 < w and used[i][j+1]:
            s[i][j+1] = "#"
            tmp.append([i, j+1])
            used[i][j+1] = False

        if j-1 >= 0 and used[i][j-1]:
            s[i][j-1] = "#"
            tmp.append([i, j-1])
            used[i][j-1] = False

    d = tmp
    ans += 1

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

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

cnt=0
for i in range(1,N+1):
    for j in range(len(A)):
        if i == A[j]:
            cnt+=1
    print(cnt)
    cnt=0

### FIXED CODE ###

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

B=[0]*N

cnt=0
for i in range(len(A)):
    B[A[i]-1]+=1

for i in range(N):
    print(B[i])
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(5)]
ch = [0]*6
ch[0] = n
cnt = 0
while ch[5]!=n:
    ch2 = [0]*5
    for i in range(5):
        ch2[i] = min(ch[i],a[i])
    for i in range(5):
        ch[i] -= ch2[i]
        ch[i+1] += ch2[i]
    cnt+=1
print(cnt)

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(5)]
print(-(-n//min(a))+4)
### BUGGY CODE ###

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

a_sum = [0]
for i in range(n):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])

ans = 0
for i in range(n+1):
  for j in range(m+1):
    if a_sum[i] + b_sum[j] <= k:
      ans = max(ans, i + j)
    else:
      break
print(ans)

### FIXED CODE ###

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

a_sum = [0]
for i in range(n):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])
  
ans = 0
j = m
for i in range(n+1):
  if a_sum[i] > k:
    break
  while a_sum[i] + b_sum[j] > k:
    j -= 1
  ans = max(ans, i + j)
print(ans)