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 = map(int, input().split())
a = list(map(int, input().split()))

max_value = [[0, n] for i in range(n + 1)]


for i in range(1, n + 1):
    num = a[-i]
    if max_value[i - 1][0] < num:
        max_value[i][0] = num
        max_value[i][1] = n + 1 - i
    else:
        max_value[i] = max_value[i - 1]


min_value = [10**10 for i in range(n + 1)]

for _ in range(n):
    x = a[_]
    min_value[_ + 1] = min(min_value[_], x)

max_dif = 0
for i in range(1, n + 1):
    if max_value[i][0] > min_value[n - i]:
        max_dif = max(max_dif, max_value[i][0] - min_value[n - i])


disk = []
for i in range(1, n + 1):
    base = a[i - 1]
    if base + max_dif == max_value[n - i][0]:
        disk.append((i, max_value[n - i][1]))




class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uni = UnionFind(n)
for some in disk:
    a, b = some[0], some[1]
    uni.union(a, b)
for i in range(n + 1):
    uni.find(i)



group = {i: [] for i in range(n + 1)}

for i in range(n + 1):
    group[uni.par[i]].append(i)
ans = 0
for i in range(n + 1):
    L = len(group[i])
    ans += L * (L - 1) // 2
print(ans)

Solution (Python):


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

max_value = [[0, n] for i in range(n + 1)]


for i in range(1, n + 1):
    num = a[-i]
    if max_value[i - 1][0] < num:
        max_value[i][0] = num
        max_value[i][1] = n + 1 - i
    else:
        max_value[i] = max_value[i - 1]


min_value = [10**10 for i in range(n + 1)]

for _ in range(n):
    x = a[_]
    min_value[_ + 1] = min(min_value[_], x)

max_dif = 0
for i in range(1, n + 1):
    if max_value[i][0] > min_value[n - i]:
        max_dif = max(max_dif, max_value[i][0] - min_value[n - i])


disk = []
for i in range(1, n + 1):
    base = a[i - 1]
    if base + max_dif == max_value[n - i][0]:
        disk.append((i, max_value[n - i][1]))




class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uni = UnionFind(n)
for some in disk:
    a, b = some[0], some[1]
    uni.union(a, b)
for i in range(n + 1):
    uni.find(i)



group = {i: [] for i in range(n + 1)}

for i in range(n + 1):
    group[uni.par[i]].append(i)
ans = 0
for i in range(n + 1):
    L = len(group[i])
    ans += L * (L - 1) // 2
print(ans)

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,T=MI()
    A=LI()
    M=[0]*N
    M[-1]=A[-1]
    for i in range(1,N):
        M[-1-i]=max(M[-i],A[-i])
        
    diff=[0]*N
    for i in range(N):
        diff[i]=M[i]-A[i]
     
    diff.sort(reverse = True)
    ans=diff.count(diff[0])
    print(ans)

main()

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

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

m = 10 ** 18
d = 0
ans = 0
for i in range(n):
    if d == cmax[i+1] - a[i]:
        ans += 1
    elif d < cmax[i+1] - a[i]:
        d = cmax[i+1] - a[i]
        ans = 1
print(ans)

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

dict = {"tmpmin":A[0],"maxvalue":0,"pairs":0}
for i in range(1,n):
    if A[i] < dict["tmpmin"]:
        dict["tmpmin"] = A[i]
    else:
        if A[i] - dict["tmpmin"] > dict["maxvalue"]:
            dict["maxvalue"] = A[i] - dict["tmpmin"]
            dict["pairs"] = 1
        elif A[i] - dict["tmpmin"] == dict["maxvalue"]:
            dict["pairs"] += 1
print(dict["pairs"])

Solution (Python):
N, T = map(int,input().split())
A = list(map(int,input().split()))
m = [0]*N
M = [0]*N
m[0] = A[0]
for k in range(1,N):
    m[k] = min(A[k],m[k-1])

M[-1] = A[-1]
for k in range(N-2,-1,-1):
    M[k] = max(A[k],M[k+1])

D = [M[k]-m[k] for k in range(N)]
P = max(D)

