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=[int(i) for i in input().split()]
B=[0 for i in range(N)]
B[0]=A[0]
for i in range(1,N):
    B[i]=min([B[i-1],A[i]])
C=[A[i]-B[i] for i in range(N)]
M=max(C)
ans=0
for i in range(N):
    if C[i]==M:
        ans+=1
print(ans)

Solution (Python):
from collections import defaultdict
N,T=map(int,input().split())
A=[int(i) for i in input().split()]
mi=A[0]
s=0
dd=defaultdict(int)
for i in range(1,N):
    mi=min(mi,A[i])
    s=max(A[i]-mi,s)
    dd[A[i]-mi]+=1
print(dd[s])

Solution (Python):
import numpy as np

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

max_num=A[-1]
num_dict = {}
for i in range(len(A)-1):
    
    if(A[-i-1]>max_num):
        max_num=A[-i-1]
    if(max_num > A[-i-2]):
        if(max_num - A[-i-2] in num_dict):
            num_dict[max_num - A[-i-2]] +=1
        else:
            num_dict[max_num - A[-i-2]]=1
key = max(num_dict.keys())
print(num_dict[key])

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

arr = map(int,raw_input().split())

mintable = []
m = float("inf")
for i in arr :
	mintable.append(min(m,i))
	m = min(m,i)

ma = float("-inf")
for i in range(n):
	ma = max(ma,arr[i] - mintable[i])
ans = 0
for i in range(n):
	if arr[i] - mintable[i] == ma:	
		ans += 1

print ans

Solution (Python):
n=int(input().split()[0])
s=input().split()
l=[0 for i in range(n)]
m=[0 for i in range(n)]
M=[0 for i in range(n)]
for i in range(n):
  l[i]=int(s[i])
m[0]=l[0]
M[0]=l[-1]
for i in range(1,n):
  m[i]=min(m[i-1],l[i])
  M[i]=max(M[i-1],l[-i-1])
M.reverse()
d=[M[i]-m[i] for i in range(n)]
ma=max(d)
memo=-1
cnt=0
for i in range(n):
   if d[i]==ma and m[i]!=memo:
      cnt+=1
      memo=m[i]
print(cnt)

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

low = [A[0]]
high = [A[N-1]]
for i in range(1, N):
    low.append(min(A[i], low[i-1]))
for i in reversed(range(N-1)):
    high.append(max(A[i], high[N-2-i]))

high.reverse()
max_gap = max([high[i] - low[i] for i in range(N)])
num = 0
first = True
for i in range(N):
    if high[i] - low[i] == max_gap:
        if first:
            idx = i
            num += 1
            first = False
        else:
            if low[idx] != low[i]:
                idx = i
                num += 1

print(num)

Solution (Python):

def inpl(): return map(int, input().split())
N, T = inpl()
A = tuple(inpl())
m = A[0]
benefit = 0
pairs = 0
ans = 0

for i in range(1, N):
    a = A[i]
    d = a - m
    if d < 0:
        m = a
    elif d < benefit:
        continue
    elif d == benefit:
        pairs += 1
    elif d > benefit:
        ans = max(ans, pairs)
        benefit = d
        pairs = 1

ans = max(ans, pairs)
print(ans)

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

cost_list = np.array(list(map(int, input().split())))

max_num = 0
max_profit = 0
max_list = []
max_value = 0
for x in reversed(cost_list[1:]):
    max_value = max(max_value, x)
    max_list.append(max_value)
max_list = list(reversed(max_list))
max_list = np.array(max_list)
res = max_list - cost_list[:-1]

res_max = max(res)

max_num_list = [y for y in res if y == res_max]

print(len(max_num_list))

Solution (Python):


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

d = 0
ans = 1
l = A[0]
for a in A[1:]:
    l = min(l, a)
    r = a
    if r - l == d:
        ans += 1
    elif r - l > d:
        ans = 1
        d = r - l

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)


