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):
n, t = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

min_rate = a[0]
max_diff = 0
for item in a[1:]:
    if item < min_rate:
        min_rate = item
    else:
        max_diff = max(max_diff, item-min_rate)

min_rate = a[0]
problems = []
to_solve = [0]
has_problem = False
for item in a[1:]:
    if item < min_rate:
        min_rate = item
        if has_problem:
            problems.append(to_solve)
        to_solve = [0]
        has_problem = False
    elif item == min_rate:
        to_solve.append(0)
    elif item == min_rate + max_diff:
        to_solve.append(1)
        has_problem = True 
if has_problem:
    problems.append(to_solve)
print(len(problems))

Solution (Python):
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1]
  querymax = -1
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if querymax <= a[i]-minA:
        querymax = a[i]-minA
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()

Solution (Python):
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1]
  querymax = -1
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if querymax <= a[i]-minA:
        querymax = a[i]-minA
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()

Solution (Python):


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

apple_price = list(map(int, input().split()))
price_diff = []
now_min = 10**9


for i in range(n):
    if(now_min > apple_price[i]):
        now_min = apple_price[i]
    else:
        price_diff.append(apple_price[i] - now_min)

if(price_diff):
    print(price_diff.count(max(price_diff)))
else:
    print(0)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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


min_ = INF
B = []
for i in A:
	B.append(i-min_)
	
	if min_ > i:
		min_ = i

print(B.count(max(B)))

Solution (Python):
def an_invisible_hand(N: int, T: int, A: list) -> int:
    max_profit = 0
    max_profit_pair_num = 0
    min_price = A[0]

    for price in A[1:]:
        
        
        profit = price - min_price

        if max_profit < profit:
            
            max_profit = profit
            max_profit_pair_num = 1
        elif max_profit == profit:
            
            
            max_profit_pair_num += 1

        min_price = min(min_price, price)

    
    
    
    
    
    return max_profit_pair_num


if __name__ == "__main__":
    N, T = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = an_invisible_hand(N, T, A)
    print(ans)

Solution (Python):
from functools import reduce

def main():
    
    

    
    
    
    
    
    
    
    

    
    
    
    
    s = input().rstrip().split(' ')
    N = int(s[0])
    T = int(s[1])
    A = [int(_) for _ in input().split()]
    min_a = A[0]
    max_cost = 0
    ans = 0
    for a in A:
        if(min_a > a):
            min_a = a
        if(a-min_a > max_cost):
            max_cost = a-min_a
            ans = 1
        elif(a-min_a == max_cost):
            ans = ans + 1
    print(ans)
if __name__ == '__main__':
    main()

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

Solution (Python):
n,t=[int(_) for _ in input().split(" ")]
a=[int(_) for _ in input().split(" ")]
b,m=[],a[0]
for _ in a:
  b.append(m)
  m=min(m,_)
d={}
for _a,_m in zip(a,b):
  if (_a-_m) in d:
    d[_a-_m]+=1
  else:
    d[_a-_m]=1

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

Solution (Python):
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    minimum = float("inf")
    maximum = -1
    ans = 0
    for i in range(N):
        minimum = min(A[i], minimum)
        if maximum == A[i] - minimum:
            ans += 1
        elif maximum < A[i] - minimum:
            maximum = A[i] - minimum
            ans = 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
x = list(map(int,input().split()))

x = x[::-1]
d = dict()
m = x.pop()
M = -1
while x:
    t = x.pop()
    if M < t-m:
        M = t-m
        d[M] = 1
    elif M == t-m:
        d[M] +=1
    m = min(m,t)
print(d[M])

Solution (Python):
n,_ = map(int, input().split())
rate = list(map(int, input().split()))
rmax = [rate[-1]]*n
for i in range(n-2,-1,-1):
  rmax[i] = max(rmax[i+1],rate[i])
benemax = 0
cnt = 0
for i in range(n-1):
  newr = rmax[i]-rate[i]
  if newr > benemax:
    benemax = newr
    cnt = 1
  elif newr == benemax:
    cnt += 1
print(cnt)

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

