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



def main3():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    time_sum = 0
    counter = 0
    ans = []

    if bb[0] >= aa[0]:
        if k < aa[0]:
            return counter
    if bb[0] <= aa[0]:
        if k < bb[0]:
            return counter

    if (sum(aa)+sum(bb)) <= k:
        return n+m

    for i in range(n+1):
        counter = i
        time_sum = sum(aa[:i])
        if time_sum > k:
            break
        elif time_sum == k:
            ans.append(counter)
        else:
            for j in range(m):
                time_sum += bb[j]
                if time_sum > k and j != 0:
                    ans.append(counter)
                    break
                if time_sum > k and j == 0:
                    break
                elif time_sum == k:
                    counter += 1
                    ans.append(counter)
                    break
                else:
                    counter += 1

    ans.sort(reverse=True)
    return ans[0]


if __name__ == '__main__':
    ans = main3()
    print(ans)


### FIXED CODE ###

n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j >= 0:
        if k >= asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


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

N=int(input())
MAXN=1005
MAXV=N*(N-1)//2

a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1

id=[[0 for j in range(MAXN)] for i in range(MAXN)]
v=0
for i in range(N-1):
  for j in range(i+1,N):
    id[i][j]=v
    v+=1

def toId(i,j):
  if i>j:
    i,j=j,i
  return id[i][j]

to=[[] for i in range(MAXV)]
inner=[0 for i in range(MAXV)]
for i in range(N):
  for j in range(N-1):
    a[i][j]=toId(i,a[i][j])
  for j in range(N-2):
    to[a[i][j]].append(a[i][j+1])
    inner[a[i][j+1]]+=1

ans=0
stack=[]
isstarted=[False for i in range(v)]
dist=[0 for i in range(v)]
for i in range(v):
  if inner[i]==0:
    stack.append([i,1])

while stack:
  node=stack.pop()
  e=node[0]
  d=node[1]
  if d>dist[e]:
    dist[e]=d
  else:
    d=dist[e]
  if dist[e]>ans:
    ans=dist[e]
  inner[e]-=1
  if inner[e]<=0 and not isstarted[e]:
    isstarted[e]=True
    children=to[e]
    for child in children:
      stack.append([child,d+1])
for i in range(len(isstarted)):
  if not isstarted[i]:
    print(-1)
    break
else:
  print(ans)


### FIXED CODE ###

N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1
  a[i]=a[i][::-1]
    
q=[]

#seen=[[False for j in range(N)] for i in range(N)]

# 選手nが試合できるならqueに入れる
def check(i):
  if len(a[i])==0:
    return False
  j=a[i][-1]
  if a[j][-1]==i:
    q.append([i,j])
  
for i in range(N):
  check(i)
  
from collections import defaultdict

day=0
while q:
  day+=1
 # q=sorted(q)
  prevQ=q.copy()
  q=[]
  matched=defaultdict(list)
  for p in prevQ:
    i=p[0]
    j=p[1]
    if i>j:
      i,j=j,i
    if matched[i]:
      continue
    a[i].pop()
    a[j].pop()
    check(i)
    check(j)
    matched[i].append(j)
    
for i in range(N):
  if len(a[i])!=0:
    print(-1)
    break
else:
  print(day)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
# print(N, M, H, AB)


dictionary = {}
for A, B in AB:
    if dictionary.get(A) is None:
        dictionary[A] = []
    if dictionary.get(B) is None:
        dictionary[B] = []

    dictionary[A].append(H[B - 1])
    dictionary[B].append(H[A - 1])
# print(dictionary)

count = 0
for i, heights in dictionary.items():
    # print(i, type(i), H[i - 1], heights)
    if H[i - 1] > max(heights):
        count += 1

import itertools

paths = list(itertools.chain.from_iterable(AB))
# print(paths)
for i in range(1, N + 1):
    if not i in paths:
        count += 1

print(count)


### FIXED CODE ###

