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):
from collections import Counter
import sys
sdin = sys.stdin.readline

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


diff_list = [] 
max_list = [] 

mini = max(a)
maxi = a[-1]
max_list = [a[-1]]
for i in range(n-1,0,-1):
    if a[i] > maxi:
        max_list.append(a[i])
        maxi = a[i]
    else:
        max_list.append(maxi)
        
max_list = max_list[::-1]


for i in range(n-1):





        
    diff_list.append(max_list[i]-a[i])
    
cnt = Counter(diff_list)


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

Solution (Python):
INF=999999999

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


res=0
mini=a[0]
best = -INF

for i in range(1,n):
	if a[i]-mini == best:
		res+=1
	elif a[i]-mini > best:
		best=a[i]-mini
		res=1
	mini=min(mini,a[i])
print(res)

Solution (Python):
N, T = map(int, input().split())
A = [int(x) for x in input().split()] + [0]
buy = A[0]
sale = A[0]
benefit = 0
cost = 0
for a in A[1:]:
  if a > sale:
    sale = a
  elif a < buy:
    b = sale - buy
    if b > benefit:
      benefit = b
      cost = 1
    elif b == benefit:
      cost += 1
    buy = a
    sale = a
print(cost)

Solution (Python):

from collections import Counter
from collections import defaultdict
_,_ = map(int, input().split())
a = list(map(int, input().split()))

benefit, min = defaultdict(int), 0
for i in range(len(a)):
    if i == 0 or a[i] <= min:
        min = a[i]
    else:
        benefit[a[i]-min] += 1
print(benefit[max(benefit)])
exit(0)

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

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

B = [x for x in accumulate(A[::-1], max)][::-1]
c = defaultdict(int)
for i in range(N - 1):
    c[B[i] - A[i]] += 1
print(c[max(c)])

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD




dp = None


def main():
    N, T = li_input()
    A = li_input()

    cmin = A[0]
    ans = 0
    maxp = -1

    for i in range(1, len(A)):
        if A[i] < cmin:
            cmin = A[i]
            continue

        if A[i] - cmin > maxp:
            ans = 1
            maxp = A[i] - cmin
        elif A[i] - cmin == maxp:
            ans += 1

    print(ans)


main()

Solution (Python):

"""
Created on Sun Aug 12 14:43:03 2018
ABC947D
@author: maezawa
"""

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

cnt_buy = 0
cnt_sell = 0
buy = 10**9
sell = 2
profit = 0

for i in range(n):
    if a[i] - buy > profit:
        profit = a[i] - buy
        sell = a[i]
    elif a[i] < buy:
        buy = a[i]

buy = 10**9
sell = 2
buys = []
sells = []
i_buy = []

for i in range(n):
    if a[i] - buy == profit:
        buys.extend(i_buy)
        sells.append(i)
    elif a[i] < buy:
        buy = a[i]
        i_buy = [i]
    elif a[i] == buy:
        i_buy.append(i)
    
n_sell = len(set(sells)) 
n_buy = len(set(buys))   
        

print(min(n_sell, n_buy))

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, A):
    ma = [-1] * N
    ma[-1] = A[-1]
    for i in range(N-2, -1, -1):
        ma[i] = max(ma[i+1], A[i])

    c = Counter()
    for i in range(N):
        c[ma[i]-A[i]] += 1

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


def main():
    N, T = read_int_n()
    A = read_int_n()

    print(slv(N, T, A))


if __name__ == '__main__':
    main()

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, A):
    ma = [-1] * N
    ma[-1] = A[-1]
    for i in range(N-2, -1, -1):
        ma[i] = max(ma[i+1], A[i])

    c = Counter()
    for i in range(N):
        c[ma[i]-A[i]] += 1

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


def main():
    N, T = read_int_n()
    A = read_int_n()

    print(slv(N, T, A))


if __name__ == '__main__':
    main()

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

maxA = [min(A)]