Solution (Python):
import sys
from collections import deque
import copy
import math
import heapq
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, T] = [int(input_raw[0]), int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    que = [-A[N - 1]]
    max_sub = 0
    count = 0
    for i in range(N-2, -1, -1):
        if (-que[0]) - A[i] == max_sub:
            count += 1
        elif (-que[0]) - A[i] > max_sub:
            count = 1
            max_sub = max((-que[0]) - A[i], max_sub)
        heapq.heappush(que, -A[i])
    print min(count, T/2)




if __name__ == '__main__':
    main()

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

m = a[0]
d = 0
c = 1

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

print(c)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
minkouho = A[0]
curmin = 0
num = 0
for i in range(1,N):
  minkouho = min(minkouho,A[i-1])
  if A[i] - minkouho >= 0:
    if A[i] - minkouho > curmin:
      num = 1
      curmin = A[i]-minkouho
    elif A[i] - minkouho == curmin:
      num += 1
print(num)

Solution (Python):

N,T=map(int,input().split())
A=list(map(int,input().split()))
ma=0
mi=10**9+1
dif=0
c=0
for a in A:
	if a<mi:
		mi=a
	else: 
		if ma<a: 
			ma=a
			dif=ma-mi
			c=1
		else: 
			if dif==a-mi:
				c+=1
			elif dif<a-mi:
				dif=a-mi
	
print(c)

Solution (Python):
import sys
N,T = [int(n) for n in input().split()]

A = [int(n) for n in input().split()]

minv = 10**10
difmax = 0
ans = 0
for i in range(N):
    minv = min(minv,A[i])
    if(difmax < A[i]-minv):
        difmax = A[i]-minv
        ans = 1
    elif difmax == A[i]-minv:
        ans+=1
print(ans)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
ans = defaultdict(int)
nowmin=1+10**9
nowmax=0
for i in range(n):
    if a[i]<nowmin:
        nowmin=a[i]
    if a[i]>nowmin:
        profit=a[i]-nowmin
        ans[profit]+=1
        if profit>nowmax:nowmax=profit
print(ans[nowmax])

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

max_profit = 0
ans = 1
left = 0
right = 1

min_a = a[0]
for i in range(1, N):
    if min_a < a[i]:
        profit = a[i] - min_a
        if profit == max_profit:
            ans += 1
        else:
            max_profit = max(max_profit, profit)
    else:
        min_a = min(min_a, a[i])

print(ans)

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

max_profit = 0
ans = 1
left = 0
right = 1

while right < N:
    if a[left] < a[right]:
        profit = a[right] - a[left]
        if profit == max_profit:
            ans += 1
        else:
            max_profit = max(max_profit, profit)
    else:
        left = right
    right += 1

print(ans)

Solution (Python):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import defaultdict

n, t = getMN()
nums = getlist()
ans = defaultdict(int)
cur = nums[0]
upper = cur
profits = defaultdict(int)
n_low = 1
n_up = 1

for num in nums[1:]:
    if cur > num:
        profits[upper-cur] += min(n_low, n_up)
        cur = num
        n_low = 1
        n_up = 1
        upper = cur
    elif cur == num:
        n_low += 1
    elif num == upper:
        n_up += 1
    elif num > upper:
        upper = num
        n_up = 1
profits[upper-cur] += min(n_low, n_up)

maxkey = max(profits.keys())
print(profits[maxkey])

Solution (Python):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

from collections import defaultdict

n, t = getMN()
nums = getlist()
ans = defaultdict(int)
cur = nums[0]
upper = cur
profits = defaultdict(int)
n_low = 1
n_up = 1

for num in nums[1:]:
    if cur > num:
        profits[upper-cur] += min(n_low, n_up)
        cur = num
        n_low = 1
        n_up = 1
        upper = cur
    elif cur == num:
        n_low += 1
    elif num == upper:
        n_up += 1
    elif num > upper:
        upper = num
        n_up = 1
profits[upper-cur] += min(n_low, n_up)

maxkey = max(profits.keys())
print(profits[maxkey])

Solution (Python):
from collections import defaultdict
N, T = map( int, input().split())
A = list( map( int, input().split()))
now = A[0]
c = 0
for i in range(N):
    c = max( c, A[i]-now)
    now = min( now, A[i])
d = defaultdict( lambda :-1)
for i in range(N):
    d[A[i]] = i
ans = 0
for i in range(N):
    if d[A[i]+c] == -1:
        continue
    if d[A[i]+c] > i:
        ans += 1
print( ans)

Solution (Python):
from collections import Counter

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

m=[None]*n
used=[False]*n

for i in range(n)[::-1]:
    if i==n-1:
        m[i]=a[i]
    else:
        m[i]=max(m[i+1],a[i])

c=Counter([m[i]-a[i] for i in range(n)])
print(c[max(c.keys())])

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

mina = a[0]
minac = 1
maxd = 0
maxdc = 1
for i in range(1, n):
    if a[i] < mina:
        mina = a[i]
        minac = 1
    elif a[i] == mina:
        minac += 1
    elif a[i] - mina > maxd:
        maxd = a[i] - mina
        maxdc = 1
    elif a[i] - mina == maxd:
        maxdc += 1
print(maxdc)

Solution (Python):


"""
参考：https://atcoder.jp/contests/abc047/submissions/4077573
"""

import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

mx = -INF
l = aN[0]
cnt = 0
for i in range(1,N):
    
    if aN[i] < l:
        l = aN[i]
    else:
        
        if aN[i] - l > mx:
            mx = aN[i] - l
            cnt = 1
        
        elif aN[i] - l == mx:
            cnt += 1
print(cnt)

Solution (Python):


"""
参考：https://atcoder.jp/contests/abc047/submissions/4077573
"""

import sys
import re
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

mx = -INF
l = aN[0]
cnt = 0
for i in range(1,N):
    
    if aN[i] < l:
        l = aN[i]
    else:
        
        if aN[i] - l > mx:
            mx = aN[i] - l
            cnt = 1
        
        elif aN[i] - l == mx:
            cnt += 1
print(cnt)

Solution (Python):


import sys
import re
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

mx = -INF
l, r = 0, 1
cnt = 0

while l < N:
    
    while r < N and aN[l] < aN[r]:
        
        if aN[r] - aN[l] > mx:
            mx = aN[r] - aN[l]
            cnt = 1
        
        elif aN[r] - aN[l] == mx:
            cnt += 1
        mx = max(aN[r] - aN[l], mx)
        r += 1
    
    l = r
    r += 1
print(cnt)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
saisyo=a[0]
saidai=0
count=0
for i in range(n):
    if a[i]<saisyo:saisyo=a[i]
    else:
        if a[i]-saisyo>saidai:
            saidai=a[i]-saisyo
            count=1
        elif a[i]-saisyo==saidai:
            count+=1
print(count)

Solution (Python):
indexes = []


def dfs(Ds, s, e, v=None):
    if e - s == 1:
        if v == Ds[s]:
            indexes.append((s, e))
        return Ds[s]
    else:
        center = (s + e) // 2
        left = dfs(Ds, s, center, v=v)
        right = dfs(Ds, center, e, v=v)

        left_m = - (10 ** 9)
        li = -1
        su = 0
        for i in range(center-1, s-1, -1):
            su += Ds[i]
            if left_m != max(left_m, su):
                left_m = max(left_m, su)
                li = i

        right_m = -(10 ** 9)
        ri = -1
        su = 0
        for i in range(center, e):
            su += Ds[i]
            if right_m != max(right_m, su):
                right_m = max(right_m, su)
                ri = i

        if left_m + right_m == v:
            indexes.append((li, ri))

        m = max(left, right, left_m + right_m)
        return m


def solve(N, T, As):
    Ds = [As[i + 1] - As[i] for i in range(N - 1)]
    max_v = dfs(Ds, 0, N - 1)
    dfs(Ds, 0, N - 1, v=max_v)
    return len(indexes)


if __name__ == "__main__":
    N, T = map(int, input().split(" "))
    As = list(map(int, input().split(" ")))
    print(solve(N, T, As))

Solution (Python):



def main():
    from collections import Counter

    n, t = map(int, input().split())
    a = list(map(int, input().split()))
    minmum_numbers = [a[0] for _ in range(n)]
    diff = [0 for _ in range(n)]

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

    print(sorted(Counter(diff).items(), key=lambda x: x[0], reverse=True)[0][1])


if __name__ == '__main__':
    main()

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

MIN_Acc = list(accumulate(A, func=min))
Profits = [A[i] - MIN_Acc[i] for i in range(N)]
MAX_Profit = max(Profits)

ans = Profits.count(MAX_Profit)
print(ans)

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

min_num = 0
margin_list = []
for i in range(N):
    if i == 0:
        min_num = a_list[0]
    else:
        if min_num > a_list[i]:
            min_num = a_list[i]
        else:
            margin_list.append(a_list[i]-min_num)
max_num = max(margin_list)
print(margin_list.count(max_num))

Solution (Python):
N, T = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
buy_price = float('inf')
count = {}
for i in range(N):
    buy_price = min(buy_price, A[i])
    profit = A[i] - buy_price
    count[profit] = count.get(profit, 0) + 1
print(count[sorted(count.keys())[-1]])

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

minA = A[0]
profit = 0
cnt = 0
for i in range(1,N):
    
    p = A[i]-minA
    if p==profit:
        cnt += 1 
    elif p>profit:
        profit = p
        cnt = 1
    
    minA = min(minA,A[i])
    
print(cnt)

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

Solution (Python):
n, t = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
b = sorted(a, reverse=True)
c = set()
k = 1
v = 0
high = 0
ansli = []
for i in range(n - 1):
    c.add(a[i])
    if i == 0 or high == a[i]:
        if i == 0 and b[0] == a[i]:
            v += 1
        while True:
            if b[v] in c:
                v += 1
            else:
                break
        for j in range(k, n):
            if a[j] == b[v] and a[j] not in c:
                high = a[j]
                k = j + 1
                v += 1
                break
            elif a[j] == b[v]:
                v += 1
                while True:
                    if b[v] in c:
                        v += 1
                    else:
                        break
    ansli.append(high - a[i])

ansli.sort(reverse=True)
ans = 1
for i in range(1, n - 1):
    if ansli[i - 1] != ansli[i]:
        break
    else:
        ans += 1
print(ans)

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

MAX=[A[-1]]

for i in range(N-2,-1,-1):
    MAX.append(max(MAX[-1],A[i]))

MAX=MAX[::-1]
SABUN=[MAX[i]-A[i] for i in range(N)]



MAXSA=max(SABUN)

ANS=0
for i in range(N):
    if SABUN[i]==MAXSA:
        ANS+=1

print(ANS)

Solution (Python):
from bisect import bisect_left

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

aa = A[:]
aa.sort()

ans = 0
num = 0

for i in range(N-1):
    ind = bisect_left(aa, A[i])
    del aa[ind]
    now = aa[-1] - A[i]
    
    if 0 < now and num < now:
        ans = 1
        num = now
    elif num == now:
        ans += 1

print(ans)

Solution (Python):
from bisect import bisect_left

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

aa = A[:]
aa.sort()

ans = 0
num = []

for i in range(N-1):
    ind = bisect_left(aa, A[i])
    del aa[ind]
    
    num.append(aa[-1]-A[i])

print(num.count(max(num)))

Solution (Python):
N, T = map(int, input().split())
a_arr = list(map(int, input().split()))
mini = 10**9
diff = []
for a in a_arr:
    if a < mini:
        mini = a
    diff.append(a - mini)
max_diff = max(diff)
ans = 0
for d in diff:
    if d == max_diff:
        ans += 1
print(ans)

Solution (Python):
N,T=map(int,input().split())
A=[int(i) for i in input().split()]
b=0
count=0
for i in range(N):
  if i==0:
    min_A=A[i]
  else:
    if b<A[i]-min_A:
      b=A[i]-min_A
      count=1
    elif b==A[i]-min_A:
      count+=1
    if min_A>A[i]:
      min_A=A[i]
print(count)

Solution (Python):
N,T=list(map(int,input().split()))
min_=10**9+1
max_=0
num=0
for x in map(int,input().split()):
    tmp=x-min_
    if x<min_:
        min_=x
    elif tmp>max_:
        max_=tmp
        num=1
    elif  tmp==max_:
        num+=1
print(num)

Solution (Python):


import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N, T = inpl()
A = inpl()
min_cost = INF
max_diff = 0
cnt = 0
for i in range(N):
    diff = A[i] - min_cost
    if max_diff <= diff:
        if max_diff == diff:
            cnt += 1
        else:
            cnt = 0
            max_diff = diff
    min_cost = min(min_cost, A[i])

print(1 + cnt)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
Min = A[0]
Profit = 0
for i in range(1,N):
    if A[i]-Min > Profit:
        Profit = A[i]-Min
        ans = 1
    elif A[i]-Min == Profit:
        ans += 1
    Min = min(A[i],Min)
print(ans)

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

num = 0
mi = A[0]
for i in range(1, N):
    mi = min(mi, A[i - 1])
    if A[i] - mi == ma:
        num += 1

print(num)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
a.append(0)
res=[]
t=1
j=False
tmin=a[0]
tmax=a[0]
for i in range(1,n+1):
    if tmin>a[i]:
        res.append(tmax-tmin)
        tmin=a[i]
        tmax=a[i]
    if tmax<a[i]:
        tmax=a[i]
print(res.count(max(res)))

Solution (Python):

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

m = A[0]
M = 0
for k in range(1,N):
    m = min(m,A[k-1])
    M = max(M,A[k]-m)

m = A[0]
ans = 0
for k in range(1,N):
    m = min(m,A[k-1])
    if A[k]-m == M:
        ans += 1

print(ans)

Solution (Python):
def 解():
    iN,iT = [int(_) for _ in input().split()]
    aA = [int(_) for _ in input().split()]

    aMaxD = [0]
    iMin = aA[0]
    iV = 0

    def checkMax(aMaxD,iMaxD):
        if aMaxD[0] < iMaxD:
            aMaxD = [iMaxD]
        elif aMaxD[0] == iMaxD:
            aMaxD.append(iMaxD)
        return aMaxD

    iB = aA[0]
    for iN in aA[1:]:
        if iB - iN > 0: 
            if iV >= 0:
                aMaxD = checkMax(aMaxD,iB-iMin)
            iV = -1
        elif iB - iN < 0: 
            if iV <= 0:
                if iB < iMin : iMin = iB
            iV = 1
        iB = iN
    aMaxD = checkMax(aMaxD,aA[-1] - iMin)
    print( len(aMaxD) )
解()

Solution (Python):
def 解():
    iN,iT = [int(_) for _ in input().split()]
    aA = [int(_) for _ in input().split()]
    iL = len(aA)

    aMaxD = [0]
    iMin = aA[0]
    iV = 0

    def checkMax(aMaxD,iMaxD):
        if aMaxD[0] < iMaxD:
            aMaxD = [iMaxD]
        elif aMaxD[0] == iMaxD:
            aMaxD.append(iMaxD)
        return aMaxD

    iB = aA[0]
    for iN in aA[1:]:
        if iB - iN > 0:
            if iV >= 0:
                aMaxD = checkMax(aMaxD,iB-iMin)
            iV = -1
        elif iB - iN < 0:
            if iV <= 0:
                iMin = min(iB,iMin)
            iV = 1
        iB = iN
    aMaxD = checkMax(aMaxD,aA[-1] - iMin)
    print( len(aMaxD) )
解()

Solution (Python):

iN,iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)