N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
# print(N, M, H, AB)


dictionary = {}
for A, B in AB:
    if dictionary.get(A) is None:
        dictionary[A] = []
    if dictionary.get(B) is None:
        dictionary[B] = []

    dictionary[A].append(H[B - 1])
    dictionary[B].append(H[A - 1])
# print(dictionary)

count = 0
for i, heights in dictionary.items():
    # print(i, type(i), H[i - 1], heights)
    if H[i - 1] > max(heights):
        count += 1

import itertools

# paths = list(itertools.chain.from_iterable(AB))
# print(paths)
for i in range(1, N + 1):
    if dictionary.get(i) is None:
        count += 1

print(count)
### BUGGY CODE ###

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

max_i = -1
max_sum = -1
for i in range(N-K+1):
    csum = sum(p[i:i+K])
    if  csum > max_sum:
        max_sum = csum
        max_i = i

# print(max_sum)
# print(max_i)
ans = 0
for k in range(K):
    ans += (p[max_i+k]+1)/2

print(ans)

    

### FIXED CODE ###

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

#累積和を使う
e_s = [0] * (N+1)
for i in range(N):
    # 期待値の計算
    e = (p[i]+1)/2
    e_s[i+1] = e_s[i] + e

ans = 0
for j in range(N-K+1):
    ans = max(ans,e_s[j+K]-e_s[j])
print(ans)
### BUGGY CODE ###

n, k, q = map(int, input().split())
tokuten = [k-q]*n

for i in range(q):
    a = int(input())
    for i in range(n):
        if i == a-1:
            tokuten[i] += 1


for i in range(n):
    if tokuten[i] <= 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n, k, q = map(int, input().split())
tokuten = [k-q]*n

for i in range(q):
    a = int(input())
    tokuten[a-1] += 1


for i in range(n):
    if tokuten[i] <= 0:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

from collections import deque

N = int(input())

A = [deque(map(int, input().split())) for _ in range(N)]

ans = 0

len_count = [0]*N
while sum(len_count) < N:
    update = False
    done = [0]*(N)
    for i in range(N):
        if done[i] == 1: continue
        if len(A[i]) == 0: continue
        tmp = A[i][0]-1
        if done[tmp] == 1: continue
        if len(A[tmp]) !=0 and A[tmp][0]-1 == i:
            update = True
            done[i] = 1
            done[tmp] = 1
            A[i].popleft()
            A[tmp].popleft()
            if len(A[i])==0:
                len_count[i] = 1
            if len(A[tmp])==0:
                len_count[tmp] = 1
    if not(update):
        print(-1)
        sys.exit()
    ans+=1
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

from collections import deque

N = int(input())
A = [deque(map(int, input().split())) for _ in range(N)]
q = []
def check(x):
    if len(A[x]) == 0: return
    tmp = A[x][0]-1
    if A[tmp][0]-1 == x:
        if tmp < x: x,tmp=tmp,x
        q.append((x,tmp))
        return

for i in range(N):
    check(i)
day = 0
while len(q) > 0:
    day+=1
    q = list(set(q))
    prevQ=[]
    prevQ,q=q,prevQ
    for i in range(len(prevQ)):
        x,y=prevQ[i]
        A[x].popleft()
        A[y].popleft()
    for i in range(len(prevQ)):
        x,y=prevQ[i]
        check(x)
        check(y)
    
for i in range(N):
    if len(A[i]) != 0:
        print(-1)
        sys.exit()
print(day)
### BUGGY CODE ###

N = int(input())
array = []
array += map(int,input().split())
sumarray = sum(array)
step = 0
while array != []:
    rearray=array[array.index(max(array)):]
    step+=len(rearray)*max(array)
    del array[array.index(max(array)):]
ans=step-sumarray
print(ans)


### FIXED CODE ###

N = int(input())
array = []
array+=map(int,input().split())
ans=0
premax=0
for n in range(N):
    premax=max(array[n],premax)
    ans+=premax-array[n]