ans = 0
for k in range(N):
    if A[k]-m[k] == P:
        ans += 1
print(ans)

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

n,t = map(int,readline().split())
lst1 = list(map(int,readline().split()))
counter = []
mn = 10**9+1

for i in range(n):
    if lst1[i] < mn:
        mn = lst1[i]
    if mn < lst1[i]:
        counter.append(lst1[i]-mn)

from collections import Counter
c = Counter(counter)

ans = 0
mx = 0
for key,value in c.items():
    if key > mx:
        ans = value
        mx = key

print(ans)

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

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

ans = [-1, 0] 
max_right = -1

for i in range(N - 2, -1, -1):
    if A[i + 1] > max_right:
        max_right = A[i + 1]
    left = A[i]
    if max_right - left > ans[0]:
        ans = [max_right - left, 1]
    elif max_right - left == ans[0]:
        ans[1] += 1

print(ans[1])

Solution (Python):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N,T=map(int,input().split())
A=list(map(int,input().split()))
ruimin=[A[0]]
ruimax=[A[-1]]
for i in range(1,N):
    ruimin.append(min(ruimin[-1],A[i]))
for i in range(0,N-1)[::-1]:
    ruimax.append(max(ruimax[-1],A[i]))
ruimax.reverse()

value=1
lst=[]
for i in range(0,N-1):
    if ruimax[i+1]-A[i]==value:
        lst.append(i)
    elif ruimax[i+1]-A[i]>value:
        value=ruimax[i+1]-ruimin[i]
        lst=[i]

print(len(lst))

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 9 + 1

profit = [0] * n
buy_mn = INF
for i, e in enumerate(a):
    profit[i] = e - buy_mn
    buy_mn = min(buy_mn, e)

profit_mx = max(profit)
ans = profit.count(profit_mx)
print(ans)

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

profit = [0] * n
buy_mn = a[0]
for i, e in enumerate(a[1:], 1):
    profit[i] = e - buy_mn
    buy_mn = min(buy_mn, e)

profit_mx = max(profit)
ans = profit.count(profit_mx)
print(ans)

Solution (Python):
N, T = map(int,input().split())
price = list(map(int,input().split()))
benefit = [0] * N
ans = 1
pr_low = float("inf")
be_max = 0
for i in range(N):
    if pr_low > price[i]:
        pr_low = price[i]
    else:
        benefit[i] = price[i] - pr_low
        if be_max < benefit[i]:
            be_max = benefit[i]
            ans = 1
        elif be_max == benefit[i]:
            ans += 1
print(ans)

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 accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

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()

lis = []
tmp = A[0]
tmp_max = 0
for i in range(N):
	if tmp > A[i]:
		tmp = A[i]
		lis.append(tmp_max)
		tmp_max = 0
	else:
		tmp_max = max(tmp_max, A[i]-tmp)
lis.append(tmp_max)

print(lis.count(max(lis)))

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

ans = []
min_a = a[0]
for i in range(1, n):
    min_a = min(min_a, a[i-1])
    ans.append(a[i] - min_a)
r = max(ans)
print(ans.count(r))

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

m = 10**9+1
s = 0
c = 0
for a in A:
    m = min(m, a)
    if a - m > s:
        s = a - m
        c = 1
    elif a - m == s:
        c += 1

print(c)

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
max_value = [0] * n 
max_value[-1] = a[-1]
for i in range(-2, -n - 1, -1):
    max_value[i] = max(max_value[i + 1], a[i])
max_profit = 0
for i in range(n - 1):
    max_profit = max(max_profit, max_value[i] - a[i])
ans = 0
for i in range(n - 1):
    if max_value[i] - a[i] == max_profit: ans += 1
print(ans)

Solution (Python):
N,T=map(int,input().split())
A=tuple(map(int,input().split()))
x=[0]*N
x[0]=A[0]
for i in range(1,N):
  x[i]=min(x[i-1],A[i])
B={}
for i in range(1,N):
  tmp=A[i]-x[i-1]
  if tmp<0:
    continue
  if tmp not in B:
    B[tmp]=1
  else:
    B[tmp]+=1
d=list(B.items())
d.sort(reverse=True)
print(d[0][1])

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