aMaxD = [0]
iMin = aA[0]
iV = 0

def checkMax(aMaxD,iMaxD):
    if aMaxD[0] < iMaxD:
        aMaxD = [iMaxD]
    elif aMaxD[0] == iMaxD:
        aMaxD.append(iMaxD)
    return aMaxD

for i in range(1,iL):
    iB = aA[i-1]
    iN = aA[i]
    if iB - iN > 0:
        if iV >= 0:
            aMaxD = checkMax(aMaxD,iB-iMin)
        iV = -1
    elif iB - iN < 0:
        if iV <= 0:
            iMin = min(iB,iMin)
        iV = 1
aMaxD = checkMax(aMaxD,aA[-1] - iMin)
print( len(aMaxD) )

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


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


def ceil(a, b):
    return (a + b - 1) // b


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

    maxi, mini = [-1] * N, [INF] * N
    mini[0] = A[0]
    for i in range(1, N):
        mini[i] = min(mini[i - 1], A[i])
    maxi[-1] = A[-1]
    for i in range(N - 2, -1, -1):
        maxi[i] = max(maxi[i + 1], A[i])

    a, b = defaultdict(int), defaultdict(int)
    diff = -1
    for i in range(N):
        d1 = maxi[i] - A[i]
        d2 = A[i] - mini[i]
        diff = max(diff, d1, d2)
        a[d1] += 1
        b[d2] += 1

    print(min(a[diff], b[diff]))


