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):
import numpy as np

N, T = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)


A_cummin = np.minimum.accumulate(A)

profit = A - A_cummin

ans = (profit == profit.max()).sum()
print(ans)

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

amin = A[0]
sa_max = [0, 0]
for i in range(1, n):
    if sa_max[0] < A[i]-amin:
        sa_max[0] = A[i]-amin
        sa_max[1] = 1
    elif sa_max[0] == A[i]-amin:
        sa_max[1] += 1
    amin = min(amin, A[i])
    

print(sa_max[1])

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

l = A[0]
mp = 0
for i in range(1, N):
    if A[i]-l > mp:
        mp = A[i]-l
        c = 1
    elif A[i]-l == mp:
        c += 1
    elif A[i] < l:
        l = A[i]

print(c)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[]
m=a[0]
for i in range(1,n):
  b.append(a[i]-m)
  m=min(m,a[i])
x=max(b)
ct=0
for i in range(len(b)):
  if b[i]==x:
    ct+=1
print(ct)

Solution (Python):
import sys
from collections import Counter
N, T = map(int, input().split())
A = [int(_) for _ in input().split()]

if N == 2:
    print(1)
    sys.exit()

start = A[0]
max_diff = 0
max_count = 0


for n in range(1, N):
    if A[n] < A[n - 1]:
        start = min(A[n], start)
        
    else:
        diff = A[n] - start
        if diff > max_diff:
            max_diff = diff
            max_count = 1
        elif diff == max_diff:
            max_count += 1


print(max_count)

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

B = [0] * (N-1)
minA = A[0]
for i in range(1, N):
    if A[i] < minA:
        minA = A[i]
    B[i-1] = A[i] - minA
B.sort(reverse=True)
ans = 0
for i in B:
    if i == B[0]:
        ans += 1
    else:
        break
print(ans)

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

a_max = [a[-1]] * n
for i in reversed(range(n-1)):
    a_max[i] = max(a[i], a_max[i+1])

a_min = [a[0]] * n
a_diff_max = 0
for i in range(1, n):
    a_min[i] = min(a[i], a_min[i-1])
    a_diff_max = max(a_diff_max, a_max[i] - a_min[i-1])

a_min_max = set()
for i in range(n-1):
    if a_max[i+1] - a_min[i] == a_diff_max:
        a_min_max.add((a_max[i+1], a_min[i]))

ans = len(a_min_max)
print(ans)

Solution (Python):
N, T = map(int, input().split())
A = [int(x) for x in input().split()]

M = [0]*N
D = [0]*N
M[0] = A[0]
D[0] = 0

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

D = sorted(D,reverse=True)
m = D[0]
cnt = 0
for i in range(N):
    if D[i] == m:
        cnt += 1
    else:
        break
print(cnt)

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

cost = 0
min_ = A[0]
dist = 0



for i in range(1, N):
    if min_ > A[i]:
        min_ = A[i]
    dist_tmp = A[i] - min_
    if dist == dist_tmp:
        cost += 1
    elif dist < dist_tmp:
        cost = 1
        dist = dist_tmp
    
    
    
print(cost)

Solution (Python):
N, T = map(int, input().split())
As = list(map(int, input().split()))
if N == 1:
  print(1)
  exit()
Ms = []
m = 0
for i in range(N):
  m = max(m, As[-i-1])
  Ms.append(m)
Ms = list(reversed(Ms))
Ds = []
for i in range(N-1):
  d = Ms[i+1]-As[i]
  Ds.append(d)
dmax = max(Ds)
r = Ds.count(dmax)
print(r)

Solution (Python):
from itertools import accumulate
from collections import Counter

N, T, *A = map(int, open(0).read().split())

M = accumulate(A, min)
B = Counter(a - mi for a, mi in zip(A, M))

print(B[max(B.keys())])

Solution (Python):
from itertools import accumulate

N, T, *A = map(int, open(0).read().split())

M = accumulate(A, min)
B = {}
for a, mi in zip(A, M):
    b = a - mi
    B[b] = B.get(b, 0) + 1