class Segtree():
    INT_MIN=-10**9

    def __init__(self,size):
        self.size=1
        while self.size<size:
            self.size=self.size*2
        self.node=[self.INT_MIN]*(2*self.size-1)


    def update(self,k,a):
        k+=self.size-1
        self.node[k]=a
        while k>0:
            k=(k-1)/2
            self.node[k]=max(self.node[k*2+1],self.node[k*2+2])

    def get_max(self,queryL,queryR,k=0,nodeL=0,nodeR=-1):
        if nodeR==-1:nodeR=self.size
        if (nodeR<=queryL or queryR<=nodeL):return self.INT_MIN
        if (queryL<=nodeL and nodeR<=queryR):return self.node[k]
        else:
            nodeM=(nodeL+nodeR)/2
            vl=self.get_max(queryL,queryR,k*2+1,nodeL,nodeM)
            vr=self.get_max(queryL,queryR,k*2+2,nodeM,nodeR)
            return max(vl,vr)

n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
seg=Segtree(n)
for i in xrange(n):
    seg.update(i,a[i])
ans=0
mx=0
for i in xrange(n):
    tmp=seg.get_max(i,n)-a[i]
    if mx<tmp:
        ans=1
        mx=tmp
    elif mx==tmp:
        ans+=1
print ans

Solution (Python):
n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
pos={}
mx=[0]*(n+1)
for i in xrange(n-1,-1,-1):
    mx[i]=max(mx[i+1],a[i])
for i in xrange(n):
    pos[a[i]]=i
a.sort()
ans=0
b=0
for i in xrange(n):
    idx=pos[a[i]]
    if b<mx[idx]-a[i]:
        b=mx[idx]-a[i]
        ans=1
    elif b==mx[idx]-a[i]:
        ans+=1
print ans

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

diff = -1
mini = A[0]
cnt = 0
ans = 0

for i in range(1, N):
	now = A[i]

	if mini > now:
		mini = now
	else:
		if now - mini == diff:
			cnt += 1
		elif now - mini > diff:
			diff = now - mini
			ans = max(ans, cnt)
			cnt = 1
ans = max(ans, cnt)
print(ans)

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

X = [0]*N
for i in xrange(N - 2, -1, -1):
    X[i] = max(X[i + 1], A[i + 1])

mx, cnt = 0, 0
for i, a in enumerate(A):
    tmp = X[i]
    if tmp - a > mx:
        mx = tmp - a
	cnt = 1
    elif tmp - a == mx:
        cnt += 1
print cnt

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):
from numpy import *
input()
a=array(input().split(),dtype=int)
d=a-minimum.accumulate(a)
print((d==d.max()).sum())

Solution (Python):
import numpy as np

input()
a = np.array(input().split(), dtype=np.int)

diff = a - np.minimum.accumulate(a)
print((diff == diff.max()).sum())

Solution (Python):
import unittest

class TestFunc(unittest.TestCase):
    def test_1(self):
        self.assertEqual(fun(5,8,[50,30,40,10,20]),2)
	self.assertEqual(fun(3,2,[100,50,200]),1)
        self.assertEqual(fun(10,100,[7,10,4,5,9,3,6,8,2,1]),2)
        self.assertEqual(fun(5,2,[1,2,3,2,4]),1)

def fun(n,t,a):
    aa = []
    b = None
    s = None
    for i in range(n):
	if b!=None:
            if s==None:
		if b<a[i]:
                    s = a[i]
                else:
                    b = a[i]
            elif s<=a[i]:
                s = a[i]
            elif s>b:
                aa.append(s-b)
		if b>a[i]:
                    b = a[i]
		s = None
	else:
            b = a[i]

    if b!=None and s!= None and s-b>0:
	aa.append(s-b)

    c = aa[0]
    ans = 1
    for i in range(1,len(aa)):
	if c<aa[i]:
            c = aa[i]
            ans = 1
	elif c==aa[i]:
            ans += 1

    return ans


if __name__=='__main__':
    

    n,t = [int(x) for x in raw_input().split(" ")]
    a = [int(x) for x in raw_input().split(" ")]
    print(fun(n,t,a))

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

input_lines = input()
items = input_lines.split()
As = [int(x) for x in items]

def my_func(N, T, As):
    buys = T // 2
    counts = 0
    val_earn = 0
    val_min = 10E10
    for val in As:
        if val < val_min:
            val_min = val
        else:
            diff = val - val_min
            if diff == val_earn:
                counts += 1
            elif diff > val_earn:
                val_earn = diff
                counts = 1
    print(counts)

my_func(N, T, As)

Solution (Python):



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