print(ans)
### BUGGY CODE ###

while True:
    n, k = map(int, input().split())
    if n==0:break
    a = [int(input()) for _ in range(n)]
    print(max([sum(a[i:i+k]) for i in range(n) if len(a[i:i+k])==k]))

### FIXED CODE ###

from collections import deque
while True:
    n, k = map(int, input().split())
    if n==0:break
    a = deque(int(input()) for _ in range(k))
    ans=tmp=sum(a)
    for _ in range(n-k):
        x = a.popleft()
        y = int(input())
        a.append(y)
        tmp += y - x
        ans = max(ans, tmp)
    print(ans)
### BUGGY CODE ###

H,W,D = map(int, input().strip().split(' '))
A = [list(map(int, input().strip().split(' '))) for _ in range(H)]

a2pos = [None]*(H*W+1)
for h in range(H):
  for w in range(W):
    a2pos[A[h][w]] = [h,w]

def dist(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])

q = int(input().strip())
for _ in range(q):
  l,r = map(int, input().strip().split(' '))
  ans = 0
  now = l
  while now != r:
    ans += dist(a2pos[now+D], a2pos[now])
    now += D
  print(ans)


### FIXED CODE ###

H,W,D = map(int, input().strip().split(' '))
A = [list(map(int, input().strip().split(' '))) for _ in range(H)]

a2pos = [None]*(H*W+1)
for h in range(H):
  for w in range(W):
    a2pos[A[h][w]] = [h,w]

def dist(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])

a2dist = [0]*(H*W+1)
for i in range(1,(H*W)-D+1):
  a2dist[i+D] = a2dist[i]+dist(a2pos[i],a2pos[i+D])
  
q = int(input().strip())
for _ in range(q):
  l,r = map(int, input().strip().split(' '))
  print(a2dist[r]-a2dist[l])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def dfs(fr, now, num):
    global graph, addsum, ans
    tmp = num + addsum[now]
    for a in graph[now]:
        if a == fr:
            continue
        dfs(now, a, tmp)
    ans[now] = tmp