print(B[max(B.keys())])

Solution (Python):
N, T, A0, *A = map(int, open(0).read().split())

mi = A0
B = {}
for a in A:
    b = a - mi
    B[b] = B.get(b, 0) + 1
    mi = min(mi, a)

print(B[max(B.keys())])

Solution (Python):
N, T, A0, *A = map(int, open(0).read().split())

ma, mi = 0, A0
B = {}
for a in A:
    b = a - mi
    B[b] = B.get(b, 0) + 1
    ma, mi = max(ma, b), min(mi, a)

print(B[ma])

Solution (Python):
from collections import Counter

N, T, *A = map(int, open(0).read().split())

mi = A[0]
ma = 0

B = Counter()
for a in A[1:]:
    b = a - mi
    B[b] += 1
    ma = max(ma, b)
    mi = min(mi, a)

print(B[ma])

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

B = []
n = A[0]
for a in A:
    B.append(a-n)
    n = min(n, a)

B.sort(reverse=True)
c = 0
for b in B:
    if b == B[0]:
        c += 1
    else:
        break
print(c)

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

profit_list = []

min_a = 10**9+1
for a in a_list:
    profit_list.append(a-min_a)
    if a<min_a:
        min_a = a

profit_list.sort()

max_profit = profit_list[-1]

cnt = 0
for p in profit_list:
    if p == max_profit:
        cnt += 1

