Problem:
 Score : 400 points    Problem Statement There are N towns located in a line, conveniently numbered 1 through N . Takahashi the merchant is going on a travel from town 1 to town N , buying and selling apples.  Takahashi will begin the travel at town 1 , with no apple in his possession. The actions that can be performed during the travel are as follows:   Move : When at town i ( i < N ), move to town i + 1 .  Merchandise : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i ( 1 ≦ i ≦ N ), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.   For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T . (Note that a single apple can be counted in both.)  During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.  Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i , any number of times. The cost of performing this operation is |A_i - A_i'| . After performing this operation, different towns may have equal values of A_i .  Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.      Constraints  1 ≦ N ≦ 10^5  1 ≦ A_i ≦ 10^9 ( 1 ≦ i ≦ N )  A_i are distinct.  2 ≦ T ≦ 10^9  In the initial state, Takahashi's expected profit is at least 1 yen.         Input The input is given from Standard Input in the following format:  N  T  A_1  A_2  ...  A_N       Output Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.        Sample Input 1 3 2
100 50 200      Sample Output 1 1  In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:   Move from town 1 to town 2 .  Buy one apple for 50 yen at town 2 .  Move from town 2 to town 3 .  Sell one apple for 200 yen at town 3 .   If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1 , thus the answer is 1 .  There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.       Sample Input 2 5 8
50 30 40 10 20      Sample Output 2 2       Sample Input 3 10 100
7 10 4 5 9 3 6 8 2 1      Sample Output 3 2

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
n,t = ma()
A = lma()
INF=10**15

mns = [INF]*(n+1) 
for i in range(n):
    mns[i] = min(mns[i-1],A[i])
c = 0
dmx = -1
for i in range(1,n):
    if A[i]-mns[i] >dmx:
        dmx=A[i]-mns[i]
        c=1
    elif A[i]-mns[i] ==dmx:
        c+=1
print(c)

Solution (Python):
from collections import defaultdict

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

buy = a[0]
gain = defaultdict(int)
for ai in a:
    buy = min(buy, ai)
    gain[ai - buy] += 1
print(gain[max(gain)])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N, T = MAP()
A = LIST()

buy = [0]*N
sell = [0]*N
buy_memo = [0]*N
sell_memo = [0]*N

tmp_buy = INF
tmp_buy_memo = -1
for i in range(N):
	if A[i] <= tmp_buy:
		tmp_buy = A[i]
		tmp_buy_memo = i
	buy[i] = tmp_buy
	buy_memo[i] = tmp_buy_memo

tmp_sell = 0
tmp_sell_memo = -1
for i in range(N-1, -1, -1):
	if tmp_sell <= A[i]:
		tmp_sell = A[i]
		tmp_sell_memo = i
	sell[i] = tmp_sell
	sell_memo[i] = tmp_sell_memo

diff = [sell[i]-buy[i] for i in range(N)]
max_diff = max(diff)

buy_possible = [0]*N
sell_possible = [0]*N

for i in range(N):
	if diff[i] == max_diff:
		buy_possible[buy_memo[i]] = 1
		sell_possible[sell_memo[i]] = 1

print(min(sum(buy_possible), sum(sell_possible)))

Solution (Python):



import bisect

n, t = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
p = [0] * n
for i in range(n-1,-1,-1):
    mx = max(mx, a[i])
    p[i] = mx - a[i]
p.sort()
print(n-bisect.bisect_left(p, p[-1]))

Solution (Python):
n,t=map(int,input().split())
ar=list(map(int,input().split()))
mn=float('inf')
mdif,mxc=-float('inf'),0
for e in ar:
    if(e-mn>mdif):
        mdif=e-mn
        mxc=1
    elif(e-mn==mdif):
        mxc+=1
    mn=min(mn,e)
print(mxc)

Solution (Python):
n, t = map(int, input().split())
a = [int(x) for x in input().split()]
mx = [0] * n
mx[-1] = a[-1]
for i in range(n - 2, -1, -1):
  mx[i] = max(mx[i + 1], a[i])
d = 0
c = 0
for i in range(n - 1):
  cur = a[i]
  can = mx[i + 1]
  dd = can - cur
  if dd > d:
    d = dd
    c = 1
  elif dd == d:
    c += 1
print(c)

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,r,*a = map(int,read().split())


