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):
def solve(a):
    m, diff, ans = 10 ** 10, 0, 0
    for i in range(len(a)):
        if a[i] < m:
            m = a[i]
        elif a[i] - m > diff:
            diff = a[i] - m
            ans = 1
        elif a[i] - m == diff:
            ans += 1

    return ans


def solve2(a):
    if len(a) <= 3:
        return 1

    base = a[-1]
    m = 10 ** 10
    diff_list = []
    for i in range(len(a) - 2, -1, -1):
        if a[i] >= base:
            diff_list.append(base - m)
            base = a[i]
            m = 10 ** 10
        m = min(m, a[i])
    else:
        diff_list.append(base - m)

    return diff_list.count(max(diff_list))


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

    print(solve2(a))


if __name__ == '__main__':
    main()

Solution (Python):
def solve(a):
    m, diff, ans = 10 ** 10, 0, 0
    for i in range(len(a)):
        if a[i] < m:
            m = a[i]
        elif a[i] - m > diff:
            diff = a[i] - m
            ans = 1
        elif a[i] - m == diff:
            ans += 1

    return ans


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

if __name__ == '__main__':
    main()

Solution (Python):
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min_a = 1000000000
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min_a:
        min_a = a[i]
    elif a[i] - min_a > max_dif:
        max_dif = a[i] - min_a
        max_dif_c = 1
    elif a[i] - min_a == max_dif:
        max_dif_c += 1
print(str(max_dif_c))

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

count = 0
m = a[0]
maxrieki = 0

for i in range(n):
    if( m > a[i]):
        m = a[i]
    else:
        if(maxrieki < (a[i] - m)):
            maxrieki = a[i] - m
            count = 1
        elif(maxrieki != 0 and maxrieki == (a[i]-m)):
            count+=1

print(count)

Solution (Python):
N,T=map(int,raw_input().split())
A=map(int,raw_input().split())
m=A[0]
maxDif=0
c=0
for i in xrange(1,len(A)):
  if A[i]-m>maxDif:
    maxDif=A[i]-m
    c=1
  elif A[i]-m==maxDif:
    c+=1
  m=min(m,A[i])
print c

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

minA = A[0]
benefit = 0
maxBenefit = 0
cost = 0

for i in range(N):
    if A[i] < minA:
        minA = A[i]
    else:
        benefit = A[i] - minA
        if benefit > maxBenefit:
            maxBenefit = benefit
            cost = 1
        elif benefit == maxBenefit:
            cost += 1

print(cost)

Solution (Python):
import numpy as np

if __name__ == "__main__":
	n,t = map(int,raw_input().split())
	li = map(int,raw_input().split())

	minv = li[0]
	dm = 0
	ans = 1
	for i in range(1, len(li)):
		minv = min(minv, li[i])
		if(dm == li[i] - minv):
			ans += 1
		elif(dm < li[i]-minv):
			dm = li[i] - minv
			ans = 1

	print ans

Solution (Python):
def r(): return list(map(int,input().split()))
M=9e9
_=r();a=r()
m=M;D=0
for x in a:
    m=min(m,x)
    D=max(D,x-m)
m=M;y=0
for x in a:
    m=min(m,x)
    y+=(x-m==D)
print(y)

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

N, T = readints()
a = list(readints())

mdiff = 0
mi = 1145141919
for x in a:
    mi = min(mi, x)
    mdiff = max(mdiff, x - mi)

mi = 1145141919
ans = 0
for x in a:
    mi = min(mi, x)
    ans += (x - mi == mdiff)

print(ans)

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

N, T = readints()
a = list(readints())

mdiff = 0
mi = 1145141919
for i in range(N):
    mi = min(mi, a[i])
    mdiff = max(mdiff, a[i] - mi)

mi = 1145141919
ans = 0
for i in range(N):
    mi = min(mi, a[i])
    ans += (a[i] - mi == mdiff)

print(ans)

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

minAi = A[0]
maxDiff = 0
ans = 0
for ai in A[1:]:
    if ai < minAi:
        minAi = ai
    else:
        diff = ai - minAi
        if diff > maxDiff:
            maxDiff = diff
            ans = 1
        elif diff == maxDiff:
            ans += 1

print(ans)

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

count = 0
profit = 0
min_val = num_list[0]

for num in num_list:
    if num < min_val:
        min_val = num
    elif num - min_val == profit:
        count += 1
    elif num - min_val > profit:
        count = 1
        profit = num - min_val