for a in A[::-1]:
    maxA.append(max(maxA[-1], a))

del maxA[0]
maxA.reverse()

ans = 0
maxd = 0

for maxa, a in zip(maxA, A):
    d = maxa - a
    if maxd == d:
        ans += 1
    elif maxd < d:
        maxd = d
        ans = 1

print(ans)

Solution (Python):
NT=input()
NT=NT.rstrip().split(" ")
N=int(NT[0])
T=int(NT[1])

cnt=0
sa=0
min=0
max=0

L=input()
L=L.rstrip().split(" ")
min=int(L[0])
for i in range(1,len(L)):
    if int(L[i])<min:
        min=int(L[i])
    s=int(L[i])-min
    if s>sa:
        sa=s
        cnt=1
    elif s==sa:
        cnt+=1
    
    
print(cnt)

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

re = 0
max_dif = 0
A_min = A[0]
for i in range(1, N):
    A_min = min(A_min, A[i-1])
    dif = A[i] - A_min
    if max_dif < dif:
        max_dif = dif
        re = 1
    elif dif == max_dif:
        re += 1

print(re)

Solution (Python):
class Bit:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def ope(self, x, y):
        return max(x, y)

    def update(self, i, v):
        j = i
        while j <= self.n:
            self.data[j] = self.ope(self.data[j], v)
            j += j & -j

    def query(self, i):
        ret = 0
        j = i
        while 0 < j:
            ret = self.ope(self.data[j], ret)
            j &= (j - 1)
        return ret

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

bit = Bit(N)
for i, a in enumerate(reversed(A)):
    bit.update(i + 1, a)

mv, mc = 0, 0
for i in range(N):
    v = bit.query(N - i) - A[i]
    if v > mv:
        mv = v
        mc = 1
    elif v == mv:
        mc += 1
print(mc)

Solution (Python):
N, T = map(int, input().split())
A = [int(Ai) for Ai in input().split()]
Amin = A[0]
Bmax = 0
count = 0
for i in range(1, len(A)):
    Amin = min(A[i-1], Amin)
    Bi = A[i] - Amin
    if Bmax == Bi:
        count += 1
    elif Bmax < Bi:
        Bmax = Bi
        count = 1
print(count)

Solution (Python):
from collections import defaultdict

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

B = [0] * N
for i in range(N - 1):
    a = A[N - i - 1]
    B[i + 1] = max(B[i], a)
B = B[::-1]

c = defaultdict(int)
for i in range(N - 1):
    c[B[i] - A[i]] += 1
print(c[max(c)])

Solution (Python):
a,b=map(int,input().split())
k=list(map(int,input().split()))

sa=0
ans=1

n=k[a-1]

for i in range(a-2,-1,-1):
    if k[i]>n:
        n=k[i]
    tmp=n-k[i]
    if tmp>sa:
        sa=tmp
        ans=1
    elif tmp==sa:
        ans+=1

    

print(ans)

Solution (Python):
from collections import defaultdict

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

min_price = p_list[0]
max_rev = 0
max_dict = defaultdict(int)

for price in p_list[1:]:
  rev = price - min_price
  if rev >= max_rev:
    max_rev = rev
    max_dict[rev] += 1
  if price < min_price:
    min_price = price

max_rev_key = max(max_dict, key=max_dict.get)
min_cost = max_dict[max_rev_key]

print(min_cost)

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


a_min = float("inf")
a_max = 0
a_diff = 0

ans = 0
a_diff = -1

for a in A:

    hasModefied = False
    if a_min > a:
        a_min = a
        a_max = a
    if a_max < a:
        a_max = a
        hasModefied = True
        
    if hasModefied:
        if a_diff == a_max-a_min:
            ans += 1
        elif a_diff < a_max-a_min:
            a_diff = a_max - a_min
            ans = 1
            
print(ans)

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

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

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

