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

from sys import stdin
from collections import deque

H, W = [int(x) for x in stdin.readline().rstrip().split()]
maze = [stdin.readline().rstrip().split()[0] for _ in range(H)]

d = [[0] * W for _ in range(H)]
ans = 0

for h in range(H):
    for w in range(W):
        q = deque([(h, w, 0)])
        if maze[h][w] == '#':
            continue
        else:
            temp_h = h
            temp_w = w
            visited = [[0] * W for _ in range(H)]
            while len(q) > 0:
                temp = q.popleft()
                temp_h = temp[0]
                temp_w = temp[1]
                temp_d = temp[2]
                ans = max(ans, temp_d)
                visited[temp_h][temp_w] = 1
                if temp_h + 1 < H and maze[temp_h + 1][temp_w] == '.' and visited[temp_h + 1][temp_w] == 0:
                    q.append((temp_h + 1, temp_w, temp_d + 1))
                if temp_h - 1 >= 0 and maze[temp_h - 1][temp_w] == '.' and visited[temp_h - 1][temp_w] == 0:
                    q.append((temp_h - 1, temp_w, temp_d + 1))
                if temp_w + 1 < W and maze[temp_h][temp_w + 1] == '.' and visited[temp_h][temp_w + 1] == 0:
                    q.append((temp_h, temp_w + 1, temp_d + 1))
                if temp_w - 1 >= 0 and maze[temp_h][temp_w - 1] == '.' and visited[temp_h][temp_w - 1] == 0:
                    q.append((temp_h, temp_w - 1, temp_d + 1))

print(ans)


### FIXED CODE ###

from sys import stdin
import queue

H, W = [int(x) for x in stdin.readline().rstrip().split()]
maze = [stdin.readline().rstrip().split()[0] for _ in range(H)]

ans = 0

for h in range(H):
    for w in range(W):
        if maze[h][w] == '#':
            continue
        else:
            q = queue.Queue()
            q.put((h, w))
            visited = [[-1] * W for _ in range(H)]
            visited[h][w] = 0
            while q.qsize() > 0:
                temp = q.get()
                temp_h = temp[0]
                temp_w = temp[1]
                ans = max(ans, visited[temp_h][temp_w])
                if temp_h + 1 < H and maze[temp_h + 1][temp_w] == '.' and visited[temp_h + 1][temp_w] < 0:
                    visited[temp_h + 1][temp_w] = visited[temp_h][temp_w] + 1
                    q.put((temp_h + 1, temp_w))
                if temp_h - 1 >= 0 and maze[temp_h - 1][temp_w] == '.' and visited[temp_h - 1][temp_w] < 0:
                    visited[temp_h - 1][temp_w] = visited[temp_h][temp_w] + 1
                    q.put((temp_h - 1, temp_w))
                if temp_w + 1 < W and maze[temp_h][temp_w + 1] == '.' and visited[temp_h][temp_w + 1] < 0:
                    visited[temp_h][temp_w + 1] = visited[temp_h][temp_w] + 1
                    q.put((temp_h, temp_w + 1))
                if temp_w - 1 >= 0 and maze[temp_h][temp_w - 1] == '.' and visited[temp_h][temp_w - 1] < 0:
                    visited[temp_h][temp_w - 1] = visited[temp_h][temp_w] + 1
                    q.put((temp_h, temp_w - 1))

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

N = int(input())
nu = [int(x) for x in input().split()]
ans = ["a" for x in range(len(nu))]
                          
for i, v in enumerate(nu):
  #print("i=", i)
  #print("v=", v)
  ans[v-1] = i+1
#print(ans)

answ = ""
for i in ans:
  answ = answ + str(i) + " "
print(answ)

### FIXED CODE ###

n1 = int(input())
l1 = [int(x) for x in input().split()]
l2 = [""] * n1

for i, v in enumerate(l1):
  l2[v -1] = i + 1

l2 = map(str,l2)
ans = " ".join(l2)
print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
for k in range(q):
  j = [int(_) for _ in input().split()]
  i = s[j[0]-1:j[1]]
  print(i.count('AC'))


### FIXED CODE ###

n,q = map(int,input().split())
s = input()
lr = [[int(i) for i in input().split()]for _ in range(q)]
dp = [0]*n
f,c = 0,0
for i,j in enumerate(s):
  if f==1 and j=='C':
    c+=1
    f =0
  elif j=='A':
    f = 1
  else:
    f = 0
  dp[i]=c