print(cnt)

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 = len([1 for i in cand if i == x])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, T = tuple(map(int, input().split()))
    A = tuple(map(int, input().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):
n,t=map(int,input().split())
a=list(map(int,input().split()))
kau=1
uru=0
cost=0
min_a=a[0]
min_count=0
max_sa=0
for i in range(1,n):
  if a[i]<min_a:
    min_a=a[i]
    if uru!=0:
      cost+=min(kau,uru)
    kau=1
    uru=0
  elif a[i]==min_a:
    kau+=1
  elif a[i]-min_a>max_sa:
    max_sa=a[i]-min_a
    cost=0
    uru=1
  elif a[i]-min_a==max_sa:
    uru+=1
if uru!=0:
  cost+=min(kau,uru)
print(cost)

Solution (Python):
import numpy as np
N, T = map(int,input().split())
A = np.array(input().split(), dtype=np.int32)

A_mi = np.minimum.accumulate(A)
pro = A - A_mi

answer = sum(pro == max(pro))
print(answer)

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

amin=10**9+1
amax=10**9+1
damax=-1
dacount=0

for a in A:
  if a<amin:
    if damax<amax-amin:
      damax=amax-amin
      dacount=1
  
    elif damax==amax-amin:
      dacount+=1
    amin=a
    amax=amin

  if amax<a:
    amax=a
if damax<amax-amin:
  damax=amax-amin
  dacount=1
elif damax==amax-amin:
  dacount+=1
print(dacount)

Solution (Python):
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
Min = a[0]
dif  = 0
for i in range(1,n):
    if dif < a[i] - Min:
        dif = a[i] - Min
        ans = 1
    elif dif == a[i] - Min:
        ans += 1
    Min = min(Min,a[i])

print(ans)

Solution (Python):



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

n,t = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

m = gain = 0
ans = 0
for ai in reversed(a):
    m = max(ai,m)
    if gain < m-ai:
        ans = 1
    elif gain == m-ai:
        ans += 1
    gain = max(gain,m-ai)

print(ans)

Solution (Python):



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

n,t = [int(i) for i in readline().split()]
a = [10**9+1]+[int(i) for i in readline().split()]


"""
gain = 0
m = 0
maxid = []
minid = []
memo = {}
for i in range(n-1,-1,-1):
    ai = a[i]
    if ai > m:
        m = ai
        maxid = [i]
        memo.append([minid[:],maxid[:]])
    elif ai == m:
        maxid.append[i]

    m = max(ai,m)
    if gain < m-ai:
        gain = m-ai
        minid = [i]
        memo = []
    elif gain == m-ai:
        minid.append(i)
    
    print(minid,maxid,memo)
"""    

gain = 0
m = 0
for ai in reversed(a):
    m = max(ai,m)
    if gain < m-ai: gain = m-ai

m = 0
mi = ma = 0

ans = 0
for ai in reversed(a):
    if m < ai:
        ans += max(mi,ma)
        mi = ma = 0
    elif m == ai:
        ma += 1

    m = max(m,ai)
    
    if m-ai == gain:
        mi += 1


print(ans)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
B = [-1]
buy = A[0]
for i in A:
    buy = min(i,buy)
    B.append(i-buy)
B.sort(reverse=True)
i = 0
while B[0] == B[i]:
    i += 1
print(i)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
B = []
buy = A[0]
for i in A:
    buy = min(i,buy)
    B.append(i-buy)
B.sort(reverse=True)
i = 0
while B[0] == B[i]:
    i += 1
print(i)

Solution (Python):
import collections
n, t = map(int, input().split())
a = list(map(int, input().split()))
mi = 10 ** 9
als = collections.defaultdict(list)
for i, v in enumerate(a):
    mi = min(mi, v)
    pft = v - mi
    als[pft] += [mi]
als = sorted(als.items(), reverse=True)
als = collections.Counter(als[0][1]).most_common()
print(len(als))

Solution (Python):
N,T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
mintmp = float("inf")
difflist = []
for A_i in A:
    mintmp = min(A_i,mintmp)
    difflist.append(A_i-mintmp)
print(difflist.count(max(difflist)))

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

maxdiff = 0
ct = 0
mintmp = float("inf")
for A_i in A:
    mintmp = min(A_i,mintmp)
    diff = A_i - mintmp
    if diff > maxdiff:
        maxdiff = diff
        ct = 1
    elif diff == maxdiff:
        ct += 1
print(ct)

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
mintmp=float("inf")
ldef=[]
for i in l:
    mintmp=min(mintmp,i)
    ldef.append(i-mintmp)
print(ldef.count(max(ldef)))

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
thenumberofgoodpairs = 0
maxpricedifference = 0
minimumprice = float("inf")
for appleprice in a :
    if minimumprice > appleprice :
        minimumprice = appleprice
    elif appleprice - minimumprice == maxpricedifference :
        thenumberofgoodpairs += 1
    elif appleprice - minimumprice > maxpricedifference :
        maxpricedifference = appleprice - minimumprice
        thenumberofgoodpairs = 1
print(thenumberofgoodpairs)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[a[-1]]
for i in a[::-1][1:]:b.append(max(i,b[-1]))
c=[b[n-i-1]-a[i]for i in range(n)]
print(c.count(sorted(c)[-1]))

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

ans = 0
temp_min = A[0]
max_diff = 0
for i in range(1, N):
    if A[i] < temp_min:
        temp_min = A[i]
    else:
        diff = A[i] - temp_min
        if diff > max_diff:
            ans = 1
            max_diff = diff
        elif diff == max_diff:
            ans += 1
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,t = map(int,input().split())
a = list(map(int,input().split()))
ma,mi,ans = 0,float('inf'),0
for i in range(n):
    if ma < a[i] - mi:
        ma = a[i] - mi
        ans = 1
    elif ma == a[i] - mi:
        ans += 1
    if mi > a[i]:
        mi = a[i]
    
print(ans)

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

MAX=[0]
MIN=[10**10]

for i in range(n):
    MAX.append(max(a_r[i],MAX[-1]))
    MIN.append(min(a[i],MIN[-1]))
    
MAX.reverse()

MAX=MAX[:n]
MIN=MIN[1:]

t=[MAX[i]-MIN[i] for i in range(n)]

m=max(t)

cnta,cntb=0,0

for i in range(n):
    if t[i]==m:
        if MAX[i]==a[i]:
            cnta+=1
        if MIN[i]==a[i]:
            cntb+=1
print(min(cnta,cntb))

Solution (Python):
import functools

def calc_reward(seq):    
    def f(m_r, e):
        return min(m_r[0], e), max(m_r[1], e - m_r[0])
    return functools.reduce(f, seq, (seq[0], 0))[1]

def calc_cost(seq: list):
    mi, ma = min(seq), max(seq)
    if mi == ma:
        return 0
    rev_seq = seq[::-1] 
    return min(seq[seq.index(mi):].count(ma), rev_seq[rev_seq.index(ma):].count(mi))
        
def divide_iter(seq):
    s = [seq[0]]
    for e in seq[1:]:
        if e < s[0]:
            yield s
            s = []
        s.append(e)
    yield s

def solve(seq):
    divided = list(divide_iter(seq))    
    rewards = list(map(calc_reward, divided))
    costs = list(map(calc_cost, divided))
    max_reward = max(rewards)
    return sum(map(lambda r_c: r_c[1], 
            filter(lambda r_c: r_c[0] == max_reward, zip(rewards, costs))))

def main():
    _ = input()
    A = list(map(int, input().split()))
    print(solve(A))

if __name__ == "__main__":
    main()

Solution (Python):

def main():
    num, t = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 1
    min_data = data[0]
    max_sa = 0

    for i in range(1, num):
        now_sa = data[i] - min_data
        if now_sa > max_sa:
           ans = 1
           max_sa = now_sa
        elif now_sa == max_sa:
            ans += 1
        min_data = min(min_data, data[i])

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

minimum = a[0]
diffs = []
for i in range(1, n):
    diffs.append(a[i] - minimum)
    minimum = min(minimum, a[i])

c = collections.Counter(diffs)
print(c[max(c)])

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: int, A: "List[int]"):
    mx = 0
    mn = float('inf')
    ret = 0
    for a in A:
        if a < mn:
            mn = a
        if a - mn > mx:
            mx = a - mn
            ret = 1
        elif a - mn == mx:
            ret += 1
    print(ret)
    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())