diffs = [0]*n
for i in range(n):
    diffs[i] = remain_max[i] - a[i]

max_diff = 0
ans = 0
for i in range(n):
    if diffs[i] > max_diff:
        max_diff = diffs[i]
        ans = 1
    elif diffs[i] == max_diff:
        ans += 1

print(ans)

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

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

diffs1 = [0]*n
for i in range(n):
    diffs1[i] = remain_max[i] - a[i]

max_diff1 = 0
ans1 = 0
for i in range(n):
    if diffs1[i] > max_diff1:
        max_diff1 = diffs1[i]
        ans1 = 1
    elif diffs1[i] == max_diff1:
        ans1 += 1


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

diffs2 = [0]*n
for i in range(n):
    diffs2[i] = a[i] - remain_min[i]

max_diff2 = 0
ans2 = 0
for i in range(n):
    if diffs2[i] > max_diff2:
        max_diff2 = diffs2[i]
        ans2 = 1
    elif diffs2[i] == max_diff2:
        ans2 += 1


print(min(ans1, ans2))

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
mi, ma = float("inf"), 0
d = 0
cnt = 0
for a in A:
    mi = min(mi, a)
    if mi+d < a:
        d = a-mi
        cnt = 1
    elif mi+d == a:
        cnt += 1
print(cnt)

Solution (Python):
n, t = map(int, raw_input().split())
a = map(int, raw_input().split())
min_a = a[0]
max_a = a[0]
max_diff = []
for i in range(1, len(a)):
  if a[i] >= max_a:
    max_a = a[i]
    max_diff.append(max_a-min_a)
  elif a[i] <= min_a:
    min_a = a[i]
    max_a = a[i]

max_d = max(max_diff)
print(len([d for d in max_diff if d == max_d]))

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

m = [0]*n
m[-1] = a[-1]
for i in range(n-2, -1, -1):
    m[i] = max(m[i+1], a[i])

p = m[0]-a[0]
ans = 1
for i in range(1, n):
    if m[i]-a[i] == p:
        ans += 1
    elif m[i]-a[i] > p:
        ans = 1
        p = m[i]-a[i]
print(ans)

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

    if n == 1:
        print(0)
    else:
        min_a, max_prof = a[0], a[1] - a[0]
        cnt, c_lst = 0, []
        for i in range(1, n):
            if a[i] - min_a > max_prof:
                max_prof = a[i] - min_a
                c_lst.append(cnt)
                cnt = 1
            elif a[i] - min_a == max_prof:
                cnt += 1

            if a[i] < min_a:
                min_a = a[i]

        c_lst.append(cnt)

        print(max(c_lst))


if __name__ == '__main__':
    main()

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

max = [0]

for a in A[::-1][:-1]:
  if a > max[-1]:
    max.append(a)
  else:
    max.append(max[-1])

max.reverse()
  
ans = 0
maxp = 0

for i in range(n):
  p = max[i] - A[i]
  if p > maxp:
    ans = 1
    maxp = p
  elif p == maxp:
    ans += 1

print(ans)

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

mincost = src[0]
maxgain = 0
sell = 0
buy = 1
for a in src[1:]:
    if a < mincost:
        mincost = a
        buy = 1
    elif a == mincost:
        buy += 1
    elif a > mincost + maxgain:
        maxgain = a - mincost
        sell = 1
    elif a == mincost + maxgain:
        sell += 1

print(max(sell,buy))

Solution (Python):
n,t = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
amax = [a[-1]]
for i in range(n-2,0,-1): amax.append(max(amax[-1],a[i]))
num,ans,amax = 0,0,amax[::-1]
for i in range(n-1):
	if num<amax[i]-a[i]: ans,num = 1,amax[i]-a[i]
	elif num==amax[i]-a[i]: ans += 1
print(ans)

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