for i in lr:
  print(dp[i[1]-1]-dp[i[0]-1])
### BUGGY CODE ###

def get_cost_change_black(S):
    return S.count(".")

N = int(input())
S = str(input())

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000
    change_white = 0
    for i in indexs:
        x = change_white + get_cost_change_black(S[i:])
        if x < answer:
            answer = x
        change_white = change_white + 1
    print(answer)


### FIXED CODE ###

def get_cost_change_black(S):
    return S.count(".")

N = int(input())
S = str(input())

indexs = [i for i, x in enumerate(S) if x == "#"]
if len(indexs) == 0:
    print(0)
else:
    answer = 10000000000
    change_white = 0
    change_black = get_cost_change_black(S[indexs[0]:])
    for i, ind in enumerate(indexs):
        x = change_white + change_black
        if x < answer:
            answer = x
        change_white = change_white + 1
        if i == len(indexs) - 1:
            if change_white < answer:
                answer = change_white
            break
        change_black = change_black - (indexs[i+1] - indexs[i] - 1)
    print(answer)
### BUGGY CODE ###

import math

INF = float("inf")

V, E = map(int, input().split())
edge = []

for _ in range(E):
    a, b, c = map(int, input().split())
    edge.append([a, b, -c])

d = [INF] * (V + 1)
d[1] = 0

for _ in range(V-1):
    update = False
    for e in edge:
        if not math.isinf(d[e[0]]) and d[e[1]] > d[e[0]] + e[2]:
            update = True
            d[e[1]] = d[e[0]] + e[2]
    if not update:
        break

negative = [False] * (V + 1)

for _ in range(V):
    for e in edge:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            negative[e[1]] = True
            d[e[1]] = d[e[0]] + e[2]
        elif negative[e[1]]:
            d[e[1]] = True
print(-d[V] if not negative[V] else "inf")


### FIXED CODE ###

import math

INF = float("inf")

V, E = map(int, input().split())
es = []

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

d = [INF] * V
d[0] = 0
cnt = [0] * V

for _ in range(V):
    updated = False
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
            cnt[e[1]] += 1
            updated = True
    if not updated:
        break

print(-d[V-1] if cnt[V-1] < V else "inf")
### BUGGY CODE ###

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

res = 1
for i in range(n):
    res *= a[i]
    if res == 0:
        break

if res > 10**18:
    res = -1

print(res)

### FIXED CODE ###

n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
ans = 1
flg = False

for i in range(n):
    if a[i] == 0:
        ans = 0
        break
if ans == 0 :
    print(ans)
else:
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            flg = True
            break
    if flg:
        print(-1)
    else:
        print(ans)
### BUGGY CODE ###


import sys
sys.setrecursionlimit(10**9)

def dfs(i):
    if distance[i] != -1:
        return distance[i]
    ans = 0
    for node in graph[i]:
        ans = max(ans, dfs(node) + 1)
    return ans

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

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

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))

print(ans)

### FIXED CODE ###


import sys
sys.setrecursionlimit(10**9)

def dfs(i):
    if distance[i] != -1:
        return distance[i]
    ans = 0
    for node in graph[i]:
        ans = max(ans, dfs(node) + 1)
    distance[i] = ans
    return ans

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

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

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))

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

from collections import deque
n, m = map(int, input().split())
q = deque()
keys = [0] * n
dic = {i: [] for i in range(n)}
for _ in range(m):
    a, b = map(int, input().split())
    dic[a - 1].append(b - 1)
    dic[b - 1].append(a - 1)

for i in dic[0]:
    q.append(i)
    keys[i] = 1
while len(q) > 0:
    next = q.popleft()
    for i in dic[next]:
        if i == 0 or keys[i]:
            continue
        if i not in q:
            q.append(i)
            keys[i] = next + 1
print('Yes')
print(*keys[1:], sep='\n')

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
q = deque()
t = {i: set() for i in range(1, n + 1)}
v = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())
    t[a].add(b)
    t[b].add(a)
q.append(1)
v[0] = 1
while q:
    next = q.popleft()
    for i in t[next]:
        if v[i - 1] == -1:
            q.append(i)
            v[i - 1] = next
print('Yes')
print(*v[1:], sep='\n')
### BUGGY CODE ###

import numpy as np
import math

global csA

def getsumanddiff(i, j, k):
    p = csA[j+1] - csA[i]
    q = csA[k+1] - csA[j+1]
    return p, q, abs(p - q)