def main():
    global graph, addsum, ans
    N, Q = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1; b -= 1
        graph[a].append(b)
        graph[b].append(a)
    addsum = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        addsum[p] += x
    
    ans = [0]*N
    dfs(-1, 0, 0)

    print(*ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def dfs(fr, now, num):
    global graph, addsum, ans
    tmp = num + addsum[now]
    for a in graph[now]:
        if a == fr:
            continue
        dfs(now, a, tmp)
    ans[now] = tmp


def main():
    global graph, addsum, ans
    N, Q = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1; b -= 1
        graph[a].append(b)
        graph[b].append(a)
    addsum = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        addsum[p] += x
    
    ans = [0]*N
    dfs(-1, 0, 0)

    print(*ans)


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

a = int(input())
b = input().split(" ")
i = 0
s = 1
while i < a :
    s = s * int(b[i])
    i = i + 1
if s > (10 ** 18) :
    print("-1")
else:
    print(s)

### FIXED CODE ###

a = int(input())
b = input().split(" ")
i = 0
s = 1
f = 0
while i < a :
    if b[i] == "0" :
        print(0)
        f = f + 1
    i = i + 1
i = 0
while (i < a) and f == 0 :
    s = s * int(b[i])
    i = i + 1
    if s > (10 ** 18):
        print("-1")
        break
    if (s <= 10 ** 18) and (i == a):
        print(s)
### BUGGY CODE ###

n = int(input())
c = 0

for i in range(n+1):
    i2 = list(str(i))
    if i2.count("3") >= 1 and i2.count("5") >= 1 and i2.count("7") >= 1:
        if i2.count("3") + i2.count("5") + i2.count("7") == len(i2):
            c += 1

print(c)

### FIXED CODE ###

import itertools
n=input()
ans=0

for i in range(3,len(n)+1):
    li=itertools.product([3,5,7],repeat=i)
    
    for j in li:
        t=''.join(map(str,j))
        
        if int(t)<=int(n):
            if t.count("3")>=1 and t.count("5")>=1 and t.count("7")>=1:
                ans+=1

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

import time
t1=time.time()
n=int(input())
kind=[0]*n
aa=[]
bb=[]
for _ in range(n-1):
	a,b=map(int,input().split())
	aa.append(a)
	bb.append(b)
	kind[a-1]+=1
	kind[b-1]+=1
print(max(kind))
p=[[set()]for _ in range(n)]
for i in range(n-1):
	t2=time.time()
	if t2-t1<=0.5:
		for j in range(max(kind),0,-1):
			if j not in p[aa[i]-1][0] and j not in p[bb[i]-1][0]:
				p[aa[i]-1][0].add(j)
				p[bb[i]-1][0].add(j)
				print(j)
				break
	else:
		for j in range(1,max(kind)+1):
			if j not in p[aa[i]-1][0] and j not in p[bb[i]-1][0]:
				p[aa[i]-1][0].add(j)
				p[bb[i]-1][0].add(j)
				print(j)
				break




### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**5*2)
n=int(input())
child=[[]for _ in range(n)]
color=[-1]*(n-1)
#adj は(子供,辺番号)
for i in range(n-1):
	a,b=map(int,input().split())
	child[a-1].append((b-1,i))
#x=現在見ている頂点
#r=その頂点の親とその頂点の間のnodeの色
def f(now,parent_node):
	color_num=1
	for i,j in child[now]:
		if color_num==parent_node:
			color_num+=1
		color[j]=color_num 
		f(i,color_num)
		color_num+=1
f(0,0)
print(max(color))
for x in color:
	print(x)
### BUGGY CODE ###

n = int(input())
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
    scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print(" ".join(str(x) for x in scarf_val))

### FIXED CODE ###

n = int(input())
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print(" ".join(str(x) for x in scarf_val))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    cnt = 0
    
    for i in range(len(S[l - 1: r])):
        
        if(S[l - 1: r][i: i + 2] == 'AC'):
            cnt += 1
        
    print(cnt)

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])
### BUGGY CODE ###

n = int(input())
A = tuple(int(input()) for i in range(n))

for i in range(n):
  X = A
  X = list(X)
  X.pop(i)
  print(max(X))

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
B = list(set(A))
B.sort()
B.reverse()
if len(B) == 1 or A.count(B[0])>= 2:
  for i in range(N):
    print(B[0])
else:
  for i in range(N):
    if A[i] == B[0]:
      print(B[1])
    else:
      print(B[0])
### BUGGY CODE ###

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

S_=[]
for s in range(len(S)):
    s_temp=S[s]
    S_.append(s_temp)
    for e in range(s+1,len(S)):
        s_temp+=S[e]
        S_.append(s_temp)
        
S_=list(set(S_))
S_.sort()
# print(S_)
print(S_[K-1])

### FIXED CODE ###

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

S_=[]
for s in range(len(S)):
    s_temp=S[s]
    S_.append(s_temp)
    for e in range(s+1,len(S)):
        if e-s>K+10:
          break
        s_temp+=S[e]
        S_.append(s_temp)
        
S_=list(set(S_))
S_.sort()
# print(S_)
print(S_[K-1])
### BUGGY CODE ###

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

l = []
amount = 0
count = 1
for i in range(N):
    for j in range(N - 1):
        if count < j:
            break
        elif numbers[j] == i+1:
            amount = amount + 1
        count = count + 1
    count = 1 
    print(amount)
    amount = 0

### FIXED CODE ###

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

result = [0] * N
for i in numbers:
    result[i- 1] += 1
    
for i in range(N-1):
    print(result[i])
print(0)
### BUGGY CODE ###

X = int(input())
P = {0}
i=1
while True:
    Q = {0}
    for p in P:
        Q.add(p+i)
        Q.add(p-i)
    P = P.union(Q)
    if X in P:
        print(i)
        break
    i = i+1

