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 in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static List<int[]> ReadPairs(int N)
    {
        List<int[]> ans = new List<int[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadInts); }
        return ans;
    }
    static List<long[]> ReadPairsLong(int N)
    {
        List<long[]> ans = new List<long[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadLongs); }
        return ans;
    }
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    void Multi<T>(out T a) => a = cv<T>(ReadStr);
    void Multi<T, U>(out (T,U) ans)
    {
        var ar = ReadStrs;
        ans =(cv<T>(ar[0]), cv<U>(ar[1]));
    }
    void Multi<T, U, V>(out (T,U,V) ans)
    {
        var ar = ReadStrs; 
        ans =(cv<T>(ar[0]), cv<U>(ar[1]),cv<V>(ar[2]));
    }
    void Multi<T,U>(out T a,out U b)
    {
        var ar = ReadStrs; 
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);
    }
    void Multi<T, U, V>(out T a,out U b,out V c)
    {
        var ar = ReadStrs;
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);  c = cv<V>(ar[2]);
    }
    #endregion

    public static Dictionary<int, int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
        Dictionary<int, int> d = new Dictionary<int, int>();

        while (i * i <= n) //※1
        {
            if (tmp % i == 0)
            {
                tmp /= i;
                if (d.ContainsKey(i)) d[i]++;
                else d.Add(i, 1);
            }
            else
            {
                i++;
            }
        }
        if (tmp != 1)
        {
            if (d.ContainsKey(tmp)) d[tmp]++;
            else d.Add(tmp, 1);
        }
        return d;
    }

    static List<long> Divisor(long N)
    {
        List<long> ans = new List<long>();
        int max = (int)Math.Sqrt(N);
        for (int i = 1; i < max; i++)
        {
            if (N % i == 0)
            {
                ans.Add(i);
                ans.Add(N / i);
            }
        }

        if (N % max == 0)
        {
            if (N / max == max) ans.Add(max);
            else
            {
                ans.Add(max);
                ans.Add(N / max);
            }
        }
        return ans;
    }
    #region Mod
    public static long GetInv(long a, long mod = 1000000007)
    {
        return PowerMod(a, mod - 2, mod);
    }
    public static long Combination(long a, long b, long mod = 1000000007)
    {
        if (b < 0 || b > a) return 0;
        if (b > a / 2) b = a - b;
        long numerator = Factorial(a, mod);
        long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod;

        return (numerator * GetInv(denominator, mod)) % mod;
    }
    public static long Factorial(long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return 1;
        long ans = n;
        for (int i = 2; i < n; i++)
        {
            ans = (ans * i) % mod;
        }

        return ans;
    }
    private static long PowerMod(long a, long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return a;

        long p = PowerMod(a, n / 2, mod);
        if (n % 2 == 1) return ((p * p) % mod * a) % mod;
        else return (p * p) % mod;
    }
    #endregion

    static HashSet<int> Primes(int limit)
    {
        bool[] done = new bool[limit+1];

        var ans = new HashSet<int>();
        for (int i = 2; i <= limit; i++)
        {
            if (done[i]) continue;
            ans.Add(i);
            int index = i;
            while (index<=limit)
            {
                done[index] = true;
                index += i;
            }
        }
        return ans;
    }





    #region SegmentTree

    /// <summary>
    /// 行う演算は結合法則を満たす必要あり
    /// </summary>
    public class SegmentTree<T> where T : IComparable
    {
        /// <summary>
        /// 完全二分木
        /// </summary>
        public T[] Data { get; }

        /// <summary>
        /// 完全二分木に含まれる葉の数
        /// </summary>
        private int LeavesCount { get; }

        /// <summary>
        /// 数列(問題などで与えられる)の要素数
        /// </summary>
        public int Count { get; }

        /// <summary>
        /// 葉のうち使われなかったもの、そしてQueryで引数として取得した範囲がDataのインデックスの外である場合に使う
        /// </summary>
        public T Default { get; }


        public SegmentTree(T[] data, T def)
        {

            //初期値の設定
            Count = data.Length;
            Default = def;
            LeavesCount = (int)Pow(2, Ceiling(Log(data.Length, 2)));
            Data = new T[LeavesCount * 2];
            //

            //完全二分木の全要素を初期化
            for (int i = 0; i < LeavesCount * 2; i++)
            {
                Data[i] = def;
            }

            //dataを用いて必要な要素をすべて埋める
            for (int i = 0; i < data.Length; i++)
            {
                this[i] = data[i];
            }
        }

        public T this[int index]
        {
            get
            {
                //取得したい要素の位置は、実際は LeavesCount-1+index となる
                index = LeavesCount - 1 + index;

                return Data[index];
            }
            set
            {
                //偏光したい要素の位置は、実際は LeavesCount-1+index となる
                index = LeavesCount - 1 + index;

                //子を変更
                Data[index] = value;

                //親たちも含めて、要素を変更
                while (index > 0)
                {
                    //indexを親のインデックスに更新
                    index = GetParentIndex(index);

                    //要素を更新
                    Data[index] = DecideNewElementFromTwoChildren(index);
                }
            }
        }


        /// <summary>
        /// 唯一の親のインデックスを返す
        /// </summary>
        /// <param name="childIndex"></param>
        /// <returns></returns>
        private int GetParentIndex(int childIndex)
        {
            return (childIndex - 1) / 2;
        }

        /// <summary>
        /// 二つの子のインデックスを返す
        /// </summary>
        /// <param name="parentIndex"></param>
        /// <returns>小さいほうはl、大きいほうはr</returns>
        private (int l, int r) GetChildIndexes(int parentIndex)
        {
            return (2 * parentIndex + 1, 2 * parentIndex + 2);
        }

        /// <summary>
        /// 親の値を二つの子から決定する
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private T DecideNewElementFromTwoChildren(int index)
        {
            var children = GetChildIndexes(index);

            return Select(Data[children.l], Data[children.r]);
        }



        /// <summary>
        /// [a,b)の範囲で回答を探す
        /// </summary>
        /// <param name="a"></param>
        /// <param name="halfOpen_b"></param>
        /// <returns></returns>
        public T Query(int a, int halfOpen_b)
        {
            return _Query(a, halfOpen_b, 0, LeavesCount, 0);
        }

        private T _Query(int a, int b, int l, int r, int current)
        {
            //Φ
            if (a >= r || b <= l)
            {
                return Default;
            }
            //部分集合
            else if (a <= l && b >= r)
            {
                return Data[current];
            }
            //一部
            else
            {

                //(1) 範囲[l,r)を分割し、子lの回答と子rの回答を取得
                //(2) 二つの回答を比べて、適切(Selectメソッド)な方を返す


                //(1)
                var children = GetChildIndexes(current);
                T t1 = _Query(a, b, l, (l + r) / 2, children.l);
                T t2 = _Query(a, b, (l + r) / 2, r, children.r);

                //(2)
                return Select(t1, t2);
            }

        }





        /// <summary>
        /// カスタマイズするところ。二つの子の値から、親の値を決定する方法を定める。
        /// </summary>
        /// <param name="t1">子の値1</param>
        /// <param name="t2">子の値2</param>
        /// <returns></returns>
        private T Select(T t1, T t2)
        {
            return t1.CompareTo(t2) < 0 ? t2 : t1;
        }

    }

    #endregion


    static void Main()
    {
        int[] NM = ReadInts;
        int N = NM[0];
        int M = NM[1];

        int[] As = ReadInts;
        int[] max = new int[N - 1];
        max[N - 2] = As[N - 1];

        for (int i = N-3; i >=0; i--)
        {
            max[i] = Max(max[i + 1], As[i+1]);
        }

        int m = 0;
        int c = 0;
        for (int i = 0; i < N-1; i++)
        {
            int diff =  max[i]-As[i];
            if (m < diff)
            {
                m = diff;
                c = 1;
            }
            else if(m == diff)
            {
                c++;
            }
        }


        WriteLine(c);
    }



}