def getfinaldiff(p, q, r, s):
    return max(p, q, r, s) - min(p, q, r, s)

N = int(input())
A = np.array(list(map(int, input().split())))
csA = np.concatenate([[0], np.cumsum(A)]) # Cumulative sum

# init
mid0 = 0
mid2 = 2

p, q, r, s = [0]*4
diff = 2 ** 63

for mid1 in range(1, N - 2):
    diff0 = 2 ** 63
    diff2 = 2 ** 63

    # mid0 search
    for i in range(mid0, mid1):
        tmpp, tmpq, tmpdiff0 = getsumanddiff(0, i, mid1)
        if diff0 > tmpdiff0:
            mid0 = i
            diff0 = tmpdiff0
            p = tmpp
            q = tmpq
        else:
            break

    # mid2 search
    for i in range(mid2, N - 1):
        if mid1 >= i:
            continue
        tmpr, tmps, tmpdiff2 = getsumanddiff(mid1+1, i, N - 1)
        if diff2 > tmpdiff2:
            mid2 = i
            diff2 = tmpdiff2
            r = tmpr
            s = tmps
        else:
            break

    tmpdiff = getfinaldiff(p, q, r, s)
    if diff > tmpdiff:
        diff = tmpdiff

print(diff)


### FIXED CODE ###

import numpy as np
import math

global csA
MAXINT = 2 ** 63 - 1

def getsumanddiff(i, j, k):
    tmp = csA[j+1]
    p = tmp - csA[i]
    q = csA[k+1] - tmp
    return p, q, abs(p - q)

N = int(input())
# A = np.array(list(map(int, input().split())))
# csA = np.cumsum(A)

csA = [0] * (N+1)
for i, v in enumerate(input().split()):
    csA[i+1] = csA[i] + int(v)

# init
mid0 = 0
mid2 = 2

p, q, r, s = [0]*4
diff = MAXINT

csAN = csA[N]
for mid1 in range(1, N - 2):
    diff0 = MAXINT
    diff2 = MAXINT
    csAmid1 = csA[mid1+1]

    # mid0 search
    for i in range(mid0, mid1):
        # tmpp, tmpq, tmpdiff0 = getsumanddiff(0, i, mid1)
        tmpp = csA[i+1]
        tmpq = csAmid1 - tmpp
        tmpdiff0 = abs(tmpp - tmpq)
        if diff0 > tmpdiff0:
            mid0 = i
            diff0 = tmpdiff0
            p = tmpp
            q = tmpq
        else:
            break

    # mid2 search
    start = mid1 if mid2 < mid1 else mid2
    for i in range(start, N - 1):
        # tmpr, tmps, tmpdiff2 = getsumanddiff(mid1+1, i, N - 1)
        csAi = csA[i+1]
        tmpr = csAi - csAmid1
        tmps = csAN - csAi
        tmpdiff2 = abs(tmpr - tmps)
        if diff2 > tmpdiff2:
            mid2 = i
            diff2 = tmpdiff2
            r = tmpr
            s = tmps
        else:
            break

    tmpdiff = max(p, q, r, s) - min(p, q, r, s)
    if diff > tmpdiff:
        diff = tmpdiff

print(diff)
### BUGGY CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
flag = 0
if N == 1:
    flag = -1
M = len(factorization(N))
num = [1,3,6,10,15,21,28,36]
ans = 0
for i in range(M):
    for j in range(len(num)):
        if num[j] <= factorization(N)[i][1]:
            ans += 1

if flag == -1:
    print(0) 
else:
    print(ans)

### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
flag = 0
if N == 1:
    flag = -1
M = len(factorization(N))
num = [1,3,6,10,15,21,28,36]
ans = 0
for i in range(M):
    for j in range(len(num)):
        if num[j] <= factorization(N)[i][1]:
            ans += 1
        else:
            break

if flag == -1:
    print(0) 
else:
    print(ans)
### BUGGY CODE ###

L, R = map(int,input().split())
tmp = 2020
for i in range(L, R):
    for j in range(i + 1, R + 1):
        modmin = i * j % 2019 
        if tmp > modmin:
            tmp = modmin
print(tmp)

### FIXED CODE ###

L, R = map(int,input().split())
tmp = 2020
if R // 2019 != L // 2019 or R % 2019 == 0 or L % 2019 == 0:
    print('0')
else:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            modmin = i * j % 2019 
            if tmp > modmin:
                tmp = modmin
    print(tmp)
### BUGGY CODE ###

n = int(input())
a=list(map(int,input().split()))
a.sort()
dp = [True]*(a[n-1]+1)
for val in set(a):
    temp=2
    while val*temp<=a[n-1]:
        dp[val*temp]=False
        temp+=1
ans = 0
for val in a:
    if dp[val] and a.count(val)==1:
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
dp=[True]*a[-1]
def hantei(i):
    ans = True
    if i!=n-1:
        if a[i]==a[i+1]: ans = False
    if i!=0:
        if a[i]==a[i-1]: ans=False
    return ans
for val in set(a):
    for i in range(2*val,a[-1]+1,val): dp[i-1]=False
ans=0
for i in range(n):
    if dp[a[i]-1] and hantei(i)==1: ans+=1
print(ans)
### BUGGY CODE ###

#sys.stdin.readline()
import sys
input = sys.stdin.readline

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

for i in range(M):
  p,y = map(int,input().split())
  P[i] = p-1
  Y[i] = y
  P_Y[p-1].append(y)
  
for i in range(N):
 P_Y[i].sort()

for i in range(M):
  ID1 = "{0:06d}".format(P[i]+1)
  tmp = P_Y[P[i]].index(Y[i])
  ID2 = "{0:06d}".format(tmp + 1)
  print(ID1 + ID2)

### FIXED CODE ###

N, M = map(int, input().split())
P_Y = []
for i in range(M):
   p,y = map(int,input().split())
   P_Y.append([p-1,y,i])
#n次元リストのソート
#普通にsort()をつけると1番目の要素でソート
#1番目の要素が同じ場合は2番目の要素の大小によってソートされる
P_Y.sort() 

ans_P_Y = [] 
count = 1
for i in range(M):
  if(i != 0):
    if(P_Y[i-1][0] == P_Y[i][0]): count += 1
    else: count = 1
  ans_P_Y.append([P_Y[i][2],P_Y[i][0]+1,count])
ans_P_Y.sort()

for i in range(M):
  ans = str(ans_P_Y[i][1]).zfill(6) + str(ans_P_Y[i][2]).zfill(6)
  print(ans)
### BUGGY CODE ###

N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0
for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    b = a +1
    while b <= current_min:
        c_idx = current_min
        bc = Ln[b] + Ln[c_idx]
        if a_l < bc:
            count += (current_min - b)
            b += 1
            current_min = N-1
            continue
        current_min -= 1
    '''
    for b in range(a+1, N):
        if b >= current_min:
            break
        for c in range(b+1,N):
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                break
            current_min -= 1
    '''
print(count)

### FIXED CODE ###

N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0
for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    b = a +1
    while b <= current_min:
        c_idx = current_min
        bc = Ln[b] + Ln[c_idx]
        if a_l < bc:
            count += (current_min - b)
            b += 1
            continue
        current_min -= 1
    '''
    for b in range(a+1, N):
        if b >= current_min:
            break
        for c in range(b+1,N):
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                break
            current_min -= 1
    '''
print(count)
### BUGGY CODE ###

N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

### FIXED CODE ###

N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)
### BUGGY CODE ###

inp = [int(i) for i in input().split()]
n = inp[0]
a = inp[1]
b = inp[2]

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**9
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

A = cmb(n,a,mod)
B = cmb(n,b,mod)
ans = 2**n-1-A-B
print(ans%(10**9+7))

### FIXED CODE ###

import math
n,a,b = [int(i) for i in input().split()]
mod = 10**9+7
  
def comb(n,k):
  ans = 1
  for i in range(k):
    ans = ans*(n-i)%mod
  for i in range(1,k+1):
    ans = ans*pow(i,mod-2,mod)%mod
  return ans

print((pow(2,n,mod)-1-comb(n,a)-comb(n,b))%mod)
# print(comb(n,a))
### BUGGY CODE ###

def main():
    S = input()
    N = len(S)
    ans = 0
    m = 2019
    for i in range(N):
        for j in range(i+1,N+1):
            num = int(S[i:j])
            if num%2019 == 0:
#                print(i,j)                                                                                                                                                            
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin
input = stdin.readline

def main():
    S = list(input())
    S.pop()
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += pow(10, i, m)*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

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