if __name__ == '__main__':
    main()

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

Profit = []
tempMin = A[0]
tempMax = A[0]
for i in range(1, N+1):
    if tempMin > A[i]:
        Profit.append(tempMax - tempMin)
        tempMin = A[i]
        tempMax = A[i]
    if tempMax < A[i]:
        tempMax = A[i]

ans = Profit.count(max(Profit))
print(ans)

Solution (Python):
N,T=map(int,input().split())
listA=list(map(int,input().split()))
max=-1
count=0
min=listA[0]
for i in range(N-1):
    if listA[1+i]<min:
        min=listA[1+i]
    if listA[1+i]-min>max:
        max=listA[1+i]-min
        count=1
    elif listA[1+i]-min==max:
        count+=1
print(count)

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

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

best_buy = 1e9
best_diff = 0
best_diff_cnt= 0

for i in range(N):
  if best_buy > A[i]:
    best_buy = A[i]
  
  if best_diff < A[i] - best_buy:
    best_diff = A[i] - best_buy
    best_diff_cnt = 1
  elif best_diff == A[i] - best_buy:
    best_diff_cnt += 1
    
  
    
print(best_diff_cnt)

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from collections import Counter

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

a_rev = a[::-1]
itv_max_rev = [0]
for i in range(n-1):
    itv_max_rev.append(max(itv_max_rev[-1], a_rev[i]))
    