high = a[-1]
delta = -1

for ai in a[::-1]:
    if high < ai:
        high = ai
    if high-ai > delta:
        delta = high-ai




high = a[-1]

hs = 0
ls = 0

ans = 0
for ai in a[::-1]:
    if high < ai:
        high = ai
        hs = 1
        ans += min(hs,ls)
        ls = 0
    elif high == ai:
        hs += 1        
    
    if high - ai == delta:
        ls += 1
    

print(ans+min(hs,ls))

Solution (Python):
def main():

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

    if N == 1: return 0

    min_v = A[0]
    max_d = float('-inf')
    for i in range(1, N):
        if A[i] - min_v > max_d:
             max_d = A[i] - min_v
        if A[i] < min_v:
            min_v =  A[i]

    d = set()
    d.add(A[0])
    ans = 0
    for i in range(1, N):
        if A[i] - max_d in d: ans += 1
        d.add(A[i])
    return ans



if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

N, T = map(int, input().split())
A = list(map(int, input().split()))
min_acc = [A[0]]

for i in range(1, N):
    min_acc.append(min(min_acc[-1], A[i]))
    
M = 0

for i in range(1, N):
    M = max(M, A[i]-min_acc[i-1])

ans = 0

for i in range(1, N):
    if A[i]-min_acc[i-1]==M:
        ans += 1

print(ans)

Solution (Python):
N,T=map(int,input().split())
a=list(map(int,input().split()))
max_profit=0
mini=a[0]
for i in range(1,N):
    max_profit=max(max_profit,a[i]-mini)
    mini=min(mini,a[i])

mini=a[0]
ans=0
for i in range(1,N):
    if a[i]-mini==max_profit:
        ans+=1
    mini=min(mini,a[i])
print(ans)

Solution (Python):
N, T = map(int, input().split())
A = map(int, input().split())
mxx, mnx = 0, 10**18
for a in A:
    if a-mnx > mxx:
        c, mxx = 1, a-mnx
    elif a-mnx == mxx:
        c += 1
    mnx = min(mnx, a)
print(c)

Solution (Python):
N , T = map(int,input().split())
A = list(map(int,input().split()))

m = 10 ** 9
L = [m] * (N)


for i in range(0,N):
  if A[i] <= m:
    m = A[i]
  L[i] = A[i] - m

M = max(L)

print(L.count(M))

Solution (Python):
N,T=map(int,input().split())
A=list(map(int,input().split())) 
B=[0 for i in range(N)] 
Bl=[set() for i in range(N)] 
B[N-1]=A[N-1]
Bl[N-1].add(N-1)
for i in range(N-2,-1,-1):
    if A[i]>B[i+1]:
        B[i]=A[i]
        Bl[i].add(i)
    elif A[i]==B[i+1]:
        B[i]=B[i+1]
        Bl[i]=Bl[i+1]+{i}
    elif A[i]<B[i+1]:
        B[i]=B[i+1]
        Bl[i]=Bl[i+1]

C=[B[i]-A[i] for i in range(N)]
'''
print(A)
print(B)
print(Bl)
print(C)
'''
Cm=max(C)
Cml=set()
for i in range(N):
    if C[i]==Cm:
        Cml.update(Bl[i])
'''
print(Cm)
print(Cml)
'''
ans=len(Cml)

print(ans)

Solution (Python):
N, M = map(int, input().split())
A = tuple(map(int, input().split()))
mini = 10**10
bnf = 0
cnt = 1
for i in range(N):
	mini = min(mini, A[i])
	_bnf = A[i] - mini
	if _bnf > bnf:
		bnf = _bnf
		cnt = 1
	elif _bnf == bnf:
		cnt += 1
print(cnt)

Solution (Python):
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, T = map(int, input().split())
a = list(map(int, input().split()))
cm = [float("inf")] * (N + 1)
cmx = [0] * (N + 1)
for i in range(N):
  cm[i + 1] = min(cm[i], a[i])
  cmx[N - 1 - i] = max(cmx[N - i], a[N - 1 - i])
res = 0
x = 0
for i in range(N + 1):
  x = max(cmx[i] - cm[i], x)
for i in range(N):
  if cmx[i] - a[i] == x:
    res += 1
print(res)

Solution (Python):
import sys
from collections import Counter
readline = sys.stdin.readline