*A, = map(int,input().split())
m = [A[0]]*N
B = [0]*N
for i,a in enumerate(A[1:],1):
    m[i] = min(m[i-1],a)
    B[i] = a - m[i]
MB = max(B)
print(B.count(MB))

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

ans = 0
tmp_min = A[0]
tmp_diff = 0
for i in range(1, N):
    if A[i] < tmp_min: 
        tmp_min = A[i]
        continue
    if A[i] - tmp_min == tmp_diff:
        ans += 1
    if A[i] - tmp_min > tmp_diff:
        ans = 1
        tmp_diff = A[i] - tmp_min

print (ans)

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

max_a = [0]
for i in range(n):
    max_a.append(max(max_a[-1], a[-i - 1]))
max_a.reverse()
profit = []
for i in range(n):
    profit.append(max_a[i] - a[i])
print(profit.count(max(profit)))

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
v = []
currMin = a[0]
for i in range(1, n):
  v.append((currMin, a[i]))
  currMin = min(currMin, a[i])

v = sorted(v, key=lambda x: x[1] - x[0], reverse=True)
cnt = 0
for i in range(len(v)):
  if v[i][1] - v[i][0] == v[0][1] - v[0][0]:
    cnt += 1
print(cnt)

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

INF = 10 ** 10
min_cum_A = [INF] * N
for i in range(N):
    min_cum_A[i] = min(A[i], min_cum_A[i-1])
ans = 0
max_profit = 0
for i in range(1, N):
    if A[i] - min_cum_A[i-1] > max_profit:
        ans = 1
        max_profit = A[i] - min_cum_A[i-1]
    elif A[i] - min_cum_A[i-1] == max_profit:
        ans += 1
print(ans)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re




def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



N, T = l_inpl()
A = l_inpl()

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

l = [max_val - min_val for max_val, min_val in h]
m = max(l)
print(l.count(m))

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

m = [A[0]]

mv = A[0]
for a in A[1:] :
    if a < mv :
        m.append(a)
        mv = a
    else :
        m.append(mv)