ans = 0
max_diff = 0
min_a = A[0]
for a in A:
    min_a = min(min_a, a)
    if (a - min_a) == max_diff:
        ans += 1
    elif (a - min_a) > max_diff:
        ans = 1
        max_diff = (a - min_a)
print(ans)

Solution (Python):
def main():
    N, T = [int(x) for x in input().split()]
    price = [int(x) for x in input().split()]

    minprice = 1000000000;
    maxbenefit = 0
    dict = {}
    res = 0

    for i in range(len(price)):
        if (price[i] < minprice): minprice = price[i]
        if (maxbenefit < (price[i] - minprice)): maxbenefit = (price[i] - minprice)
        dict[price[i]] = i

    for i in range(len(price)):
        if price[i] + maxbenefit in dict:
            if (dict[price[i] + maxbenefit] > i): res += 1

    print(res)

if __name__ == "__main__":
    main()

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


N, T = map(int, input().split())
A = list(map(int, input().split()))
p = -1
dif = h = hc = lc = c = 0
for i in A[-2::-1]:
    a, b = A[p], A[p]-i
    if i > a:
        p = -c-2
    elif b >= dif:
        if a != h : h, hc = a, hc+1
        if b > dif : dif, lc = b, 0
        lc += 1
    c += 1
print(min(hc, lc))

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

lowest = a[0]
lowests = {a[0]}
diff = -1
pairs = []

for x in a[1:]:
    if lowest > x:
        lowests = {x}
        lowest = x
    elif lowest == x:
        lowests.add(x)
    elif diff == x - lowest:
        pairs += [(x, y) for y in lowests]
    elif diff < x - lowest:
        pairs = [(x, y) for y in lowests]
        diff = x - lowest

a, b = zip(*pairs)
print(min(len(set(a)), len(set(b))))

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

count = 0
max_profit = A_n[1] - A_n[0]
min_element = min(A_n[0], A_n[1])
for i in xrange(1, len(A_n)):
    if A_n[i] - min_element > max_profit:
        max_profit = A_n[i] - min_element
        count = 0

    if A_n[i] - min_element == max_profit:
        count += 1

    if A_n[i] < min_element:
        min_element = A_n[i]

print count

Solution (Python):
N, T = map(int, input().split())
a = [int(i) for i in input().split()]
b = [a[0]]
m = b[0]
for i in range(1,N):
	if m > a[i]:
		m = a[i]
	b.append(m)
c = [a[i] - b[i] for i in range(N)]
print(c.count(max(c)))

Solution (Python):


N, T = map(int, input().split())
A = list(map(int, input().split()))
pu = -1
SPU = set([])
SPD = []
b = 0
c = 0
for i in A[:-1][::-1]:
    if i > A[pu]:
        pu = -c-2
    elif i < A[pu] and A[pu]-i >= b:
        SPU.add(pu)
        b = A[pu]-i
        SPD += [b]
    c += 1

print(min(len(SPU), SPD.count(b)))

Solution (Python):
from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
highestCount = [1]

for price in prices[-2:-N-1:-1]:
    if price==highestTally[-1]:
        highestCount.append(highestCount[-1]+1)
    else:
        highestCount.append(1)
    highestTally.append(max(highestTally[-1],price))
highestTally.reverse()
highestCount.reverse()

indexOfHighest={}
for i in range(N-1,-1,-1):
    if highestTally[i]==prices[i]:
        indexOfHighest[highestTally[i]]=i

biggestJump=0
sellingPriceForBiggestJump=0
HPcount=0
LPcount=0
HPGroups=[]
LPGroups=[]
for index,price in enumerate(prices):
    if index==N-1:
        break
    bestSellingPrice = highestTally[index+1]
    jump = bestSellingPrice-price
    
    if jump>biggestJump:
        biggestJump = jump
        
        LPGroups=[]
        HPGroups=[]
        
        LPGroups.append(1)
        sellingPriceForBiggestJump = bestSellingPrice
        
        HPGroups.append(highestCount[indexOfHighest[bestSellingPrice]])
    elif jump==biggestJump:
        if bestSellingPrice!=sellingPriceForBiggestJump:
            sellingPriceForBiggestJump = bestSellingPrice
            
            HPGroups.append(highestCount[indexOfHighest[bestSellingPrice]])
            LPGroups.append(0)
        LPGroups[-1]+=1