N, T = map(int, readline().split())
A = list(map(int, readline().split()))
Amax = [None]*N
Amax[N-1] = A[N-1]
for i in range(N-2, -1, -1):
    Amax[i] = max(Amax[i+1], A[i])

B = [am - a for a, am in zip(A, Amax)]
print(Counter(B)[max(B)])

Solution (Python):
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    tmp = A[-1]
    diff_A = [0] * N
    for i in range(N-1,-1,-1):
        tmp = max(A[i],tmp)
        diff_A[i] = tmp - A[i]

    print(diff_A.count(max(diff_A)))



if __name__ == "__main__":
    main()

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
m = a[-1]
tmp = 0
cnt = 0
for i in range(n - 2, -1, -1):
    p = m - a[i]
    if p > tmp:
        tmp = p
        cnt = 1
    elif p == tmp:
        cnt += 1
    m = max(m, a[i])
print(cnt)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))

B = [0]*N
C = [0]*N

h = A[0]
B[0] = h
for i in range(1,N):
    h = min(A[i],h)
    B[i] = h

h = A[-1]
C[-1] = h
for i in range(N-2,-1,-1):
    h = max(A[i],h)
    C[i] = h

B = B[:-1]
C = C[1:]
D = list(map(lambda x:C[x]-B[x],range(N-1)))
t = max(D)

s = 0
D.append(0)
for i in range(N-1):
    if D[i] == t and D[i] > D[i+1]:
        s += 1

print(s)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))

h = []
B = [0]*N

for i in range(N):
    h.append(A[i])
    h = [min(h)]
    B[i] = h[0]

j = []
C = [0]*N

for i in range(N-1,-1,-1):
    j.append(A[i])
    j = [max(j)]
    C[i] = j[0]

B = B[:-1]
C = C[1:]
D = list(map(lambda x:C[x]-B[x],range(N-1)))
t = max(D)

s = 0
D.append(0)
for i in range(N-1):
    if D[i] == t and D[i] > D[i+1]:
        s += 1

print(s)

Solution (Python):
import heapq

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

h = []
B = [0]*N

for i in range(N):
    heapq.heappush(h,A[i])
    B[i] = h[0]

j = []
C = [0]*N

for i in range(N-1,-1,-1):
    heapq.heappush(j,-A[i])
    C[i] = -j[0]

B = B[:-1]
C = C[1:]
D = list(map(lambda x:C[x]-B[x],range(N-1)))
t = max(D)

s = 0
D.append(0)
for i in range(N-1):
    if D[i] == t and D[i] > D[i+1]:
        s += 1

print(s)

Solution (Python):
import numpy as np

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

A = np.array(list(map(int,input().split())))

B = np.minimum.accumulate(A)

C = A - B

ans = (C == C.max()).sum()

print(ans)

Solution (Python):
N, T = map(int,input().split())
A = list(map(int,input().split()))
B = [0 for k in range(N)]
B[0] = A[0]
for k in range(1,N):
    B[k] = min(B[k-1],A[k])
m = 0
for k in range(N):
    m = max(A[k]-B[k],m)
ans = 0
for k in range(N):
    if A[k]-B[k] == m:
        ans += 1
print(ans)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))

cnt = max_profit = 0
INF = float('inf')
min_cost = INF
for a in A:
    profit = a - min_cost
    if profit == max_profit:
        cnt += 1
    elif profit > max_profit:
        cnt = 1
        max_profit = profit
    min_cost = min(min_cost, a)

print(cnt)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
m=10**10
M=0
k=[]
for i in range(n):
	m=min(m,a[i])
	M=a[i]-m
	k.append(M)
o=max(k)
print(k.count(o))

Solution (Python):
def getlist():
	return list(map(int, input().split()))


N, T = getlist()
A = getlist()
m = A[0]
plus = -float("inf")
cost = 1
for i in range(1, N):
	if A[i] - m == plus:
		cost += 1
	elif A[i] - m > plus:
		plus = A[i] - m
		cost = 1
	else:
		pass
	m = min(m, A[i])

print(cost)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    min_b = 10 ** 9
    max_p = 0
    for v in a:
        p = v - min_b
        max_p = max(max_p, p)
        d[p] += [min_b]
        min_b = min(min_b, v)
    print(len(d[max_p]))


