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

import sys
sys.setrecursionlimit(1000000)

n,m = map(int,input().split())
# 差が0だと通れない
tmp=10000000
a_list=[]
for i in range(m):
    a=int(input())
    a_list.append(a)
    if abs(tmp-a)==1:
        print(0)
        exit()
    tmp=a

def count(now,s,e):
    if now > e:
        return 0
    if now == e:
        return 1
    cnt=0
    cnt+=count(now+1,s,e)
    cnt+=count(now+2,s,e)
    return cnt


c_mod=1000000007
start=0
end=0
ans=1
for a in a_list:
    # 各部分の移動方法
    end=a-1
    ans=ans*count(start,start,end)%c_mod
    start=a+1
if end<n:
    end=n
    ans=ans*count(start,start,end)%c_mod
print(ans)


### FIXED CODE ###

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

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

if step[0]!=-1:
    step[0]=1
if step[1]!=-1:
    step[1]=1
for i in range(n-1):
    if step[i]==-1:
        continue
    if step[i+1]!=-1:
        step[i+1]+=step[i]
    if step[i+2]!=-1:
        step[i+2]+=step[i]
print(step[n-1]%c_mod)
### BUGGY CODE ###


N = int(input())
I = input()

R = []
G = []
B = []
for i in range(N):
    if I[i] == 'R':
        R.append(i)
    if I[i] == 'G':
        G.append(i)
    if I[i] == 'B':
        B.append(i)

ans = len(R) * len(G) * len(B)

for a in R:
    for b in G:
        for c in B:
            abs1 = abs(a - b)
            abs2 = abs(b - c)
            abs3 = abs(c - a)
            
            if( abs1 == abs2 or abs2 == abs3 or abs3 == abs1 ):
                ans -= 1

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

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

import numpy as np
import sys

input = sys.stdin.readline

N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
select_num = np.array([0]*(maxim+1))
select_num2 = np.array([0]*(maxim+1))
count_num = np.array([0]*(maxim+1))


for i in range(1,maxim+1):
  temp = np.count_nonzero(A == i)
  count_num[i] = temp
  if(temp > 1):
    select_num[i] = (temp)*(temp - 1)//2
    select_num2[i] = temp - 1
sumS = np.sum(select_num)
ans1,ans2 = sumS,select_num2
for i in A:
  print(ans1 -ans2[i])

### FIXED CODE ###

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

select_num = 0
count_num = [0]*(N+1)
for i in A:
  count_num[i] += 1
for i in range(1,N+1):
  select_num += (count_num[i])*(count_num[i] - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)
### BUGGY CODE ###

def calcdp(i,j):
    global dp, A, BIG_INT
    
    if dp[i][j] != -1:
        return dp[i][j]
    
    if i + 1== j:
        dp[i][j] = 0
        return dp[i][j]
    
    elif i + 2== j:
        dp[i][j] = A[i] + A[i + 1]
        return dp[i][j]
    
    else:
        m = BIG_INT
        for k in range(i + 1, j):
            m = min(calcdp(i, k) + calcdp(k, j), m)
        m += sum(A[i:j])
        dp[i][j] = m
        return dp[i][j]

    
BIG_INT = 10**12
N = int(input())
A = [int(x) for x in input().split()]
dp = [[-1] * (N + 1) for _ in range(N)] 

print(calcdp(0, N))

### FIXED CODE ###

def calcdp(i,j):
    global dp, A, BIG_INT
    
    if dp[i][j] != -1:
        return dp[i][j]
    
    if i + 1== j:
        dp[i][j] = 0
        return dp[i][j]
    
    elif i + 2== j:
        dp[i][j] = A[i] + A[i + 1]
        return dp[i][j]
    
    else:
        m = BIG_INT
        for k in range(i + 1, j):
            m = min(calcdp(i, k) + calcdp(k, j), m)
        m += sum(A[i:j])
        dp[i][j] = m
        return dp[i][j]

    