count = 0
bs = T//2
for a,b in zip(HPGroups,LPGroups):
    if bs>min(a,b):
        count+=min(a,b)
    else:
        count+=bs
print(count)

Solution (Python):
n, t = map(int, raw_input().split())
prices = list(map(int, raw_input().split()))
lows = n * [ 0 ]
low = prices[0] + 1
for i, x in enumerate(prices):
    if x < low:
        low = x
    lows[i] = x
best_gap = 0
best_gap_count = 0
high = prices[-1] - 1
low = lows[-2] + 1
for i in range(len(prices) - 1, 0, -1):
    update = False
    x = prices[i]
    if x > high:
        high = x
        update = True
    if lows[i - 1] != low:
        low = lows[i - 1]
        update = True
    if update:
        gap = high - low
        if gap == best_gap:
            best_gap_count += 1
        elif gap > best_gap:
            best_gap = gap
            best_gap_count = 1
print(best_gap_count)

Solution (Python):


import collections


INF = 10 ** 10


def solve(n, t, xs):
    trades = collections.Counter()
    maxs = [INF for _ in range(n)]
    maxs[n - 1] = xs[n - 1]
    for i in range(n - 1)[::-1]:
        maxs[i] = max(xs[i], maxs[i + 1])
    for i in range(n):
        delta = maxs[i] - xs[i]
        if delta > 0:
            trades[delta] += 1
    max_delta = max(trades.keys())
    return trades[max_delta]


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


if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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


def f():
    n,t = list(map(int,input().split()))
    a = list(map(int,input().split()))
    m = 0
    mc = inf
    r = 0
    for c in a:
        if mc > c:
            mc = c
            continue
        if c - mc > m:
            m = c - mc
            r = 1
            continue
        if c - mc == m:
            r += 1
    return r

print(f())

Solution (Python):
n, t = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
m = a[0]
for i in range(n):
    m = min(m, a[i])
    b[i] = a[i] - m
m = b[0]
k = 0
for i in range(n):
    if b[i] >= m:
        m = b[i]
        k = i
ans1 = 1
for i in range(n):
    if b[i] == m and i != k:
        ans1 += 1
b = [0 for i in range(n)]
m = a[n - 1]
for i in range(n - 1, -1, -1):
    m = max(m, a[i])
    b[i] = a[i] - m
m = b[n - 1]
k = 0
for i in range(n - 1, -1, -1):
    if b[i] <= m:
        m = b[i]
        k = i
ans2 = 1
for i in range(n):
    if b[i] == m and i != k:
        ans2 += 1
print(min(ans1, ans2))

Solution (Python):
import numpy as np
N, T = map(int, raw_input().split())
A_list = map(int, raw_input().split())

dif_dict = dict()

A_min = np.minimum.accumulate(A_list)
A_max = np.maximum.accumulate(A_list[::-1])[::-1]

max_d = (A_max - A_min).max()
print len(set(A_min[max_d ==A_max - A_min]))

Solution (Python):


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

cm = A[0]
cd = 0
cnt = 0
for i in range(1, N):
    if A[i] < cm:
        cm = A[i]
    else:
        d = A[i] - cm
        if d == cd:
            cnt += 1
        elif d > cd:
            cd = d
            cnt = 1
print(cnt)

Solution (Python):
N, T = map(int, input().split())
A = list(map(int, input().split()))
minv = A[0]
maxv = -1
L = [0]
for i in range(1, N):
    if A[i] - minv > maxv:
        L = [i]
        maxv = A[i] - minv
    elif A[i] - minv == maxv:
        L.append(i)
    minv = min(minv, A[i])
print(len(L))

Solution (Python):
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l


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 copy

n, t = map(int, raw_input().split())
a = map(int, raw_input().split())

minA = copy.copy(a)
maxA = copy.copy(a)
for i in range(n-1):
    minA[i+1] = min(minA[i], a[i+1])

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

T = [maxA[i]-minA[i] for i in range(n)]

maxT = max(T)

ans_list = set()
for i in range(n):
    if T[i] == maxT:
        ans_list.add(minA[i])

print len(ans_list)

Solution (Python):
from sys import stdin
from collections import defaultdict
def main():
    n, k = map(int, stdin.readline().split())
    a = map(int, stdin.readline().split())
    mn = 1001001001
    p = 0
    d = defaultdict(int)
    for x in a:
        if mn > x:
            mn = x
        if p < x - mn:
            p = x - mn
        d[x] += 1
    ans = 0
    for x in reversed(a):
        if x not in d:
            continue
        if x - p in d:
            ans += min(d[x], d[x-p])
            d.pop(x-p)
        d[x] -= 1
    print ans