if __name__ == '__main__':
    slove()

Solution (Python):
_,_,*a=map(int,open(0).read().split());d={}
for x,y in zip(a,__import__("itertools").accumulate(a,min)):d[x-y]=d.get(x-y,0)+1
print(d[max(d.keys())])

Solution (Python):
from itertools import*;_,a=open(0);*a,=map(int,a.split());c=[x-y for x,y in zip(a,accumulate(a,min))];print(c.count(max(c)))

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    MAXl = [A[-1]]
    for i in range(1,N-1):
        MAXl.append(max(MAXl[i-1],A[-i-1]))
    MAXl.reverse()
    count = 0
    profit = 0
    for i in range(N-1):
        p = MAXl[i]-A[i]
        if p == profit:
            count += 1
        elif p > profit:
            profit = p
            count = 1

    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    b = collections.defaultdict(list)
    m_c = 10 ** 9
    for i, v in enumerate(a):
        if i != 0 and m_c < v:
            b[v-m_c] += [m_c]
        m_c = min(m_c, v)
    b = sorted(b.items(), reverse=True)[0]
    print(len(collections.Counter(b[1])))


if __name__ == '__main__':
    slove()

Solution (Python):

def main():
    N, T, *A = map(int, open(0).read().split())
    cur, cand = A[0], []
    for i in A:
        if i < cur:  
            cur = i
        else:
            cand += [i - cur]  
    x = max(cand)  
    
    ans = sum(i == x for i in cand)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

maxA = [0 for _ in range(N + 1)]
minA = [float('inf') for _ in range(N + 1)]

for i, a in enumerate(A):
    minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
    maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)

maxProfit = 0
for i in range(1, N):
    if maxProfit < maxA[i + 1] - minA[i]:
        maxProfit = maxA[i + 1] - minA[i]

pairs = set([])
for i in range(1, N):
    if maxProfit == maxA[i + 1] - minA[i]:
        pairs.add((minA[i], maxA[i + 1]))

ans = len(pairs)
print(ans)

Solution (Python):
(N,T)=map(int,input().split())
a=list(map(int,input().split()))
x=10**9
d=0
counter=0
for i in a:
    if i<x:
        x=i
    elif i-x>d:
        d=i-x
        counter=1
    elif i-x==d:
        counter+=1
print(counter)

Solution (Python):
N,T=map(int,input().split())
A=list(map(int,input().split()))
x=10**9
d=0
ans=0
for a in A:
    if a<x:
        x=a
    elif a-x>d:
        d=a-x
        ans=1
    elif a-x==d:
        ans+=1
print(ans)

Solution (Python):
n,t = map(int,input().split())
a = list(map(int,input().split()))
mn = a[0]
l = []
for i in range(n-1):
    if a[i] < a[i+1]:
        l.append(a[i+1]-mn)        
    if a[i+1] < mn:
        mn = a[i+1]
if len(l) > 0:
    d = max(l)
ans = l.count(d)
print(ans)

Solution (Python):
N, T = map(int, input().split())
*A, = map(int, input().split())
min_price = A[0]
max_prof = 0
count = 1
for a in A[1:]:
    prof = a - min_price
    if prof < 0: min_price = a
    elif prof == max_prof: count += 1
    elif prof > max_prof: max_prof = prof; count = 1;
print(count)

Solution (Python):
N, T = map(int, input().split())
*A, = map(int, input().split())
max_price = A[N-1]
max_prof = 0
count = 1
for a in reversed(A[:N-1]):
    prof = max_price - a
    if prof < 0: max_price = a
    elif prof == max_prof: count += 1
    elif prof > max_prof: max_prof = prof; count = 1;
print(count)

Solution (Python):
n,t=map(int,input().split())
A=[int(i) for i in input().split()]
A=A[::-1]
B,C=[0]*n,[0]*n
B[0]=A[0]
cur=A[0]
for i in range(1,n):
  cur=max(cur,A[i])
  B[i]+=cur
for i in range(n):
  C[i]=B[i]-A[i]
m=max(C)
ans=0
for i in range(n):
  if C[i]==m:
    ans+=1