profit = -1
low = a[0]
for i in range(n):
    if a[i] < low:
        low = a[i]
    x = 0 if low > a[i] else a[i] - low
    if profit < x:
        profit = x

ans = 0
low = a[0]
for i in range(n):
    diff = a[i] - low
    if diff == profit:
        ans += 1
    if a[i] < low:
        low = a[i]

print(ans)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*n
x[0]=a[0]
for i in range(1,n):
    x[i]=min(x[i-1],a[i])
d=dict()
for i in range(1,n):
    y=a[i]-x[i-1]
    if y>0:
        if y in d:
            d[y]+=1
        else:
            d[y]=1
d=list(d.items())
d.sort(reverse=True)
print(d[0][1])

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*n
x[0]=a[0]
for i in range(1,n):
    x[i]=min(x[i-1],a[i])
d=dict()
for i in range(1,n):
    y=a[i]-x[i-1]
    if y>0:
        if y in d:
            d[y]+=1
        else:
            d[y]=1
d=list(d.items())
d.sort(reverse=True)
print(d[0][1])

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
max_prof = 0
cnt = 0
max_after = [0] * N
max_after[-1] = A[-1]
for i in range(N-1)[::-1]:
    max_after[i] = max(max_after[i+1], A[i])
for i in range(N-1):
    prof = max_after[i+1] - A[i]
    if prof == max_prof:
        cnt += 1
    elif prof > max_prof:
        max_prof = prof
        cnt = 1
print(cnt)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7

N, T = MI()
A = LMI()


m = [0] * N
for j, a in enumerate(reversed(A)):
    if j == 0:
        m[N - 1] = a
        continue
    i = N - j - 1
    m[i] = max(a, m[i + 1])

M = 0
M_cnt = 0
for i, a in enumerate(A):
    if i == N - 1:
        continue
    diff = m[i + 1] - a
    if diff > M:
        M = diff
        M_cnt = 1
    elif diff == M:
        M_cnt += 1
print(M_cnt)

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

min_a = A[0]
diff = 0
count = 0

for i in range(1, len(A)):
    if A[i] <= min_a:
        min_a = A[i]
    elif A[i] - min_a == diff:
        count += 1
    elif A[i] - min_a > diff:
        diff = A[i] - min_a
        count = 1

print(count)

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

max_d = 0
max_count = 0

current_min = 999999999
current_max = 0

for a in A:
    if a < current_min:
        current_min = a
        current_max = 0
        if max_d < (current_max - current_min):
            max_d = current_max - current_min
            max_count = 1
        elif max_d == (current_max - current_min):
            max_count += 1

    if a > current_max:
        current_max = a
        if max_d < (current_max - current_min):
            max_d = current_max - current_min
            max_count = 1
        elif max_d == (current_max - current_min):
            max_count += 1

print(max_count)

Solution (Python):
def main():
    import sys 
    input = sys.stdin.readline
    n,t = map(int,input().split())
    l = list(map(int,input().split()))
    ans = []
    check = l[0]
    for i in l:
        if i < check:
            check = i
        else:
            dis = i-check
            ans.append(dis)
    print(ans.count(max(ans)))

if __name__ == "__main__":
    main()

Solution (Python):
n,t = map(int,input().split())
l = list(map(int,input().split()))
ans = []

check = l[0]
dis = 0
for i in l:
    if i < check:
        check = i
        dis = 0
    
    else:
        dis = i-check
        ans.append(dis)
print(ans.count(max(ans)))

Solution (Python):


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

buy=10**9
buy_loc=[]
benefit=0
for index,item in enumerate(A):
    if buy>item:
        buy=item
        buy_loc.append(index)
    benefit=max(item-buy,benefit)

buy_loc.append(10**6)
buy_loc=buy_loc[::-1]

ans=0
buy_count=0
sell_count=0
for i in range(len(A)):
    if i==buy_loc[-1]:
        buy_loc.pop(-1)
        buy=A[i]
        
        ans+=min(buy_count,sell_count)
        buy_count=0
        sell_count=0
    if A[i]==buy:
        buy_count+=1
    if A[i]-buy==benefit:
        sell_count+=1