import random
import time
import copy
start=time.time()
d=int(input())
c=list(map(int, input().split()))
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
s=[]
solution=[]
last=[0]*26
sco=0
for i in range(d):
  s.append(list(map(int, input().split())))
for day in range(1,d+1):
  man=[]
  for i in range(26):
    man.append(s[day-1][i]+last[i]*c[i])
  con=man.index(max(man))
  sco+=s[day-1][con]
  last[con]=day
  for (i,j) in zip(last,range(26)):
    sco-=cli[i][j]
  solution.append(con)
#print(sco)
while time.time()-start<8:
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(3)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[i][j]
  if sc>sco:
    solution=copy.deepcopy(sol)
    sco=sc
for i in solution:
  print(i+1)
#print(sco)

### FIXED CODE ###

d=int(input())
c=list(map(int, input().split()))
s=[]
for i in range(d):
  s.append(list(map(int, input().split())))
for i in s:
  print(i.index(max(i))+1)
### BUGGY CODE ###

nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
s = input()
ac = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac.append(i)
for i in range(q):
    lr = list(map(int, input().split()))
    l = lr[0]
    r = lr[1]
    ans = 0
    for j in ac:
        if l - 1 <= j < r - 1:
            ans += 1
        elif j >= r - 1:
            break
    print(ans)


### FIXED CODE ###

nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
s = input()
ac_list = []
ac_number = 0
for i in range(n - 1):
    if s[i : i+2] == "AC":
        ac_number += 1
    ac_list.append(ac_number)
ac_list.append(0)
for i in range(q):
    lr = list(map(int, input().split()))
    l = lr[0]
    r = lr[1]
    print(ac_list[r - 2] - ac_list[l - 2])
### BUGGY CODE ###

# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(M)]

lst2 = [[] for i in range(N)]

for j in range(M):
    for i in range(N):
        if i+1 in lst[j]:
            if lst[j][0] == i+1:
                lst2[i].append(H[lst[j][1]-1])
            else:
                lst2[i].append(H[lst[j][0]-1])

num = N
for i in range(N):

    if len(lst2[i]) == 0:
        continue

    if H[i] <= max(lst2[i]):
        num -= 1

print(num)


### FIXED CODE ###

# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))

lst = [1 for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] <= H[B-1]:
        lst[A-1] = 0
    if H[B-1] <= H[A-1]:
        lst[B-1] = 0

print(sum(lst))
### BUGGY CODE ###

import math

def perm(n, r):
    return math.factorial(n) // math.factorial(n - r)

def comb(n, r):
    return perm(n, r) // math.factorial(r)


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

A = [int(input()) for _ in range(m)]
for i in range(m - 1):
    if A[i + 1] - A[i] == 1:
        ans = 0
        print(ans)
        exit()

S = []
for a in A:
    S.extend((a - 1, a, a + 1))
S.insert(0, 0)
S.append(n)

ans = 1
for i in range(len(S) - 1):
    r = S[i + 1] - S[i]
    if r > 1:
        c = 0
        t_max = r // 2
        for t in range(t_max + 1):
            c += comb(r - t, t)
        ans *= c

ans %= 10**9 + 7
print(ans)


### FIXED CODE ###

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

S = [1] * (n + 1)
for _ in range(m):
    a = int(input())
    S[a] = 0

i = -3
for _ in range(n - 1):
    if S[i] != 0:
        S[i] = S[i + 1] + S[i + 2]
    i -= 1

ans = S[0] % (10**9 + 7)
print(ans)
### BUGGY CODE ###

import itertools

def main():
    n, m = map(int, input().split())

    x = sorted(list(map(int, input().split())))
    y = sorted(list(map(int, input().split())))

    s = 0
    # x_len = 0
    # y_len = 0

    for e1 in itertools.combinations(x, 2):
        for e2 in itertools.combinations(y, 2):
            x_len = e1[0] - e1[1]
            y_len = e2[0] - e2[1]
            s += x_len * y_len

    print(s % (10 ** 9 + 7))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import itertools


def main():
    n, m = map(int, input().split())

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

    x_len = 0
    y_len = 0

    for i in range(n):
        x_len += (2 * i - n + 1) * x[i] % (10 ** 9 + 7)
        # print(x_len)

    for j in range(m):
        y_len += (2 * j - m + 1) * y[j] % (10 ** 9 + 7)
        # print(y_len)

    print(x_len * y_len % (10 ** 9 + 7))


if __name__ == '__main__':
    main()