print(ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, t = li()
a = list(li())

mina = [0]*n
mina[0] = a[0]
maxprof = 0

for i in range(1, n):
    mina[i] = min(mina[i-1], a[i])

ans = 0
for i in range(n):
    if a[i] - mina[i] > maxprof:
        maxprof = a[i] - mina[i]
        ans = 1

    elif a[i] - mina[i] == maxprof:
        ans += 1

print(ans)

Solution (Python):
n,t = map(int, input().split())
a = list(map(int, input().split()))

b = float('inf')

c = 0

ans = 0

for i in range(n):
    if a[i]<b:
        b = a[i]
    if a[i]-b == c:
        ans += 1
    elif a[i]-b > c:
        c = a[i]-b
        ans = 1

print(ans)

Solution (Python):

import sys


def solve(N: int, T: int, A: "List[int]"):
    right_max = [0] * N 
    m_a = 0
    for i in range(1, N):
        m_a = max(m_a, A[-i])
        right_max[-i-1] = m_a

    m_p = 0
    count = 0
    for i, a in enumerate(A):
        profit = right_max[i] - a
        if profit > m_p:
            m_p = profit
            count = 1
        elif profit == m_p:
            count += 1
    print(count)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    T = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, T, A)

if __name__ == '__main__':
    main()

Solution (Python):
n, t = map(int, input().split())
alist = list(map(int, input().split()))
minal = [alist[0]]
maxal = [alist[-1]]
for a in alist[1:]:
  if minal[-1] > a:
    minal.append(a)
  else:
    minal.append(minal[-1])

for a in alist[::-1][1:]:
  if maxal[-1] < a:
    maxal.append(a)
  else:
    maxal.append(maxal[-1])
maxal = maxal[::-1]

maxda = 0
ans = 0
prevmina, prevmaxa = None, None
for mina, maxa in zip(minal, maxal):
  if prevmina == mina and prevmaxa == maxa:
    continue
  elif maxa - mina == maxda:
    ans += 1
  elif maxa - mina > maxda:
    maxda = maxa - mina
    ans = 1
  prevmina, prevmaxa = mina, maxa

print(ans)

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
min_A = 1000000001
max_diff = 0
ans = 0
for i in A:
    min_A = min(min_A, i)
    if i - min_A == max_diff:
        ans += 1
    if i - min_A > max_diff:
        max_diff = i - min_A
        ans = 1
print(ans)

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
min_A = 1000000001
max_diff = 0
ans = 0
for i in A:
    min_A = min(min_A, i)
    if i - min_A == max_diff:
        ans += 1
    if i - min_A > max_diff:
        max_diff = i - min_A
        ans = 1
print(ans)

Solution (Python):
n,_,*a=map(int,open(0).read().split())
m=d=c=0
for t in a[::-1]:
    if t>m:
        m=t
    if m-t>d:
        d=m-t
        c=1
    elif m-t==d:
        c+=1
print(c)

Solution (Python):
n,_,*a=map(int,open(0).read().split())
m=d=c=0
for t in a[::-1]:
    if t>m:
        m=t
    if m-t>d:
        d=m-t
        c=1
    elif m-t==d:
        c+=1
print(c)

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))



minv = a[0]

value = [0] * n
for i, v in enumerate(a[1:], 1):
    if minv >= v:
        value[i] = 0
        minv = v
    else:
        value[i] = v - minv

maxv = max(value)

print(value.count(maxv))

Solution (Python):
n, t = map(int, input().split())
ax = list(map(int, input().split()))

sell = []
for a in ax[::-1][:n-1]:
    if len(sell) == 0:
        sell.append([a,1])
        continue
    if a > sell[-1][0]:
        sell.append([a,1])
    elif a == sell[-1][0]:
        sell.append([a, sell[-1][1]+1])
    else:
        sell.append(sell[-1])
sell = sell[::-1]
ans = {}
for i in range(n-1):
    sell_p, cnt = sell[i]
    ans[sell_p-ax[i]] = ans.get(sell_p-ax[i],0)+1
print(ans[max(ans.keys())])

Solution (Python):
N,T = map(int, input().split())
A = list(map(int, input().split()))

back = [(0,0)]*(N+1)

def heapsort(lst):
    h = []
    for value in lst:
        heappush(h,value)
    return [heappop(h) for i in range(len(h))]

for i in range(N, 0, -1):
    if A[i-1] > back[i][0]:
        back[i-1] = (A[i-1], 1)
    elif A[i-1] == back[i][0]:
        back[i-1] = (A[i-1], back[i][1] + 1)
    else:
        back[i-1] = back[i]

