Problem:
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.

Incorrect submission (verdict: Wrong Answer):
def main():
    n, t = map(int, input().split())
    a = list(map(int, input().split()))

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

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

if __name__ == '__main__':
    main()


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


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


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


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

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

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

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


if __name__ == '__main__':
    main()