max_benefit = 0
a_min = a[0]
ans = 0
for i in range(1, n):
    if a[i] < a_min:
        a_min = a[i]
    benefit = (a[i] - a_min)
    if  benefit == max_benefit:
        ans += 1
    elif benefit > max_benefit:
        ans = 1
        max_benefit = benefit

print(ans)

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

Solution (Python):
from collections import Counter
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[]
m=10**9
for i in a:
  if i < m:
    m = i
  else:
    b.append(i-m)

ma=max(b)
c=Counter(b)
print(c[ma])

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
minP,prof,pc = 10**9+1,0.5,0
for i in range(N):
    minP = min(minP,A[i])
    d = A[i]-minP
    if d > prof:
        prof = d
        pc = 1
    elif d == prof:
        pc += 1
print(pc)

Solution (Python):
from collections import defaultdict

if __name__ == '__main__':
    nums = [int(x) for x in input().split()]
    N,T = nums[0],nums[1]
    cities = [int(x) for x in input().split()]

    d = defaultdict(int)

    minPrice = 90000000000
    maxProf = -1
    for city in cities:
        minPrice = min(city, minPrice)
        prof = city - minPrice
        d[prof] += 1
        
        maxProf = max(prof,maxProf)
    print(d[maxProf])

Solution (Python):
def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N, T = get_next_ints()
    values = get_next_ints()

    r_values = reversed(values)

    count = 0
    max_val = 0
    max_diff = 0
    for value in r_values:
        if value >= max_val:
            max_val = value
            continue
        diff = max_val - value
        if diff > max_diff:
            max_diff = max_val - value
            count = 1
        elif diff == max_diff:
            count += 1
    print(count)

solve()

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

maxp = 0
minv = float('inf')
ans = 0
for a in A:
    p = a - minv
    if p > maxp:
        maxp = p
        ans = 1
    elif p == maxp:
        ans += 1

    minv = min(minv, a)

print(ans)

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
B = A[::-1]
C = []

maxv = 0
for i in range(N):
    if maxv > B[i]:
        C.append(maxv)
    else:
        maxv = B[i]
        C.append(maxv)

C = C[::-1]

ans = 0
maxv = 0
for i in range(N-1):
    z = C[i] - A[i]
    if maxv > z:
        continue
    elif maxv < z:
        maxv = z
        ans = 1
    else:
        ans += 1

print(ans)

Solution (Python):
from collections import Counter
N,T=map(int, raw_input().split())
A=map(int, raw_input().split())

A_r=[None for i in range(N)]
n=0
for i in range(N-1,-1,-1):
	n=max(A[i],n)
	A_r[i]=n

B=[]
for i in range(N-1):
	B.append(A_r[i+1]-A[i])


C=Counter(B)

print C[max(B)]

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

minA = [(-1,-1)] * (N)
maxA = [(-1,-1)] * (N)

maxA[N-1] = (A[-1],1)
minA[0] = (A[0],1)
for i in range(1,N):
	if A[i] == minA[i-1][0]:
		minA[i] = (A[i],minA[i-1][1]+1)
	else:
		minA[i] = (min(minA[i-1][0],A[i]),1)

	if A[N-i-1] == minA[N-i][0]:
		minA[N-i-1] = (A[N-i-1],minA[N-i][1] + 1)
	else:
		maxA[N-i-1] = (max(maxA[N-i][0],A[N-i-1]),1)

pair = {}
prev = maxA[1][0] - minA[0][0]
for i in range(N-1):
	if prev < (maxA[i+1][0] - minA[i][0]):
		pair = {(maxA[i+1][0],minA[i][0]) : min(maxA[i+1][1],minA[i][1])}
		prev = (maxA[i+1][0] - minA[i][0])
	elif prev == (maxA[i+1][0] - minA[i][0]):
		if (maxA[i+1][0],minA[i][0]) in pair:
			pair[(maxA[i+1][0],minA[i][0])] = max(pair[(maxA[i+1][0],minA[i][0])],min(maxA[i+1][1],minA[i][1]))
		else:
			pair[(maxA[i+1][0],minA[i][0])] = min(maxA[i+1][1],minA[i][1])