anslst = []
from heapq import heappush, heappop

for i in range(N):
    heappush(anslst, (- (back[i][0] - A[i]), back[i][1]) )
anslst = heapsort(anslst)


val = - anslst[0][0]

ans = 0
for i in range(N):
    if val != - anslst[i][0]:
        break
    ans += anslst[i][1] 
print(ans)

Solution (Python):
N, T = map(int, input().split())
towns = list(map(int, input().split()))

p = towns[-1]
r = []

for i in reversed(range(N)):
    if towns[i] >= p:
        p = towns[i]
    else:
        r.append(p-towns[i])

res = r.count(max(r))
print(res)

Solution (Python):

"""
import math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""


"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""


"""
import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)
"""


"""
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
q = int(input())
p = [int(input()) for _ in range(q)]
ans = [[0 for i in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        break
for _ in p:
    print(ans[p])
"""


"""
s = input()
bf = s[0]
ans = 0
for i in range(1,len(s)):
    if bf != s[i]:
        ans += 1
        bf = s[i]
print(ans)
"""


"""
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
ans = ta[0]
for i in ta:
    if ans[0] <= i[0] and ans[1] <= i[1]:
        ans = i
    else:
        a = ((ans[0] - 1) // i[0]) + 1
        b = ((ans[1] - 1) // i[1]) + 1
        ab = max(a,b)
        ans = [i[0] * ab, i[1] * ab]
print(ans[0]+ans[1])
"""


n, t = map(int, input().split())
a = list(map(int, input().split()))
minv = a[0]
maxv = 0
ans = 0
for i in range(1, n):
    if maxv == a[i] - minv:
        ans += 1
    elif maxv < a[i] - minv:
        maxv = a[i] - minv
        ans = 1
    else:
        minv = min(minv,a[i])
print(ans)


"""
s = input()
ans = 0
for i in range(1,len(s)):
    if i % 2 == 1:
        if s[i] != "p":
            ans += 1
    else:
        if s[i] != "g":
            ans -= 1
print(ans)
"""

Solution (Python):

from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007


"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""


"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""


"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""


"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
    d[i+1].insert(0,0)
for i in range(n):
    for j in range(n):
        d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]

for a in range(n+1):
    for b in range(n+1):
        for c in range(a):
            for e in range(b):
                ans[(a-c)*(b-e)] = max(ans[(a-c)*(b-e)],d[a][b]-d[c][b]-d[a][e]+d[c][e])

for i in p:
    an = 0
    for a in range(i+1):
        an = max(an, ans[a])
    print(an)
"""


"""
s = list(S())
ans = -1
s.insert(0,0)
d = 0
for i in range(1,len(s)):
    if s[i] != d:
        d = s[i]
        ans += 1
print(ans)
"""


"""
n = II()
x,y = LI()
for _ in range(n-1):
    a,b = LI()
    if a == b:
        x = max(x,y)
        y = x
    else:
        i = max(x//a,y//b)
        while 1:
            if a*i >= x and b*i >= y:break
            i += 1
        x = a*i
        y = b*i
print(x+y)
"""

"""
s = list(S())
p = 0
g = 0
for i in s:
    if i == "g":
        g += 1
    else:
        p += 1
ans = (g-p)//2
print(ans)
"""

n,t = LI()
a = LI()
b = []
for i in range(n):
    b.append([i,a[i]])
b.sort(key = lambda x:x[1])
b = b[::-1]
m = []
if n == 1:
    print(1)
    quit()
i = 0
for j in range(n):
    while i < b[j][0]:
        m.append(b[j][1])
        i += 1
ans = 0
ma = 0
for i in range(n-1):
    ma = max(ma,m[i]-a[i])
for i in range(n-1):
    if m[i]-a[i] == ma:
        ans += 1
print(ans)

Solution (Python):
n,t = map(int,input().split())
a = list(map(int,input().split()))

p = a[n-1]
r = []

for i in range(n-1,-1,-1):
    if a[i] >= p:
        p = a[i]
    else:
        r.append(p-a[i])

res = r.count(max(r))

print(res)

Solution (Python):
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10000)


N, T = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

ma = A[-1]
mas = 1
resma = 0
rescc = 0
for i in range(N-2, -1 ,-1):
    if A[i] > ma:
        ma = A[i]
        mas = 1
    elif A[i] == ma:
        mas += 1
    else:
        if ma - A[i] > resma:
            resma = ma - A[i]
            rescc = 1
        elif ma - A[i] == resma:
            rescc += 1
        else:
            pass

print(rescc)

Solution (Python):
N,T=map(int,input().split())
A=list(map(int,input().split()))
i=0
j=1
a=0
b=0
while i<=N-1:
    if j==N:
        i=N
    elif A[i]>A[j]:
        i=j
        j+=1
    else:
        if A[j]-A[i]>a:
            a=A[j]-A[i]
            b=1
            j+=1
        elif A[j]-A[i]==a:
            b+=1
            j+=1
        elif A[j]-A[i]<a:
            j+=1
print(b)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))

cummax = [A[-1]]
for a in reversed(A[:-1]):
    cummax.append(max(cummax[-1], a))
cummax.reverse()

maxgain = n = 0
for buy,sell in zip(A,cummax):
    gain = sell - buy
    if gain > maxgain:
        maxgain = gain
        n = 1
    elif gain == maxgain:
        n += 1
print(n)

Solution (Python):

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    T = int(buflist[1])
    buf = input()
    buflist = buf.split()
    A = list(map(int, buflist))
    min_price = A[0]
    max_price_diff = 0
    max_diff_count = 0
    for i in range(1, N):
        if A[i] < min_price:
            min_price = A[i]
        elif A[i] - min_price > max_price_diff:
            max_price_diff = A[i] - min_price
            max_diff_count = 1
        elif A[i] - min_price == max_price_diff:
            max_diff_count += 1
    print(max_diff_count)

if __name__ == '__main__':
    main()

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

N, T = inpl()
A = inpl()
minA = [0 for _ in range(N)]
minA[0] = A[0]
for i in range(N-1):
    minA[i+1] = min(minA[i], A[i+1]) 
ans = 1
maxpro = 0
for i in range(N-1):
    if A[i+1]-minA[i] == maxpro:
        ans += 1
    if A[i+1]-minA[i] > maxpro:
        ans = 1
        maxpro = A[i+1]-minA[i]

print(ans)

Solution (Python):
from collections import Counter

N, T = map(int, input().split())
As = list(map(int, input().split()))

T //= 2
profits = [0] * (N - 1)
minA = As[0]
for i, A in enumerate(As[1:]):
    profits[i] = T * (A - minA)
    minA = min(minA, A)

cnts = Counter(profits)
print(cnts[max(cnts.keys())])

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))