ans+=min(buy_count,sell_count)
print(ans)

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, T: int, A: "List[int]"):

    amin, amin_i = (INF, -1)
    gmax = 0
    cand = []

    for i, a in enumerate(A):
        if a < amin:
            amin = a
            amin_i = i
        else:
            if a-amin > gmax:
                gmax = a-amin
                cand = [(gmax, amin_i, i)]
            elif a-amin == gmax:
                cand.append((gmax, amin_i, i))
    print(len(cand))
    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 = list(map(int, input().split()))
B = [-1]*n
B[-1] = A[-1]
for i in range(n-2, 0, -1):
  B[i] = max(A[i], B[i+1])
L = [B[i+1]-A[i] for i in range(n-1)]
ans = L.count(max(L))
print(ans)

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

ma = a[-1]
m = 1
maxsaeki = 0
ans = 0

for i in range(n-2,-1,-1):
    if a[i] > ma:
        ma = a[i]
        m = 1
    elif a[i] < ma:
        if (ma - a[i]) > maxsaeki:
            maxsaeki = ma-a[i]
            ans = 1
        elif (ma - a[i]) == maxsaeki:
            ans += 1

print(ans)

Solution (Python):

n,t = map(int,input().split())
a = list(map(int,input().split()))
b = [0]
for i in range(n)[::-1]:
  b.append(max(b[-1],a[i]))
b.reverse()
b.pop()

c = []
for i in range(n):
  c.append(b[i]-a[i])
c.sort(reverse=True)

cnt = 0
for i in range(n):
  if c[0] == c[i]:
    cnt += 1
  else:
    print(cnt)
    break

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N,T = LI()
A = LI()

diff = -1
num = 0
high = 0
for i in range(N)[::-1]:
    high = max(high,A[i])
    if high-A[i] > diff:
        diff = high-A[i]
        num = 1
    elif high-A[i] == diff:
        num += 1
    else:
        continue

print(num)

Solution (Python):
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1,-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Solution (Python):
N,T = map(int,input().split())
List = list(map(int,input().split()))
dic = {}
min = List[0]
for i in range(N):
  if List[i]<min:
    min = List[i]
  if List[i]-min not in dic:
    dic[List[i]-min] = 1
  else:
    dic[List[i]-min] += 1
dic2 = sorted(dic.items(), reverse=True)
Answer = dic2[0][1]
print(Answer)

Solution (Python):
n,t=map(int,input().split())
l=list(map(int,input().split()))
mi=l[0]
ri=0
t=0
ans=0
for i in l[1:]:
    mi=min(mi,i)
    ma=i 
    if ri<ma-mi:
        ri=ma-mi
        ans=1
    elif ri==ma-mi:
        if t:
            ans+=1
            t=0
    else:
        t=1
print(ans)

Solution (Python):
n, k, *a = map(int, open(0).read().split())

mn = 1e18
ans, got = 1, 0
for i in range(n):
    if(mn>a[i]): mn = a[i]
    elif got==a[i]-mn: ans += 1
    elif got<a[i]-mn:
        got = a[i]-mn
        ans = 1
print(ans)

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

mx = 0
b = []
for i in a[::-1]:
    if mx < i:
        mx = i
    b.append(mx-i if i < mx else 0)
c = Counter(b)

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

Solution (Python):
from itertools import accumulate
from collections import Counter
N, T = map(int, input().split())
A = list(map(int, input().split()))
B = list(accumulate(A, min))
C = Counter(b-a for a, b in zip(A, B))
print(C[min(C)])

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

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

lowest = a[0]
d = []

for i in range(n):
    d.append(a[i]-lowest)
    lowest = min(lowest, a[i])

print(d.count(max(d)))

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

min_A = 10**10
max_A = 0
profit = []
for i in range(N):
    if A[i] <= min_A:
        profit.append(max_A - min_A)
        min_A = A[i]
        max_A = A[i]
    elif A[i] >= max_A:
        profit.append(max_A - min_A)
        max_A = A[i]
profit.append(max_A - min_A)        
        
max_profit = max(profit)
count = 0
for i in range(len(profit)):
    if profit[i] == max_profit:
        count += 1
        