BIG_INT = 10**30
N = int(input())
A = [int(x) for x in input().split()]
dp = [[-1] * (N + 1) for _ in range(N)] 

print(calcdp(0, N))
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1
print(count)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if s - k <= x + y <= s:
            count += 1
print(count)
### BUGGY CODE ###

from collections import Counter
N = int(input())
T = tuple(map(int, input().split()))
C = Counter(T)
C = C.most_common()
for t in T:
  ans = 0
  for c in C:
    if c[1] == 1:
      break
    if c[0] == t:
      ans += ((c[1] - 1) * (c[1] - 2)) // 2
    else:
      ans += (c[1] * (c[1] - 1)) // 2
  print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
T = tuple(map(int, input().split()))
C = Counter(T)
d = dict()
sum = 0
for c in C.most_common():
  if c[1] == 0:
    break
  if d.get(c[1]):
    sum += d[c[1]]
  else:
    x = (c[1] * (c[1] - 1)) // 2
    d[c[1]] = x
    sum += x
for t in T:
  x = C[t]
  if x >= 2:
    if d.get(x):
      minus = d[x]
    else:
      minus = (x * (x - 1)) // 2
      d[x] = minus
    if d.get(x-1):
      plus = d[x - 1]
    else:
      plus = ((x - 1) * (x - 2)) // 2
      d[x - 1] = plus
    print(sum - minus + plus)
  else:
    print(sum)
### BUGGY CODE ###

from operator import itemgetter
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key = itemgetter(1), reverse=True)

ans = 0
for i in range(n):
    now = a[i]
    for rep, con in enumerate(bc):
        if now < con[1] and bc[rep][0] != 0:
            ans += con[1]
            bc[rep][0] -= 1
            break

    else: ans += now

print(ans)

### FIXED CODE ###

from collections import Counter

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

abc = Counter(a).most_common()
for i in range(m):
    b, c = map(int, input().split())
    abc.append((c, b))

abc.sort(reverse=True)

ans = 0
count = n
for c, b in abc:
    rep = min(count, b)
    ans += c * rep
    count -= rep
print(ans)
### BUGGY CODE ###

n, m = map(int,input().split())
pS = [tuple(input().split()) for _ in range(m)]
pena = 0
correct = 0
d = {}
for p, s in pS:
    if p in d.keys():
        d[p].append(s)
    else:
        d[p] = [s]
for key, values in d.items():
    cnt = 0
    for i in values:
        if i == "WA":
            cnt += 1
        else:
            correct += 1
            pena += cnt
            break
print(correct, pena)

### FIXED CODE ###

n, m = map(int,input().split())
pS = [input().split() for _ in range(m)]
correct = 0
flag = [False] * n
pena = [0] * n
sum = 0
for p, s in pS:
    p = int(p)
    if flag[p-1] == True:
        continue
    else:
        if s == "WA":
            pena[p-1] += 1
        elif s == "AC":
            sum += pena[p-1]
            correct += 1
            flag[p-1] = True
print(correct, sum)
### BUGGY CODE ###

def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    N = 10**9+7
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            ans += a[i]*a[j]
            ans %= N
    print(ans)
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    N = 10**9+7
    s = sum(a) % N
    ans = 0
    for i in a:
        s -= i
        ans += s*i
        ans %= N
    print(ans)
resolve()
### BUGGY CODE ###

def warshall_floyd(d):
  n = len(d)
  for i in range(n):
    for j in range(n):
      for k in range(n):
        d[j][k] = min(d[j][k], d[j][i]+d[k][i])
  
  return d


N, M, L = map(int, input().split())
d = [[float('inf') for _ in range(N)] for _ in range(N)]

for _ in range(M):
  a, b, c = map(int, input().split())
  d[a-1][b-1] = c
  d[b-1][a-1] = c
  
for i in range(N):
  d[i][i] = 0