min_a = A[0]
profit = 0
ans = 0
for a in A[1:]:
    min_a = min(min_a, a)
    if a - min_a > profit:
        profit = a - min_a
        ans = 1
    elif a - min_a == profit:
        ans += 1
print(ans)

Solution (Python):


def main():
    n, t = map(int, input().split())
    an = list(map(int, input().split()))

    mi = [an[0]]
    for i in range(1, n):
        mi.append(min(mi[i - 1], an[i]))

    ma = 0
    num_ma = 0
    for i in range(1, n):
        be = an[i] - mi[i - 1]
        if be > ma:
            ma = be
            num_ma = 1
        elif be == ma:
            num_ma += 1
    print(num_ma)

main()

Solution (Python):


def main():
    n, t = map(int, input().split())
    an = list(map(int, input().split()))

    mi = [an[0]]
    se_mi = {0}
    for i in range(1, n):
        if mi[i - 1] > an[i]:
            se_mi = {i}
        elif mi[i - 1] == an[i]:
            se_mi.add(i)
        mi.append(min(mi[i - 1], an[i]))

    ma = 0
    se_ma = set()
    for i in range(1, n):
        be = an[i] - mi[i - 1]
        if be > ma:
            ma = be
            se_ma = {i}
        elif be == ma:
            se_ma.add(i)
    print(len(se_ma))

main()

Solution (Python):
f = lambda: map(int,input().split())
n,_ = f()
a = list(f())
b = [a[0]]+[0]*(n-1)
for i in range(1,n):
    b[i] = min(a[i], b[i-1])
c = [a[i]-b[i] for i in range(n)]
m = max(c)
print(c.count(m))