print(count)

Solution (Python):
import sys,heapq
from collections import defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 

def ddprint(x):
  if DBG:
    print(x)

n,t = inm()
a = inl()
heappair = []
hpair = defaultdict(int)
hcnt = defaultdict(int)
hcnt[a[0]] = 1
mn = a[0]
dif = 0
for i in range(1,n):
    z = a[i]
    hcnt[z] += 1
    if z<mn:
        mn = z
    if z-mn>=dif:
        if z-mn>dif:
            dif = z-mn
        e = (-dif,mn,z)
        if e not in hpair:
            hpair[e] = 1
            heapq.heappush(heappair,e)
cnt = 0
v = 1
while len(heappair)>0:
    mdif,mn,z = heapq.heappop(heappair)
    if v==1:
        v = mdif
    if v != mdif:
        break
    cnt += min(hcnt[mn],hcnt[z])
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline
n,t=map(int,input().split())
a=list(map(int,input().split()))
m=a[0]
M=0
for i in range(1,n):
    m=min(m,a[i-1])
    M=max(M,a[i]-m)
m=a[0]
ans=0
for i in range(1,n):
    m=min(m,a[i-1])
    if a[i]-m==M:
        ans+=1
print(ans)

Solution (Python):
N, T = map(int, input().split())
*a, = map(int, input().split())
m = a[0]
p = 0
ans = 0
for i in range(1, N):
    c = a[i] - m
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c
        ans = 1
    elif c == p:
        ans += 1

print(ans)

Solution (Python):
from collections import defaultdict

N, T = map(int, input().split())
*a, = map(int, input().split())
t = defaultdict(int)
m = a[0]
p = 0
ans = 0
for i in range(1, N):
    c = a[i] - m
    if t[m] < c:
        t[m] = c
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c
        ans = 1
    elif c == p:
        ans += 1

print(ans)

Solution (Python):
from collections import defaultdict

N, T = map(int, input().split())
*a, = map(int, input().split())
t = defaultdict(int)
m = a[0]
p = 0
for i in range(1, N):
    c = a[i] - m
    if t[m] < c:
        t[m] = c
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c

ans = 0
for k, v in t.items():
    if v == p:
        ans += 1

print(ans)

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


import heapq
import collections
hq=[]
heapq.heapify(hq)
heapq.heappush(hq,A[0])
tmp=0
table=collections.defaultdict(int)
for i in range(1,N):
  j=heapq.heappop(hq)
  table[A[i]-j]+=1
  tmp=max(tmp,A[i]-j)
  heapq.heappush(hq,j)
  heapq.heappush(hq,A[i])
print(table[tmp])

Solution (Python):
def solve():
    N,T = map(int, input().split())
    A = list(map(int, input().split()))
    max_profit = 0
    min_val = 10**9
    max_profit_pair = []
    
    for a in A:
        
        if max_profit < a-min_val:
            max_profit = a-min_val
            max_profit_pair = [(min_val,a)]
        elif max_profit == a-min_val:
            max_profit_pair.append((min_val,a))
            
        if min_val > a:
            min_val = a
            
    
    print(len(max_profit_pair))
    
solve()

Solution (Python):

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

max_diff = 0
max_value = A[-1]
for i in range(N-2, -1, -1):
    if A[i] > max_value:
        max_value = A[i]
        buf = [i]
    elif A[i] == max_value:
        pass
    else:
        max_diff = max(max_diff, max_value - A[i])


indices = set()
buf = [N-1]
max_value = A[-1]
for i in range(N-2, -1, -1):
    if A[i] > max_value:
        max_value = A[i]
        buf = [i]
    elif A[i] == max_value:
        pass
    else:
        if max_value - A[i] == max_diff:
            indices.add(i)


print(len(indices))

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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


mn = INF
base = -INF
for a in A:
    base = max(base, a - mn)
    mn = min(mn, a)


S = set()
ans = 0
for a in A:
    if a-base in S:
        ans += 1
        S.remove(a-base)
    S.add(a)
print(ans)

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

a = map(int, input().split(" "))

INF = 1000000000000