Md, Mn = 0, 0
for i in range(N - 1, 0, -1) :
    d = A[i] - m[i-1]
    if d > Md :
        Md, Mn = d, 1
    elif d == Md :
        Mn += 1
        
print(Mn)

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

m = [(A[0], 1)]

mv, mn = A[0], 1
for a in A[1:] :
    if a < mv :
        m.append((a, 1))
        mv, mn = a, 1
    elif a == mv :
        m.append((mv, mn + 1))
        mn += 1
    else :
        m.append((mv, mn))

Md, Mn = 0, 0
for i in range(N - 1, 0, -1) :
    d = A[i] - m[i-1][0]
    if d > Md :
        Md, Mn = d, 1
    elif d == Md :
        Mn += m[i-1][1]
        
print(Mn)

Solution (Python):
n, x = [ int(v) for v in input().split() ]

num_list = [ int(v) for v in input().split() ]
profit_list = []

low, high = None, None
for i in range(n):
    if low == None:
        low = num_list[i]
    if high == None:
        high = num_list[i]
    
    if low > num_list[i]:
        if high != low:
            profit_list.append(high-low)
        low, high = num_list[i], num_list[i]
    if num_list[i] > high:
        high = num_list[i]
    if i == n-1 and high != low:
        profit_list.append(high-low)


max_prof = max(profit_list)
ans = profit_list.count(max_prof)
print(ans)

Solution (Python):
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
mn,mx=10**10,-1
d={}
for i in range(n-1):
    mn=min(a[i],mn)
    mx=max(a[i+1]-mn,mx)
    d[a[i]]=i
d[a[n-1]]=n-1
ans=0
for i in range(1,n):
    if a[i]-mx in d and d[a[i]-mx]<i:
        ans+=1
print(ans)

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, T = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

cummin = list(itertools.accumulate(A, min))
rcummax = list(reversed(list(itertools.accumulate(reversed(A), max))))

max_profit = 0
for mi, ma in zip(cummin, rcummax):
    max_profit = max(max_profit, ma - mi)

mic = 0
mac = 0
for a, mi, ma in zip(A, cummin, rcummax):
    if a == mi and ma - mi == max_profit:
        mic += 1
    if a == ma and ma - mi == max_profit:
        mac += 1
print(min(mic, mac))

Solution (Python):
input()
d,a={},list(map(int,input().split()))
for x in a:
 d[x-a[0]]=d.get(x-a[0],0)+1
 a[0]=min(a[0],x)
print(d[max(d.keys())])

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

mn = a[0]
d = {}

for x in a:
    d[x-mn] = d.get(x-mn, 0) + 1
    mn = min(mn, x)

print(d[max(d.keys())])

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

mn = a[0]
d = {}

for x in a:
    d[x-mn] = d.get(x-mn, 0) + 1
    mn = min(mn, x)

print(max(d.items(), key=lambda x:x[0])[1])

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

mn = a[0]
l = []

for x in a:
    l.append(x-mn)
    mn = min(mn, x)

l.sort()
print(l.count(l[-1]))

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

max_bef = 0
cnt = 0
A_min = A[0]

for i in range(1,N):
    tmp = A[i] - A_min
    if max_bef < tmp:
        max_bef = tmp
        cnt = 0
    if max_bef == tmp:
        cnt += 1
    A_min = min(A_min, A[i])

print(cnt)

Solution (Python):
n,t=map(int,input().split())
arr=list(map(int,input().split()))
tmin=10**10
tdiff=0
ans=0
for i in range(n):
  if arr[i]<tmin:
    tmin=arr[i]
  else:
    diff=arr[i]-tmin
    if diff<tdiff:
      continue
    elif tdiff==diff:
      ans+=1
    else:
      tdiff=diff
      ans=1
print(ans)

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

ma = A[-1]
maL = [ma]
for i in range(1,N):
    if A[-i-1] > ma:
        ma = A[-i-1]
        maL.append(ma)
    else:
        maL.append(ma)