### FIXED CODE ###

X = int(input())
a = 0
while X >0:
    a += 1
    X -= a
print (a)
### BUGGY CODE ###

import itertools

n = int(input())
L = list(map(int, input().split()))
cnt = 0

ls = list(itertools.combinations(L, 3))

for l in ls:
    if l[0] < l[1]+l[2] and l[1] < l[2] + l[0] and l[2] < l[0] + l[1]:
        cnt += 1

print(cnt)


### FIXED CODE ###

import bisect
import sys

input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0

for i in range(0, n-2):
    for j in range(i+1, n-1):
        cnt += bisect.bisect_left(l, l[i] + l[j]) - j-1

print(cnt)
### BUGGY CODE ###

a,b = map(int,input().split())
ans = 0
if a > b:
  for x in range(b+1):
    for y in range(b-x+1):
      for z in range(b-x-y+1):
        if (x+y+z)==b:
          ans += 1
else:
  for x in range(a+1):
    for y in range(a+1):
      for z in range(a+1):
        if (x+y+z)==b:
          ans += 1
        if (x+y+z)>=b:
          continue
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
ans = 0

for x in range(b+1):
  if x > a:
    break
  for y in range(b+1):
    if y > a:
      break
    z = b-x-y
    if z <= a and z >= 0:
      ans +=1
    else:
      continue  
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, S: str):
    d = []  # type: List[int]
    i = 0
    while True:
        r = 0
        while i < N and S[i] == "1":
            r += 1
            i += 1
        d.append(r)
        if i >= N:
            break
        s = 0
        while i < N and S[i] == "0":
            s += 1
            i += 1
        d.append(s)
    c = 2 * K + 1
    if c > len(d):
        print(sum(d))
        return
    print(max(sum(d[dl:dl + c]) for dl in range(0, len(d) - c + 1, 2)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, S: str):
    d = []  # type: List[int]
    i = 0
    while True:
        r = 0
        while i < N and S[i] == "1":
            r += 1
            i += 1
        d.append(r)
        if i >= N:
            break
        s = 0
        while i < N and S[i] == "0":
            s += 1
            i += 1
        d.append(s)
    c = 2 * K + 1
    if c > len(d):
        print(sum(d))
        return
    dl = 0
    acc = sum(d[:c])
    ans = acc
    while dl + c + 2 <= len(d):
        acc += d[dl + c] + d[dl + c + 1] - d[dl] - d[dl + 1]
        ans = max(ans, acc)
        dl += 2
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)


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

N,W = map(int, input().split())
nupList = (map(int, input().split()) for _ in range(N))
dp = [0] * (W + 1)

for w, v in nupList:
    for j in range(W, w - 1, -1 ):
        DP = dp[j - w] + v
        if dp[j] < DP:
            dp[j] = DP

print(dp[W])

### FIXED CODE ###

def DP():
    n,W = map(int, input().split(' '))
    WV = (map(int, input().split(' ')) for _ in range(n))
    dp = [0] * (W+1)
 
    for w, v in WV:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(DP())
### BUGGY CODE ###

from collections import defaultdict
N, P = map(int,input().split())
S = input()

if P==5:
    ans = 0
    for i,m in enumerate(S):
        if m == '5' or m == '0':
            ans += i+1
elif P==2:
    ans = 0
    for i,m in enumerate(S):
        if int(m) % 2 ==0:
            ans += i+1
else:
    S = int(S)
    primdic = defaultdict(int)
    for i in range(1,N+1):
        # i~右端までの数字のmodPをキーにする
        primdic[(S%(10**i))%P] += 1
    # 文字なしの時はあまり0なので
    primdic[0] += 1
    ans = 0
    for value in primdic.values():
        ans += value*(value-1)//2
print(ans)

### FIXED CODE ###