itv_max = itv_max_rev[::-1]

cnt = Counter([])
for ai,ivmi in zip(a, itv_max):
    cnt[ivmi - ai] += 1
    
max_key = max(cnt.keys())
print(cnt[max_key])

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

vm = a[n - 1]
dfm = 0
cnt = 0
for i in range(n - 2, -1, -1):
    if a[i] > vm:
        vm = a[i]
    else:
        df = vm - a[i]
        if dfm < df:
            dfm = df
            cnt = 1
        elif dfm == df:
            cnt += 1

print(cnt)

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

vm = a[n - 1]
d = dict()
for i in range(n - 2, -1, -1):
    if a[i] > vm:
        vm = a[i]
    else:
        df = vm - a[i]
        d[df] = d.get(df, 0) + 1

df_cnt = sorted(d.items(), key = lambda x:x[0], reverse = True)

print(df_cnt[0][1])

Solution (Python):
n,t=map(int,input().split())
*a,=map(int,input().split())
l=[None]*n
m=a[0]
for i in range(n):
  m=min(m,a[i])
  l[i]=a[i]-m
print(l.count(max(l)))

Solution (Python):
n,t = map(int,input().split())
a =list(map(int,input().split()))
MIN = float("inf")
b = [0] * n
for i in range(n):
  MIN = min(MIN,a[i])
  b[i] = a[i]-MIN
print(b.count(max(b)))

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

small = 10**9
adv = []
for i in range(1, n):
    small = min(small, a[i-1])
    adv.append(a[i] - small)

count = 0
highest = max(adv)
for i in range(n-1):
    if adv[i] == highest:
        count += 1

print(count)