max_price = -1
min_price = -1

min_pos = 1
max_pos = 1
max_diff = 0
tmp = INF
ans = 0

for c in a:
    if max_price < 0 or min_price < 0:
        max_price = c
        min_price = c
        continue

    if max_price == c:
        max_pos += 1
        tmp = min(tmp, min_pos, max_pos)

    if min_price == c:
        min_pos += 1

    if max_price < c:
        max_price = c
        max_pos = 1

        if max_diff == max_price - min_price:
            tmp = min(tmp, min_pos, max_pos)

        elif max_diff < max_price - min_price:
            max_diff = max_price - min_price
            ans = 0
            tmp = min(tmp, min_pos, max_pos)

    if min_price > c:
        min_price = c
        max_price = c
        min_pos = 1
        ans += (tmp if tmp < INF else 0)
        tmp = INF

if tmp < INF:
    ans += tmp

print(ans)

Solution (Python):
n,t = map(int, input().split( ))
a = list(map(int, input().split( )))
mn = 10**10
mx = 0
cnt_mn = 0
cnt_inf = 0
cnt_sup = 0
for i in range(n):
    if a[i]<mn:
        mn = a[i]
        cnt_mn = 1
    elif a[i] == cnt_mn:
        cnt_mn += 1
    if mx < a[i] - mn:
        mx = a[i] - mn
        cnt_sup = 1
        cnt_inf = cnt_mn
    elif mx == a[i]-mn:
        cnt_sup += 1
        cnt_inf += cnt_mn

print(min(cnt_inf,cnt_sup))

Solution (Python):
n,t=map(int,input().split())
A=list(map(int,input().split()))
a=10**10
b=0
c=0
ans=0
for i in range(n):
  if A[i]<a:
    a=A[i]
    b=0
  if A[i]>b:
    b=A[i]
    if b-a>c:
      c=b-a
      ans=0
    elif b-a==c:
      ans=ans+1
print(ans+1)

Solution (Python):


import sys
input = sys.stdin.readline

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

    maxgain = 0
    time = 0
    maxcost = A[0]
    mincost = A[0]

    for now in A:
        
        maxcost = max(maxcost,now)
        mincost = min(mincost,now)
        temp = now - mincost
        
        if maxgain == temp:
            time += 1
        elif maxgain < temp:
            maxgain = temp
            time = 1
        
        

    print(time)



main()

Solution (Python):
import numpy as np
N,T = map(int,input().split())
A=np.array(input().split(),dtype=np.int32)
s=A-np.minimum.accumulate(A)
print((s==max(s)).sum())

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

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

im = 0
m = 10**20
B = []
C = []
for i,a in enumerate(A):
    if a<m:
        m=a
        im=i
    B.append(a-m)
    C.append(im)

maxB = max(B)
print(len({c for b,c in zip(B,C) if b==maxB}))

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

bl = []

min_a = float("inf")
for a in al:
   min_a = min(a, min_a)
   bl.append(min_a)

cl = []

for a,b in zip(al, bl):
   cl.append(a-b)

cl = sorted(cl)

print(cl.count(cl[-1]))

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

M = max(B)
print(B.count(M))

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

mini = 10**9+1
diff = 0
ans = 1
for i in range(n):
    if a[i] <= mini:
        mini = a[i]

    if diff == a[i] - mini:
        ans += 1
    elif diff < a[i] - mini:
        ans = 1
        diff = a[i] - mini
print(ans)

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

N, T = rl()
A = np.array(rl())
A_cummin = np.minimum.accumulate(A)
B = A - A_cummin

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

Solution (Python):
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

N, T = rl()
A = rl()
answer = 1
profit = 0
min = A[0]
for i in range(1, N):
    if A[i] < min:
        min = A[i]
        continue
    x = A[i] - min
    if x > profit:
        answer = 1
        profit = x
    elif x == profit:
        answer += 1

print(answer)

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

INF = 10**10
L_min = [INF] * N
for i in range(N):
  L_min[i] = min(L_min[i-1], A[i])


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


answer = 0
for i in range(N):
  if P_max == A[i] - L_min[i]:
    answer += 1
print(answer)