main()

Solution (Python):








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

diff = [0]*N

mini = A[0]
for i in range(1, N):
	now = A[i]
	if now <= mini:
		mini = now
	else:
		diff[i] = now - mini

sa = max(diff)

ans = 0
mini = A[0]
l = 1
r = 0
for i in range(1, N):
	now = A[i]
	if mini == now:
		l += 1
	elif now < mini:
		if r > 0:
			ans += min(l, r)
			r = 0
		mini = now
		l = 1
	else: 
		if now - mini == sa:
			r += 1

if r > 0:
	ans += min(l, r)
print(ans)

Solution (Python):
n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
ma=[a[n-1]]*n
for i in reversed(range(n-1)):
    ma[i]=max(ma[i+1],a[i])
tt=0;cnt=0;u=[]
for i in range(n-1):
    if ma[i+1]-a[i]>=tt:tt=ma[i+1]-a[i]
for i in range(n-1):
    if ma[i+1]-a[i]==tt:u+=[i]
w=max(u)
ans=0
for x in u:
    c=1
    while x+tt in u:c+=2
    ans+=c
print ans

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

a = [int(i) for i in raw_input().split()]

good = []

mmm = []

mmm.append(a[n-1])

for i in range(n-1):
    mmm.append(max(mmm[i],a[n-i-2]))

mmm.reverse()

for i in range(len(a)-1):
    good.append(mmm[i+1]-a[i])

m = max(good)

count = 0

for g in good:
    if g==m:count+=1

print count

Solution (Python):
n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
now=a[0]
cnt=[]
for i in xrange(1,n):
    if now<a[i]:
        cnt.append(a[i]-now)
    else:
        now=a[i]
print(cnt.count(max(cnt)))

Solution (Python):



from __future__ import division, print_function, absolute_import, unicode_literals

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

maxA = [0] * N
minA = [0] * N

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


max_diff = -10000000000
for i in range(N-1):
    max_diff = max(maxA[i] - A[i], max_diff)

cnt = 0
for i in range(N-1):
    if maxA[i] - A[i] == max_diff:
        cnt += 1
print(cnt)

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9


def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N, T = ln()
A = ln()

count = 0
max_diff = -1
minimum = 10**10
for a in A:
    if a < minimum:
        minimum = a
    diff = a - minimum
    if diff > max_diff:
        max_diff = diff
        count = 1
    elif diff == max_diff:
        count += 1

print count

Solution (Python):
import sys

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

As = []
As = list(map(int, sys.stdin.readline().rstrip().split()))

mins = []
m = 1e10
vs = []
for A in As:
    m = min(m, A)
    vs.append(A - m)
max_v = max(vs)
res = 0
for v in vs:
    if v == max_v:
        res += 1
print(res)

Solution (Python):


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

mns = [0] * N
mxs = [0] * N

mns[0] = As[0]
mxs[N-1] = As[N-1]

for i in range(1, N):
    j = N - i - 1
    mns[i] = min(As[i], mns[i-1])
    mxs[j] = max(As[j], mxs[j+1])




mx_diff = -1
pairs = set()
for i in range(1, N):
    diff = mxs[i] - mns[i]
    if diff > mx_diff:
        mx_diff = diff
        pairs.clear()
    if diff >= mx_diff:
        pairs.add((mns[i], mxs[i]))
print(len(pairs))

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

m = 10**10
M = 0
ans = 1
for x in xs:
    if x < m:
        m = x
    elif x - m == M:
        ans += 1
    elif x - m > M:
        ans = 1
        M = x - m

print(ans)

Solution (Python):
N,T = map(int, raw_input().split())
A = map(int, raw_input().split())
x = 10**9
y = 0
ans = 0
for a in A:
    t = a-x
    if t>y:
        y = t
        ans = 0
    if t==y:
        ans += 1
    x = min(x, a)
print ans

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, T) = reads()
A = reads()

B = [0] * N

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

C = [max(A[i] - B[i], 0) for i in range(N)]

M = max(C)
result = sum(c == M for c in C)

print(result)