ans = 1
maL = maL[::-1]
sa = maL[0] - A[0]
for i in range(1,N):
    s = maL[i] - A[i]
    if s == sa:
        ans += 1
    elif s > sa:
        ans = 1
        sa = s
print(ans)

Solution (Python):

N,T=map(int,raw_input().split())
A=map(int,raw_input().split())
A.reverse()
ma=-1
B=[-1145181919810]*N
for i in range(len(A)):
    if ma<A[i]:ma=A[i]
    else:B[i]=ma-A[i]
mi=max(B)
ans=0
for b in B:
    if b==mi:ans+=1
print(ans)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
ma=[0]*n
ma[n-1]=a[n-1]
for i in range(n-2,-1,-1):
  ma[i]=max(ma[i+1],a[i])
plus=[0]*n
for j in range(n):
  plus[j]=ma[j]-a[j]
plusm=max(plus)
print(plus.count(plusm))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

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

L_min = [mod for i in range(N)]
L_min[0] = A[0]
for i in range(1,N):
    L_min[i] = min(L_min[i-1],A[i])

A.reverse()
R_max = [0 for i in range(N)]
R_max[0] = A[0]
for i in range(1,N):
    R_max[i] = max(R_max[i-1],A[i])

R_max.reverse()

ans = 0
dif = -mod

for i in range(1,N):
    if dif < R_max[i] - L_min[i] and 0 < R_max[i] - L_min[i]:
        dif = R_max[i] - L_min[i]
        r,l = R_max[i],L_min[i]
        
        ans = 1
    elif dif == R_max[i] - L_min[i]:
        if r == R_max[i]:
            pass
        else:
            r,l = R_max[i],L_min[i]
            ans += 1

print(ans)

Solution (Python):
s=input()
a=list(map(int,input().split()))
mx=0
l=[]
for i in a[::-1]:
    mx = max(mx,i)
    l+=[mx-i]
l.sort()
r = 0
for i in l[::-1]:
    if i==l[-1]:
        r+=1
print(r)

Solution (Python):
n , t = map(int,input().split())
a = list(map(int,input().split()))
mx = 0
l = []
for i in a[::-1]:
    mx = max(mx,i)
    l.append(mx-i)
l.sort()
res = 0
for i in l[::-1]:
    if i==l[-1]:
        res+=1
    else:
        break
print(res)

Solution (Python):
N,T=map(int,input().split())
A=list(map(int,input().split()))
d=0
m=A[0]
M=A[0]
for i in range(N):
    if m>A[i]:
        m=A[i]
        M=A[i]
    elif M<A[i]:
        M=A[i]
        d=max(M-m,d)
tmp=0
D=0
m=A[0]
M=A[0]
for i in range(N):
    if m>A[i]:
        m=A[i]
        M=A[i]
    elif M<A[i]:
        M=A[i]
        D=max(M-m,D)
        if M-m==d:
            tmp+=1
print(tmp)

Solution (Python):

import numpy as np
N,T = map(int,input().split())
A = np.array(input().split(),dtype=np.int32)


A_cummin = np.minimum.accumulate(A)

profit = A - A_cummin

answer = (profit == profit.max()).sum()
print(answer)

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
a_min = a[0]
d = 0
x = 0
for i in range(1, n):
    di = a[i] - a_min
    if d < di:
        d = di
        x = 1
    elif d == di:
        x += 1
    a_min = min(a_min, a[i])
print(x)

Solution (Python):
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]
limax = [ it for it in li ]
for i in range(N-2,-1,-1):
  limax[i] = max(limax[i+1],li[i])
ma = -100000000000000000000
for i in range(N-1,-1,-1):
  ma=max(limax[i] - li[i],ma)
s = 0
for i in range(N-1,-1,-1):
  if (limax[i] - li[i]==ma):
    s+=1
print ( s )

Solution (Python):
N, T = map(int, input().split())
A = [int(a) for a in input().split()]
mi = 10**9
madif = 0
madifcnt = 0
for a in A:
    if a < mi:
        mi = a
    elif a - mi > madif:
        madif = a - mi
        madifcnt = 1
    elif a - mi == madif:
        madifcnt += 1