d = warshall_floyd(d)
d2 = [[1 if d[i][j]<=L else float('inf') for j in range(N)] for i in range(N)]
for i in range(N):
  d2[i][i] = 0

d2 = warshall_floyd(d2)

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  out = d2[s-1][t-1]
  print(-1 if out == float('inf') else int(out-1))

### FIXED CODE ###

from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())

D = np.ones([N, N]) * np.inf
D[np.eye(N, dtype=bool)] = 0

for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = C

D = floyd_warshall(D)
D2 = D <= L

D2 = floyd_warshall(D2)

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1] - 1
  if r < np.inf:
    print(int(r))
  else:
    print(-1)
### BUGGY CODE ###

n, x, y = map(int, input().split())
distance = []
for i in range(1, n):
    for j in range(i+1, n+1):
        distance.append(min([abs(j-i), abs(x-i)+abs(y-j)+1]))

for k in range(1, n):
    print(distance.count(k))

### FIXED CODE ###

n, x, y = map(int, input().split())
distance = [0] * n
for i in range(1, n):
    for j in range(i+1, n+1):
        distance[min([abs(j-i), abs(x-i)+abs(y-j)+1])] += 1

print('\n'.join(map(str, distance[1:])))
### BUGGY CODE ###

s = input()
k = int(input())

cand_list = []
for i in range(len(s)):
    for j in range(0, len(s)+1):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break

print(sorted(list(set(cand_list)))[k-1])

### FIXED CODE ###

s = input()
k = int(input())

cand_list = []
for i in range(len(s)):
    for j in range(len(s)+1-i):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break
        elif len(cand_list) > k:
            cand_list.pop(len(cand_list) - 1)

print(sorted(cand_list)[k-1])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
X = []
for i in range(Q):
    l, r = map(int, input().split())
    X.append(S[l-1:r])

for x in X:
    print(x.count('AC'))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
cumsum = [0] * N