print(sum(pair.values()))

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

buy_min=10000000000
max_ben=0
ans=0

for i in range(N):
  if A[i]>buy_min and (A[i]-buy_min)>max_ben:
    ans=1
    max_ben=(A[i]-buy_min)
  elif A[i]>buy_min and (A[i]-buy_min)==max_ben:
    ans+=1
  if buy_min>A[i]:
    buy_min=A[i]
print(ans)

Solution (Python):
def d_AnInvisibleHand(N, T, A):
    min_value = A[0]  
    max_profit = 0  
    ans = 0  
    for i in range(1, N):
        profit = A[i] - min_value  
        if profit > max_profit:
            
            
            max_profit = profit
            ans = 1
        elif profit == max_profit:
            
            
            ans += 1
        min_value = min(min_value, A[i])
    return ans

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

Solution (Python):
N,T = map(int,input().split())
src = list(map(int,input().split()))
minv = src[0]
maxp = ans = 0
for i in range(1,N):
    profit = src[i] - minv
    if profit == maxp:
        ans += 1
    elif profit > maxp:
        maxp = profit
        ans = 1
    minv = min(minv, src[i])

print(ans)

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

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

l = list(map(int, input().split()))
maxdiff = 0
count = 0
currentmin = 10000000000

for i in l:
    if i - currentmin > maxdiff:
        maxdiff = i - currentmin
        count = 1
    elif i - currentmin == maxdiff:
        count += 1
    elif i < currentmin:
        currentmin = i
print(count)

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

current_min = 100000000000000000
current_max_diff = -10000000000000000
max_diff_cnt = 0
for a in A:
  if a - current_min == current_max_diff:
    max_diff_cnt += 1
  if a - current_min > current_max_diff:
    current_max_diff = a - current_min
    max_diff_cnt = 1
  if a < current_min:
    current_min = a

print(max_diff_cnt)

Solution (Python):
from collections import defaultdict


def main():
    N, T = map(int, input().split())
    a_list = list(map(int, input().split()))
    d = defaultdict(int)
    min_a, min_i = a_list[0], 0
    for i in range(1, len(a_list)):
        a = a_list[i]
        d[a - min_a] += 1
        min_a = min(min_a, a)

    print(d[max(d)])

if __name__ == '__main__':
    main()

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

max_diff = 0
count = 0
minv = A[0]

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

Solution (Python):

 
n,t = map(int, raw_input().split())
a = map(int, raw_input().split()) 
 
m = 10**9+1
num = 0
diff = 0
for i in range(n):
    if(a[i]<m):
        m = a[i]
    if(a[i]-m > diff):
        diff = a[i]-m
        num = 1
    elif(a[i]-m == diff):
        num += 1
print(num)

Solution (Python):
N, T = list(map(int, input().split()))
ps = list(map(int, input().split()))
min_p = 99999999999999
max_diff = 0
min_n = 0
 
for i in range(0, N):
    if ps[i] < min_p:
        min_p = ps[i]
    elif max_diff == ps[i] - min_p:
        min_n += 1
    elif max_diff < ps[i] - min_p:
        max_diff = ps[i] - min_p
        min_n = 1
 
print(str(min_n))

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, T = map(int, input().split())
    A = [int(i) for i in input().split()]
    min_v = float('inf')
    max_dif = 0
    ans = 0

    for a in A:
        if min_v > a:
            min_v = a
        else:
            max_dif = max(max_dif, a - min_v)

    

    min_v = float('inf')

    for a in A:
        if min_v > a:
            min_v = a
        else:
            if a - min_v == max_dif:
                ans += 1

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):