from collections import defaultdict
N, P = map(int,input().split())
S = input()

if P==5:
    ans = 0
    for i,m in enumerate(S):
        if m == '5' or m == '0':
            ans += i+1
elif P==2:
    ans = 0
    for i,m in enumerate(S):
        if int(m) % 2 ==0:
            ans += i+1
else:
    S = S[::-1]
    primdic = defaultdict(int)
    before = 0
    for i in range(0,N):
        now = (int(S[i])*pow(10,i,P)+before)%P
        primdic[now] += 1
        before = now
    # 文字なしの時はあまり0なので
    primdic[0] += 1
    ans = 0
    for value in primdic.values():
        ans += value*(value-1)//2
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

good_ob = []
for i in range(N):
    good_ob.append(i+1)

for i in range(M):
    if H[road[i][0]-1] > H[road[i][1]-1]:
        if road[i][1] in good_ob:
            good_ob.remove(road[i][1])
    elif H[road[i][0]-1] < H[road[i][1]-1]:
        if road[i][0] in good_ob:
            good_ob.remove(road[i][0])
    else:
        if road[i][1] in good_ob:
            good_ob.remove(road[i][1])
        if road[i][0] in good_ob:
            good_ob.remove(road[i][0])


print(len(good_ob))


### FIXED CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

bad_ob = []

for i in range(M):
    if H[road[i][0]-1] > H[road[i][1]-1]:
        bad_ob.append(road[i][1]-1)
    elif H[road[i][0]-1] < H[road[i][1]-1]:
        bad_ob.append(road[i][0]-1)
    else:
        bad_ob.append(road[i][0]-1)
        bad_ob.append(road[i][1]-1)


print(N-len(set(bad_ob)))
### BUGGY CODE ###


N, M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
LR=[[int(i) for i in input().split()] for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

ret = set(range(LR[0][0], LR[0][1]+1))

for i in LR[1:]:
    ret = set(range(i[0], i[1]+1)) & ret

print(len(ret))
    

### FIXED CODE ###


N, M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
LR=[[int(i) for i in input().split()] for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

mi, ma = 0, 10**5

for i in LR:
    mi = max(mi, i[0])
    ma = min(ma, i[1])

if ma-mi < 0:
    print(0)
else:
    print(ma-mi + 1)
### BUGGY CODE ###

import numpy as np
import sys

buf = sys.stdin.buffer
R,C = map(int,buf.readline().split())
# \nが含まれるから列要素の数が+1
black = (np.frombuffer(buf.read(R*(C+1)),dtype='S1') == b'#')
sharps = np.where(black==True)[0]

coord_x = np.array([[j for i in range(C)] for j in range(R)])
coord_y = np.array([[i for i in range(C)] for j in range(R)])

sharps = sharps[sharps%(C+1)!=C]
for i,one in enumerate(sharps):
    one_sharp_x = one//(C+1)
    one_sharp_y = one%(C+1)
    if i == 0:
        result_np = abs(coord_x-one_sharp_x) + abs(coord_y-one_sharp_y)
    else:
        result_np = np.minimum(result_np,abs(coord_x-one_sharp_x) + abs(coord_y-one_sharp_y))

print(max(result_np.flatten()))

### FIXED CODE ###

import numpy as np
import sys
# https://atcoder.jp/contests/agc033/submissions/6021787
buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())
# +1周分だけ
black = np.zeros((H+2,W+2),dtype=np.bool)
# \nがあることに注意
black[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'#').reshape(H,W+1)

INF = 10 ** 4
dist = np.zeros((H,W),dtype=np.int16)
# .のところは０それ以外はINFで初期化
dist[~black[1:-1,1:-1]] = INF
# 右、左、下、上と展開させていく感じ
for n in range(1,H):
    np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(H-2,-1,-1):
    np.minimum(dist[n+1]+1,dist[n],out=dist[n])
for n in range(1,W):
    np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(W-2,-1,-1):
    np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

print(dist.max())