for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        cumsum[i] = cumsum[i - 1] + 1
    else:
        cumsum[i] = cumsum[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    print(cumsum[r-1] - cumsum[l-1])
### BUGGY CODE ###

a,b=map(int,input().split())
i=0
while i <= 1000:

    if a==int(i*0.08) and b==int(i*0.1):
        print(i)
print(-1)

### FIXED CODE ###

import sys
a,b=map(int,input().split())
i=0
while i <= 10000:
    c=int(i*0.08)
    d=int(i*0.1)
    if c==a and d==b:

        print(i)
        sys.exit()
    i+=1

print(-1)
### BUGGY CODE ###

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

ans = [a.index(x)+1 for x in range(1, n+1)]

print(*ans)

### FIXED CODE ###

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

l = [[] for x in range(n)]
for i, num in enumerate(a):
    l[num-1] = (int(i) + 1)

print(*l)
### BUGGY CODE ###

from bisect import bisect_left

N = int(input())
A = [int(input()) for _ in range(N)]

t = [A[0]]
for a in A[1:]:
    i = bisect_left(t, a) - 1
    if i == -1:
        t = [a] + t
    else:
        t[i] = a
print(len(t))


### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

t = [A[0]]
for a in A[1:]:
    if t[-1] >= a:
        t.append(a)
        continue
    ok = len(t) - 1
    ng = -1
    while ok - ng > 1:
        m = (ok + ng) // 2
        if t[m] < a:
            ok = m
        else:
            ng = m
    t[ok] = a
print(len(t))
### BUGGY CODE ###

import sys
 
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = 0
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    extend([c]*b)
 
A.sort()
del A[0:B]
print(sum(A))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

s=input()
n=len(s)

#sのあるindexに、ある操作回数後にいる人の数を格納する配列を準備する。はじめはすべてのマスに1人
state=[[1 for i in range(n)],[1 for i in range(n)]]
#state[移動の前（0）か後（1）か][index]

for t in range(10**5):
	for i in range(n):
		if i==0:
			state[1][i]=(s[i+1]=='L')*state[0][i+1]
		elif i==n-1:
			state[1][i]=(s[i-1]=='R')*state[0][i-1]
		else:
			state[1][i]=(s[i-1]=='R')*state[0][i-1]+(s[i+1]=='L')*state[0][i+1]
	for i in range(n):
		state[0][i]=state[1][i]

for i in range(n):
	print(state[0][i],end=' ')

### FIXED CODE ###

#print('RRRLLRL'.index('LR'))
#print('RRRLLRLR'.index('LR'))
#=>4
#str.index(検索文字列,開始位置,終了位置)

#indexは見つからないとエラー
#findは見つからないと-1を出力

#s='RRLRLR'
#bubun=s[0:3]
#print(bubun)
#=>RRL


def stateRL(s):
	state=[0]*len(s)
	r=s.count('R')
	l=s.count('L')
	state[r-1]=1+(r-1)//2+l//2
	state[r]=1+r//2+(l-1)//2
	return state

s=input()
n=len(s)

state=[]

kireme=-1
nkireme=s.find('LR',0)

while nkireme!=-1:
	bubun=s[kireme+1:nkireme+1:]
	state+=stateRL(bubun)
	kireme=nkireme
	nkireme=s.find('LR',kireme+1)

bubun=s[kireme+1::]
state+=stateRL(bubun)
	
for i in range(n):
	print(state[i],end=' ')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 21:40:34 2019

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
num = 0

for i in range(N):
    A,B = map(int, input().split())
    for j in range(B):
        numlist.append(A)

numlist.sort()


for k in range(M):
    num += numlist[k]
    
print(num)
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 21:40:34 2019

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
money = 0
count = 0
count1 = 0
count2 = 0

for i in range(N):
    AB = list(map(int, input().split()))
    numlist.append(AB)

numlist.sort()

while count < M:
    while numlist[count1][1] > count2:
        money = money + numlist[count1][0]
        count = count + 1
        count2 = count2 + 1
        if count == M:
            break
    count1 = count1 + 1
    count2 = 0
    
print(money)
### BUGGY CODE ###

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

a = b = c = -1

for i in range(0,n+1):
    for j in range(0,n+1):
        x = i
        y = j
        z = n - i - j
        if n >= x >=0 and n >= y >=0 and n >= z >=0:
            sum = 10000*int(x) + 5000*int(y) + 1000*int(z) 
            if total == sum:
                a = x
                b = y
                c = z
                break
            else:
                continue
            break
print(a,b,c)            
        
            

### FIXED CODE ###

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

a = b = c = -1

for i in range(0,n+1):
    x = i
    for j in range(0,n+1-x):
        
        y = j
        z = n - i - j
        if n >= x >=0 and n >= y >=0 and n >= z >=0:
            if total == 10000*int(x) + 5000*int(y) + 1000*int(z):
                a = x
                b = y
                c = z
                break
            else:
                continue
            break
print(a,b,c)
### BUGGY CODE ###

from collections import defaultdict

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

A=defaultdict(list)
Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y])
  A[P].append(Y)
  
for a,b in A.items():
  A[a].sort()

for l in Q:
  s=str(l[0]).zfill(6)
  num=A[l[0]].index(l[1])
  s+=str(num+1).zfill(6)
  print(s)


### FIXED CODE ###

from collections import defaultdict

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

Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y,i])
  
Q = sorted(Q,key=lambda x:x[1])
Q = sorted(Q,key=lambda x:x[0])

nowP=Q[0][0]
nownum=0

for l in Q:
  s=str(l[0]).zfill(6)
  if l[0]==nowP:
    nownum+=1
  else:
    nowP=l[0]
    nownum=1
  s+=str(nownum).zfill(6)
  l.append(s)
  
Q = sorted(Q,key=lambda x:x[2])

for l in Q:
  print(l[3])
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
    _a=a[:]
    _a.pop(i)
    print(max(_a))


### FIXED CODE ###