print(madifcnt)

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = 0
profit = 0
ans = 0
for i in range(n)[::-1]:
    max_a = max(max_a, a[i])
    tmp_profit = max_a - a[i]
    if tmp_profit > profit:
        profit = tmp_profit
        ans = 1
    elif tmp_profit == profit:
        ans += 1
print(ans)

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

A_MIN = list(accumulate(A, func=min))
diff = [a - a_min for a, a_min in zip(A, A_MIN)]

MAX_diff = max(diff)
print(diff.count(MAX_diff))

Solution (Python):
N,T=map(int,input().split())
*A,=map(int,input().split())
B=[0]
for a in A[::-1]:B.append(max(B[-1],a))
C=[b-A[i] for i,b in enumerate(B[:0:-1])]
print(C.count(max(C)))

Solution (Python):


def read_input():
    n, t = map(int, input().split())
    alist = list(map(int, input().split()))

    return n, t, alist


def submit():
    n, t, alist = read_input()

    takahashi_cap = [0]
    curr_min = alist[0]

    for i in range(1, n):
        a = alist[i]
        takahashi_cap.append(a - curr_min)
        if a < curr_min:
            curr_min = a

    takahashi_max = max(takahashi_cap)
    print(len([t for t in takahashi_cap if t == takahashi_max]))


if __name__ == '__main__':
    submit()

Solution (Python):
inf = 10**18
mod = 10**9+7

n,t = map(int,input().split())
a = list(map(int,input().split()))
ma = inf
benefit = 0
ans = 1
for i in range(n):
    if a[i] < ma:
        ma = a[i]
    else:
        b = a[i]-ma
        if b == benefit:
            ans += 1

        if b > benefit:
            benefit = b
            ans = 1
print(ans)

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

max_now = 0
max_idx = 0
max_gap = 0
dat = []
for i in range(n-1,-1,-1):
    if i == n-1:
        max_now = a[i]
        max_idx = i
        max_gap = 0
    else:
        if a[i]>max_now:
            max_idx = i
            max_now = a[i]
            dat.append((a[i],i,max_now,max_idx,0))
        else:
            dat.append((a[i],i,max_now,max_idx,max_now-a[i]))
dat.sort(key = lambda x:x[4],reverse=True)
max_gap = dat[0][4]

res = 0
for _,_,_,_,gap in dat:
    if gap == max_gap:
        res+=1
    else:
        break
print(res)

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

prof = 0
_min = A[0]
setA = set()
answer = 0

for a in A:
  setA.add(a)
  if a > prof+_min:
    prof = a-_min
    answer = 1
    continue
  if _min < a <= prof+_min:
    if a-prof in setA:
      answer +=1    
    continue
  if a<_min:
    _min = a
    continue
    
print(answer)

Solution (Python):
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
p=a[0]
l=[]
for i in range(n):
    p=min(p,a[i])
    if a[i]-p>0:
        l.append(a[i]-p)

print(l.count(max(l)))

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

B = [A[0]]
for i in range(1, N):
    if A[i] < B[-1]:
        B.append(A[i])
    else:
        B.append(B[-1])
        
A.reverse()
C = [A[0]]
for i in range(1, N):
    if A[i] > C[-1]:
        C.append(A[i])
    else:
        C.append(C[-1])
C.reverse()

ans = [[C[1] - B[0]]]
for i in range(1, N - 1):
    if B[i] < B[i - 1]:
        ans.append([C[i + 1] - B[i]])
        
x = max(ans)
print(ans.count(x))

Solution (Python):
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0 for _ in range(N)]

    a = A[0]
    max_profit = 0
    for i in range(N):
        a = min(a, A[i])
        B[i] = A[i] - a
        max_profit = max(max_profit, A[i] - a)

    cnt = 0
    for b in B:
        if b == max_profit:
            cnt += 1

    return cnt


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