print(count)

Solution (Python):
IS=float('inf')

n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
chk=1
x=IS
y=0
for i in a:
    if x>i:
        x=i
    elif y<i:
        y=i
    if i-x>chk:
        ans=1
    elif i-x==chk:
        ans+=1
    chk=max(chk,i-x)
print ans

Solution (Python):
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
N = int(sizes[0])
T = int(sizes[1])
line = lines[1].split(" ")
inp = []
for i in line:
    inp.append(int(i))

check = []
checkMax = []





    













count=0
for i in range(1,len(inp)):
    if i==1:
        mi = min(inp[0],inp[1])
        ma = inp[1]-inp[0]
        if ma>0:
            count+=1
    elif i>1:
        if ma<inp[i]-mi:
            count=1
            ma=inp[i]-mi
        elif ma==inp[i]-mi:
            count+=1
        mi = min(inp[i],mi)

print (count)

Solution (Python):
def read():
	return [int(i) for i in input().split(' ')]
N, T = read()
A = read()
t_min = A[0]
cost = 1
profit = 0

for p in A:
	if(p < t_min):
		t_min = p
	elif(p - t_min == profit):
		cost += 1
	elif(p - t_min > profit):
		cost = 1
		profit = p - t_min
print(cost)

Solution (Python):


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

p, q = 0, 0
r = A[0]

for i in range(1, N):
	if A[i] < r:
		r = A[i]
	elif A[i] - r > p:
		p = A[i] - r
		q = 1
	elif A[i] - r == p:
		q += 1

print(q)

Solution (Python):
dat = raw_input()
(N,T) = dat.split(" ")

N = int(N)
T = int(T)

dat = raw_input()
A = map(int,dat.split(" "))

diffno = 0

mind = A[0]
maxd = 0

for x in range(1,len(A)):
  if maxd < (A[x] - mind):
    maxd = A[x] - mind
    diffno = 1
  elif maxd == (A[x] - mind):
    diffno += 1

  if mind > A[x]:
    mind = A[x]

print diffno

Solution (Python):
input()
a=[]
for i in input().split():
	a.append(int(i))

maxp = 0
minp = 10000000000000
maxval=0
c=0
for i in range(len(a)):
	if a[i]<minp:
		minp=a[i]
	val=a[i]-minp
	if val>maxval:
		maxval=val
		c=1
	elif val==maxval:
		c+=1

print(c)

Solution (Python):
from collections import defaultdict

n,t=map(int,input().split())
arr=list(map(int,input().split()))
curmax=0
curdiff=0
maxmax=0
dd=defaultdict(int)
for i in range(n):
    curmax=max(arr[n-1-i],curmax)
    curdiff = curmax-arr[n-1-i]
    maxmax=max(maxmax,curdiff)
    if maxmax==curdiff:
        dd[maxmax]+=1
print(dd[maxmax])

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

submax = 0
amin=A[0]
total = 0
for i in range(N):
    if A[i] < amin:
        amin = A[i]
    sub = A[i]-amin
    if sub == submax:
        total += 1
    if sub > submax:
        total = 1
        submax = sub

print(total)

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

mx = 0
mn = l[0]
r = []
for i in range(1,len(l)):
    if mx <= l[i]-mn:
        mx = l[i]-mn
        r.append(mx)
    mn = min(mn,l[i])

e = sorted(r)[len(r)-1]
print(r.count(e))

Solution (Python):



def main():
    n, t = [int(i) for i in raw_input().split()]
    a_list = [int(i) for i in raw_input().split()]
    num_max_gain = 0
    max_gain = 0
    cur_min_cost = a_list[0]
    for i in xrange(1, len(a_list)):
        b_a, a = a_list[i-1], a_list[i]
        if b_a > a:
            cur_min_cost = min(cur_min_cost, a)
        else:
            gain = a-cur_min_cost
            if gain > max_gain:
                num_max_gain = 1
                max_gain = gain
            elif gain == max_gain:
                num_max_gain += 1
    print num_max_gain

if __name__ == '__main__':
    main()

Solution (Python):
n, t = map(int, input().split())
a = list(map(int, input().split()))
maxa = a.pop()
max_rizaya, count = 0, 0
while a:
    ca = a.pop()
    rizaya = maxa - ca
    if rizaya > max_rizaya:
        max_rizaya = rizaya
        count = 1
    elif rizaya == max_rizaya:
        count += 1
    maxa = max(maxa, ca)
print(count)