n=int(input())
t,s=0,0
a=[]
for i in range(n):
    _a=int(input())
    a.append(_a)
    if _a>t:
        t=_a
    elif _a==t or _a>s:
        s=_a
for _a in a:
    if _a==t:
        print(s)
    else:
        print(t)
### BUGGY CODE ###

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

arr = [[0 for j in range(n)] for i in range(n)]
arr_sum = [[0 for j in range(n)] for i in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    arr[l-1][r-1] += 1

for i in range(n):
    for j in range(n):
        if i <= j:
            arr_sum[i][j] = sum(arr[i][:j+1])


ans_arr = []
for k in range(q):
    ans = 0
    p, q = map(int, input().split())
    for i in range(p-1, q):
        ans += arr_sum[i][q-1]
    ans_arr.append(ans)

for i in ans_arr:
    print(i)

### FIXED CODE ###

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

arr = [[0 for j in range(n)] for i in range(n)]
arr_sum = []
arr_sum2 = []

for i in range(m):
    l, r = map(int, input().split())
    arr[l-1][r-1] += 1


for i in range(n):
    s = 0
    arr_tmp = []
    for j in range(n):
            s += arr[i][j]
            arr_tmp.append(s)
    arr_sum.append(arr_tmp)


for j in range(n):
    s = 0
    arr_tmp2 = []
    for i in range(n-1,-1,-1):
            s += arr_sum[i][j]
            arr_tmp2.append(s)
    arr_sum2.append(arr_tmp2)

arr_sum3 = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        arr_sum3[i][j] = arr_sum2[j][n-i-1]

ans_arr = []
for k in range(q):
    p, q = map(int, input().split())
    ans = arr_sum3[p-1][q-1]
    ans_arr.append(ans)

for i in ans_arr:
    print(i)
### BUGGY CODE ###

n=int(input())
s=str(input())
t=len(s)
r=[]
g=[]
b=[]
a=0
for i in range(n):
    if s[i]=='R':
        r.append(i)
    if s[i]=='G':
        g.append(i)
    if s[i]=='B':
        b.append(i)
for ri in r:
    for gi in g:
        for bi in b:
            if 2*ri==gi+bi or 2*gi==ri+bi or 2*bi==gi+ri:
                a+=1
d=len(r)*len(g)*len(b)
d=d-a
print(d)

### FIXED CODE ###

n=int(input())
s=str(input())
t=len(s)
r=set()
g=set()
b=set()
a=0
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
d=len(r)*len(g)*len(b)
for ri in r:
    for gi in g:
        rg=gi-ri
        if rg+gi in b:
            d-=1
        if  ri-rg in b:
            d-=1
        if (gi+ri)/2 in b:
            d-=1

print(d)
### BUGGY CODE ###

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

sum = 0
mod = 1000000000+7
for i in range(n-1):
    for j in range(i+1, n):
        sum = sum + a[i] * a[j]
        #print(sum)
        if sum >= mod:
            #print('no')
            sum = sum % mod
            #print(sum)
            #print('o')
print(sum)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
sum = 0
sum1 = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
    sum1 += a[i]
    sum1 %= mod
    
for i in range(n-1):
    #for j in range(i+1, n):
    sum1 -= a[i]
    #sum += a[i] * a[j]
    if sum1 < 0:
        sum1 += mod
    sum += a[i] * sum1
    sum %= mod
            
print(sum)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ai = max(A)
aj1 = ai // 2
aj2 = aj1 + (ai % 2)
while True:
    if aj1 in A:
        print(ai, aj1)
        break
    elif aj2 in A:
        print(ai, aj2)
        break
    aj1 -= 1
    aj2 += 1

### FIXED CODE ###

import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
ai = A[-1]

tmp = ai / 2
i = bisect.bisect_left(A, tmp)
if abs(tmp - A[i]) < abs(tmp - A[i - 1]):
    print(ai, A[i])
else:
    print(ai, A[i - 1])
### BUGGY CODE ###

N, T = map(int, raw_input().split())
A_n = map(int, raw_input().split())

max_profit = 0
cost = 0
for i in xrange(len(A_n)):
    for j in xrange(i, len(A_n)):
        if A_n[j]-A_n[i] > max_profit:
            max_profit = A_n[j]-A_n[i]

for i in xrange(len(A_n)):
    for j in xrange(i, len(A_n)):
        if A_n[j]-A_n[i] == max_profit:
            cost += 1

print cost

### FIXED CODE ###

N, T = map(int, raw_input().split())
A_n = map(int, raw_input().split())

count = 0
max_profit = A_n[1] - A_n[0]
min_element = min(A_n[0], A_n[1])
for i in xrange(1, len(A_n)):
    if A_n[i] - min_element > max_profit:
        max_profit = A_n[i] - min_element
        count = 0

    if A_n[i] - min_element == max_profit:
        count += 1

    if A_n[i] < min_element:
        min_element = A_n[i]

print count
### BUGGY CODE ###

N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = [i + 1 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    A = a in kouho
    B = b in kouho
    if A or B:
        Ha = H[a]
        Hb = H[b]
        if Ha > Hb and B:
            kouho.remove(b)
        elif Ha < Hb and A:
            kouho.remove(a)
        elif Ha == Hb:
            if A:
                kouho.remove(a)
            if B:
                kouho.remove(b)
print(len(kouho))


### FIXED CODE ###

N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = set([i + 1 for i in range(N)])
hazure = set()
for i in range(M):
    a, b = map(int, input().split())
    Ha = H[a]
    Hb = H[b]
    if Ha >= Hb:
        hazure.add(b)
    if Ha <= Hb:
        hazure.add(a)
ans = kouho - hazure
print(len(ans))
### BUGGY CODE ###

def main(N,P):
    A=[-1]*4*N*N
    ad=(1,N,-1,-N)
    for I in range(4*N*N):
        i,j=I//4,I%4
        if 0<=i+ad[j]<N*N:
            A[i*4+j]=i+ad[j]
    X=[0]*N*N
    for i in range(N*N):
        X[i]=min(i//N,N-1-i//N,i%N,N-1-i%N)
    E=[1]*N*N
    a=0
    q=[0]*N*N*N
    l,r=0,0
    for p in P:
        p-=1
        a+=X[p]
        E[p]=0
        q[r]=p
        r+=1
        while l<r:
            i=q[l]
            l+=1
            for j in A[4*i:4*(i+1)]:
                if 0<=j and X[i]+E[i]<X[j]:
                    X[j]=X[i]+E[i]
                    q[r]=j
                    r+=1
    return a
import sys
import numpy as np
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,signature):
        cc.export(f.__name__,signature)(f)
        return njit(f)
    main=cc_export(main,(i8,i8[:],))
    cc.compile()
    exit()
N=int(readline())
P=np.array(readline().split(),dtype=np.int64)
from my_module import main
print(main(N,P))


### FIXED CODE ###

def main(N,P):
    ad=(1,N,-1,-N)
    X=[0]*N*N
    for i in range(N*N):
        X[i]=min(i//N,N-1-i//N,i%N,N-1-i%N)
    E=[1]*N*N
    a=0
    q=[0]*N*N*N
    l,r=0,0
    for p in P:
        p-=1
        a+=X[p]
        E[p]=0
        q[r]=p
        r+=1
        while l<r:
            i=q[l]
            l+=1
            for j in ad:
                if 0<=i+j<N*N and X[i]+E[i]<X[i+j]:
                    X[i+j]=X[i]+E[i]
                    q[r]=i+j
                    r+=1
    return a
import sys
import numpy as np
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,signature):
        cc.export(f.__name__,signature)(f)
        return njit(f)
    main=cc_export(main,(i8,i8[:],))
    cc.compile()
    exit()
N=int(readline())
P=np.array(readline().split(),dtype=np.int64)
from my_module import main
print(main(N,P))