N,T = [int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
Max = 0
count = 1
Min = A[0]
for i in range(N):
    if A[i] <= Min :
        Min = A[i]
    else :
        temp = A[i]-Min
        if temp > Max:
            Max = temp 
            count = 1
        elif temp == Max :
            count += 1
print(count)

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

min_list = [0 for i in range(N)]
max_list = [0 for i in range(N)]
min_list[0] = A[0]
max_list[N-1] = A[N-1]
for i in range(1, N):
	min_list[i] = min(min_list[i-1], A[i])
	max_list[N-i-1] = max(max_list[N-i], A[N-i-1])
prof = max([max_list[i+1]-min_list[i] for i in range(N-1)])
count = 0
for i in range(N-1):
	if max_list[i+1]-min_list[i]==prof:
		if count==0:
			pair = (min_list[i], max_list[i+1])
			count = count+1
		elif pair!=(min_list[i], max_list[i+1]):
			pair = (min_list[i], max_list[i+1])
			count = count+1
print(count)

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


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

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

Solution (Python):
nt=input().split(" ")
N=int(nt[0])
T=int(nt[1])


a=input().split(" ")
int_a=[]
maxlist=[]
for i in range(N):
    int_a.append(int(a[i]))

reva=int_a
reva.reverse()
max=0
for i in range(N):
    if reva[i]>max:
        max=reva[i]
    maxlist.append(max)

maxlist.reverse()
int_a.reverse()


max=0
count=1
for i in range(N):
    if maxlist[i]-int_a[i]>max:
        count=1
        max=maxlist[i]-int_a[i]
    elif maxlist[i]-int_a[i]==max:
        count+=1

print(count)

Solution (Python):

import sys
N, T = map(int, raw_input().split())
A = map(int, raw_input().split())
mini = A[0]
maxdlt = 0
count = 0
for n in A:
    
    if mini > n:
        mini = n
    dlt = n - mini
    if dlt == maxdlt:
        count = count + 1
    if dlt != 0:
        if maxdlt < dlt:
            maxdlt = dlt
            count = 1
print(count)

Solution (Python):
input()
A=list(map(int,input().split()))
d,c,s=0,0,A[0]
for x in A[1:]:
 s=min(s,x)
 D=x-s
 if d<D:
  d,c=D,1
 elif D==d:
  c+=1
print(c)

Solution (Python):
raw_input('').split()
A = [int(x) for x in raw_input('').split()]
max = 0
count = 0
pl = 0
msp = A[0]
for i in range(1,len(A)):
  pl_t = pl + A[i] - A[i-1]
  if pl_t <= 0:
    pl = 0
  else:
    pl = pl_t
    if max < pl_t:
      max = pl_t
      count = 1
    elif max == pl_t:
      count += 1
print count

Solution (Python):
N,T = [int(x) for x in raw_input().split(" ")]

A = [int(x) for x in raw_input().split(" ")]

mx = -1e10
cnt = 0
X = []

for i in range(len(A)):
	mx = max(A[-i-1],mx)
	
	dif = mx - A[-i-1]
	
	X.append(dif)



mxx = max(X)

for i in X:
	if i == mxx:
		cnt += 1

print cnt

Solution (Python):
import sys

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

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

cnt = 0
diff = 0
miniA = A[0]
for i in xrange(1, N):
    if A[i] < miniA:
        miniA = A[i]
    if A[i] - miniA > diff:
        diff = A[i] - miniA
        cnt = 1
    elif A[i] - miniA == diff:
        cnt += 1
print cnt

Solution (Python):

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

minv=A[0]
interval=0
cnt=0
for i in A[1:]:
    if i < minv:
        minv=i
    if i-minv > interval:
        interval=i-minv
        cnt=1
    elif i-minv == interval:
        cnt=cnt+1
print(cnt)

Solution (Python):
input()
A=list(map(int,input().split()))
m,B,r=A[0],0,0
for a in A[1:]:
    if a<m:
        m=a
    b=a-m
    if b>B:
        B,r=b,1
    elif b==B:
        r+=1
print(r)