stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstdlib>

using namespace std;



const int maxn = 100010;

int A[maxn],pre[maxn],N,T,best;



inline int gi()

{

	char ch; int ret = 0,f = 1;

	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');

	if (ch == '-') f = -1,ch = getchar();

	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');

	return ret*f;

}



int main()

{

	// freopen("B.in","r",stdin);

	// freopen("B.out","w",stdout);

	N = gi(); T = gi();

	for (int i = 1;i <= N;++i) A[i] = gi();

	pre[0] = 1<<30;

	for (int i = 1;i <= N;++i) pre[i] = min(pre[i-1],A[i]);

	for (int i = 1;i <= N;++i) best = max(best,A[i]-pre[i]);

	int ans = 0;

	for (int i = 1;i <= N;++i) if (A[i]-pre[i] == best) ++ans;

	cout << ans << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int n,a[100010],nowm[100010];



int main()

{

	scanf("%d%*d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	for(int i=n;i;i--)

	{

		nowm[i]=max(nowm[i+1],a[i]);

	}

	int nowans=0;

	for(int i=1;i<=n;i++)

		if(nowm[i]-a[i]>=nowans)nowans=nowm[i]-a[i];

	int ans=0;

	for(int i=1;i<=n;i++)

		if(nowm[i]-a[i]==nowans)ans++;

	printf("%d\n",ans);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;



#define N 100010



int n,Ans,T;

int A[N];

map<int,bool> flag;



inline int read()

{

	int x=0,f=1;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}

	return x*f;

}





int main()

{

	n=read();T=read();

	for(int i=1;i<=n;i++)

	{

		A[i]=read();

	}

	int Min=A[1],Max=0,Ans=0;

	for(int i=2;i<=n;i++)

	{

		int now=A[i]-Min;

		if(now>Max)

			Max=now;

		Min=min(Min,A[i]);

	}

	for(int i=n;i>=1;i--)

	{

		int now=A[i]+Max;

		flag[A[i]]=true;

		if(!flag[now])

			continue;

		Ans++;

	}

	cout<<Ans<<endl;				

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

using namespace std;



typedef long long LL;

const int INF = 1e9 + 10;

int a[1111111];

int n, T;

vector<int> vec1, vec2;



inline int solve(int l, int r, int delta) {

//cout << l << " " << r << endl;

	int s1 = 0, s2 = 0;

	int mina = INF, maxa = -INF;

	for (int i = l; i <= r; ++i) {

		if (a[i] - mina == delta) {

			++s1;

		}

		mina = min(mina, a[i]);

	}

	for (int i = r; i >= l; --i) {

		if (maxa - a[i] == delta) {

			++s2;

		}

		maxa = max(maxa, a[i]);

	}

	return min(s1, s2);

}



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	cin >> n >> T;

	for (int i = 1; i <= n; ++i) {

		cin >> a[i];

	}

	

	int mina = INF, maxa = -INF;

	int delta = 0;

	for (int i = 1; i <= n; ++i) {

		delta = max(delta, a[i] - mina);

		mina = min(mina, a[i]);

	}

	mina = INF;

	int ans = 0, last = 0;

	vec1.clear();

	vec1.push_back(0);

	vec2.clear();

	vec2.push_back(0);

	a[0] = -2; a[n + 1] = -1;

	for (int i = 1; i <= n; ++i) {

		if (a[i] - mina == delta) {

			if (a[i] != a[vec1[vec1.size() - 1]]) {

				vec1.push_back(i);

				vec2.push_back(i);

			} else {

				vec2[vec2.size() - 1] = i;

			}

		}

		mina = min(mina, a[i]);

	}

	vec1.push_back(n + 1);

	vec2.push_back(n + 1);

	for (int i = 1; i + 1 < vec1.size(); ++i) {

		ans += solve(vec2[i - 1] + 1, vec1[i + 1] - 1, delta);

	}

	

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



const int MAXN = 100005;



int n, T;

int a[MAXN];

int mn, mx, cnt;



void input()

{

	scanf("%d%d", &n, &T);

	for(int i = 1; i <= n; i++)

		scanf("%d", &a[i]);

}



void solve()

{

	mn = a[1];

	for(int i = 2; i <= n; i++)

	{

		if(a[i] > mn)

		{

			int tmp = a[i] - mn;

			if(tmp > mx)

			{

				mx = tmp;

				cnt = 1;

			}

			else if(tmp == mx)

			{

				cnt++;

			}

		}

		mn = min(mn, a[i]);

	}

	cout << cnt << endl;

}



void output()

{

}



int main()

{

	input();

	solve();

	output();



	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#define rep(a,b,c) for(int a=b;a<c;a++)

#define rep_(a,b,c) for(int a=c-1;a>=b;a--)

using namespace std;



int main()

{

	cin.sync_with_stdio(false);

	cout.sync_with_stdio(false);

	int a[100005],b[100005],c[100005],n,t,p=0,q=0;

	cin >>n>>t;

	rep(i,0,n) cin >> a[i],b[i]=((i)?min(a[i],b[i-1]):a[i]);

	c[n-1]=a[n-1];rep_(i,0,n-1) c[i]=max(a[i],c[i+1]);

	rep_(i,0,n)

	{

		t=a[i]-b[i];

		if (p<t) p=t,q=0;

		if (p==t) q++;

	}

	int P=0,Q=0;

	rep(i,0,n)

	{

		t=c[i]-a[i];

		if (P<t) P=t,Q=0;

		if (P==t) Q++;

	}

	cout << min(q,Q) << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;



int n, m, a[100005];



int main() {

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++)

		scanf("%d", &a[i]);

	int mn = 1e9 + 7;

	int mx = 0, cnt = 0;

	for (int i = 1; i <= n; i++) {

		if (mn < a[i]) {

			int t = a[i] - mn;

			if (t > mx) {

				mx = t;

				cnt = 1;	

			} else if (t == mx) cnt++;

		}

		mn = min(mn, a[i]);

	}

	printf("%d\n", cnt);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

using namespace std;

const int nMax=1e5+10;

int n,t,a[nMax],ans,cnt;

int main()

{

	scanf("%d%d",&n,&t);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	int Min=a[1];

	ans=0;

	for(int i=2;i<=n;i++)

	{

		if(a[i]-Min>ans)

		{

			ans=a[i]-Min;

			cnt=1;

		}

		else

			if(a[i]-Min==ans)

				cnt++;

		Min=min(Min,a[i]);

	}

	printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>

#include <iostream>

using namespace std;

const int N = 1e5 + 5;

int ls[N], s[N], pos[N], num[N], n, a[N];

int sum[N * 4];

void add(int now, int l, int r, int pos) {

    sum[now]++;

    if(l == r) return;

    int mid = l + r >> 1;

    if(pos <= mid) add(now * 2, l, mid, pos);

    else add(now * 2 + 1, mid + 1, r, pos);

}

bool ask(int now, int l, int r, int L, int R) {

    if(l > R || L > r) return false;

    if(L <= l && r <= R) return (sum[now] != 0);

    int mid = l + r >> 1;

    return ask(now * 2, l, mid, L, R) | ask(now * 2 + 1, mid + 1, r, L, R);

}

bool ask(int pos) {

   return ask(1, 1, n, 1, pos);

}

void add(int pos) {

   add(1, 1, n, pos);

}

bool find(int x, int right) {

    int l = 1, r = n;

    for(int mid = l + r >> 1; l < r; mid = l + r >> 1) {

        if(ls[mid] < x) l = mid + 1;

        else r = mid;

    }

    while(ls[l] > x && l > 0) l--;

    if(l == 0) return false;

   // printf("ask = %d %d %d %d\n", l, ask(l), x, ls[l]);

    return ask(l);

}

bool check(int x) {

   // printf("test = %d\n", x);

    memset(sum, 0, sizeof(sum));

    for (int i = 1; i <= n; i++) {

        if(find(a[i] - x, i)) return true;

        add(num[i]);

        //printf("num = %d\n", num[i]);

        //rem[num[a[i]]] ++; 

    }    

    return false;

}

int main()

{

    int minn = 0, maxn = 0, m;

    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i++) {

        scanf("%d", &a[i]);

        ls[i] = a[i];

        maxn = max(maxn, a[i]);

    }

    sort(ls + 1, ls + n + 1);

    for (int i = 1; i <= n; i++) {  

        num[i] = lower_bound(ls + 1, ls + n + 1, a[i]) - ls;

        pos[num[i]] = i;

        //cerr << num[i] << " "; 

        //

    }

    //cerr << "\n"; 

    //

    int l = minn, r = maxn;

    for (int mid = (l + r) >> 1; l < r; mid = (l + r) >>  1) {

    //printf("%d %d\n", l, r);

        if(check(mid)) l = mid + 1;

        else r = mid;

    }

    if(!check(l)) l--;

    memset(sum, 0, sizeof(sum));

    //printf("%d\n", l);

    int ans = 0;

    for (int i = 1; i <= n; i++) {

        if(find(a[i] - l, i)) ans++;

        add(num[i]);

    }

    printf("%d\n", ans);

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>

#define N 200010

using namespace std;

int a[N], preMin[N];

int main() {

	int n, t, ans = 0, cnt;

	scanf("%d%d", &n, &t);

	preMin[0] = 1000000001;

	for (int i = 1; i <= n; ++i) {

		scanf("%d", &a[i]);

		preMin[i] = min(preMin[i - 1], a[i]);

		if (a[i] - preMin[i] > ans) {

			cnt = 1;

			ans = a[i] - preMin[i];

		}

		else if (a[i] - preMin[i] == ans) {

			cnt++;

		}

	}

	

	printf("%d\n", cnt);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=1e5+5;

map<ll,ll>mp;

ll n,m,x,mi;

int main()

{

	cin>>n>>m;

	cin>>mi;

	for(int i=1;i<n;i++)

	{

		cin>>x;

		mp[x-mi]++;

		mi=min(mi,x);

	}

	ll pnt;

	for(map<ll,ll>::iterator it=mp.begin();it!=mp.end();it++)pnt=it->second;

	cout<<pnt<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

#include <cstdio>

int n,t,a;

int main(){

//	freopen("a.in","r",stdin);

	scanf("%d%d",&n,&t);

	scanf("%d",&a);

	int min1=a,ans=0,maxc=0;

	for(int i=2;i<=n;++i){

		scanf("%d",&a);

		if(a-min1==maxc) ans++;

		if(a-min1>maxc) maxc=a-min1,ans=1;

		if(min1>a) min1=a;

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

    int n,t;

    scanf("%d%d",&n,&t);

    int x,pre;

    int minn,maxx=-999;

    int cnt=1;

    for(int i=0;i<n;i++)

    {

        scanf("%d",&x);

        if(i)

        {

            if(x>pre)

                if(x-minn>maxx)

                    maxx=x-minn,cnt=1;

                else if(x-minn==maxx)

                    cnt++;

            if(minn>x)

                minn=x;

        }

        else

            minn=x;

        pre=x;

    }

    printf("%d\n",cnt);

}


// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

#include <cstdio>

int n,t,a;

int main(){

//	freopen("a.in","r",stdin);

	scanf("%d%d",&n,&t);

	scanf("%d",&a);

	int min1=a,ans=0,maxc=0;

	for(int i=2;i<=n;++i){

		scanf("%d",&a);

		if(a-min1==maxc) ans++;

		if(a-min1>maxc) maxc=a-min1,ans=1;

		if(min1>a) min1=a;

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std ;



#define N 100010

#define inf 0x3f3f3f3f

#define ll long long



int n , t ;

int a[ N ] ;



int main() {

    scanf( "%d%d" , &n , &t ) ;

    for( int i = 1 ; i <= n ; i ++ ) scanf( "%d" ,&a[ i ] ) ;

    int ans = 0 , mx = 0 ;

    int tot = 0 ;

    for( int i = n ; i  ; i -- ) {

        mx = max( a[ i ] , mx ) ;

        ans = max( mx - a[ i ] , ans ) ;

    }

    mx = 0 ;

    for( int i = n ; i ; i -- ) {

        mx = max(  a[ i ] , mx ) ;

        if( mx - a[ i ] == ans ) tot ++ ;

    }

    printf( "%d\n" , tot ) ;

     return 0;

}

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<cstring>

#include<cstdio>

#define ll long long

#define fr(c,a,b) for(int c=a;c<=b;c++)

#define rf(c,a,b) for(int c=a;c>=b;c--)

const int Max=100010;

const int Min=-1;

using std::sort;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

inline int read()

{

	int x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

	return x*f;

}

inline void write(int x)

{

	if(x<0){putchar('-');x=-x;}

	if(x>9)write(x/10);

	putchar(x%10+'0');

}

int n=read(),t=read(),sum,ans,maxn1,maxn2;

int a[Max];

int main()

{

	fr(i,1,n)a[i]=read();

	rf(i,n,1)

	{

		maxn1=max(a[i],maxn1);

		sum=max(maxn1-a[i],sum);

	}

	rf(i,n,1)

	{

		maxn2=max(a[i],maxn2);

		if(maxn2-a[i]==sum)++ans;

	}

	write(ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define LL long long

using namespace std;

const LL MAXN = 1010;

const LL INF = 0x3f3f3f3f;

LL n,m,k,l,an[1001000],bn[1001000],i,x,y,t;

int main()

{

    scanf("%lld %lld",&n,&t);

    LL mi=INF,ma=0;

    for(i=1;i<=n;i++)

    {

     scanf("%lld",&an[i]);

     mi=min(an[i],mi);

     bn[i]=an[i]-mi;

     if(bn[i]==ma) x++;

     if(bn[i]>ma) {ma=bn[i];y=i;x=1;}



    }

    printf("%lld\n",x);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

const int MAXN=110000;

const int INF=0X3F3F3F3F;

int a[MAXN];

int main()

{

//	freopen("D.in", "r", stdin);

//	freopen("D.out", "w", stdout);

	int n, t;

	scanf("%d%d", &n, &t);

	for (int i=1; i<=n; i++) scanf("%d", &a[i]);

	int mx=0, ans=0;

	for (int i=1, mi=INF; i<=n; i++)

	{

		mi=min(mi, a[i]);

		if (a[i]-mi>mx) mx=a[i]-mi, ans=0;

		if (a[i]-mi==mx) ans++;

	}

	printf("%d\n", ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <algorithm>

#define IOS ios::sync_with_stdio(false)

using namespace std;

#define inf (0x3f3f3f3f)

typedef long long int LL;



#include <iostream>

#include <sstream>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <string>

const int maxn = 1e6 + 20;

int dp[maxn];

void work() {

    int n, t;

    scanf("%d%d", &n, &t);

    if (n == 1) while(1);

    int mi = (1LL << 31) - 1;

    int mx = -((1LL << 31) - 1);

    for (int i = 1; i <= n; ++i) {

        int x;

        scanf("%d", &x);

        dp[i] = max(0, x - mi);

        mi = min(mi, x);

        mx = max(mx, dp[i]);

    }

    int tim = 0;

    for (int i = 1; i <= n; ++i) {

        tim += dp[i] == mx;

    }

    int ans = tim;

    cout << ans << endl;

}



int main() {

#ifdef local

    freopen("data.txt","r",stdin);

#endif

    work();

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

const int MAXN=110000;

const int INF=0X3F3F3F3F;

int a[MAXN];

int main()

{

//	freopen("D.in", "r", stdin);

//	freopen("D.out", "w", stdout);

	int n, t;

	scanf("%d%d", &n, &t);

	for (int i=1; i<=n; i++) scanf("%d", &a[i]);

	int mx=0, ans=0;

	for (int i=1, mi=INF; i<=n; i++)

	{

		mi=min(mi, a[i]);

		if (a[i]-mi>mx) mx=a[i]-mi, ans=0;

		if (a[i]-mi==mx) ans++;

	}

	printf("%d\n", ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

using namespace std;



const int offset = 1 << 20;

int st[2 * offset];

int in[offset];



int minimum(int a, int b) {

    a += offset;

    b += offset;



    int rv = 1e9 + 7;

    while(a <= b) {

        if(a % 2 == 1) rv = min(rv, st[a++]);

        if(b % 2 == 0) rv = min(rv, st[b--]);

        a /= 2; b /= 2;

    }

    return rv;

}





void add(int k, int x) {

    k += offset;

    st[k] = x;

    for(k /= 2; k >= 1; k /= 2) {

        st[k] = min(st[k * 2], st[k * 2 + 1]);

    }

}



int main() {

    int n, k;

    scanf("%d %d", &n, &k);



    for(int i = offset; i < offset * 2; i++) st[i] = 1e9 + 7;

    for(int i = 0; i < n; i++) {

        scanf("%d", &in[i]);

        add(i, in[i]);

    }



    int maxx = 0;

    for(int i = 1; i < n; ++i) {

        int v = minimum(0, i - 1);

        if(in[i] - v > maxx) {

           maxx = in[i] - v;

        }

    }



    int res = 0;

    set< int> st;

    st.insert(in[0]);

    for(int i = 1; i < n; ++i) {

        if(st.count(in[i] - maxx)) res++;

        st.insert(in[i]);

    }

    printf("%d\n", res);

}

// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

using namespace std;



const int offset = 1 << 20;

int st[2 * offset];

int in[offset];



int minimum(int a, int b) {

    a += offset;

    b += offset;



    int rv = 1e9 + 7;

    while(a <= b) {

        if(a % 2 == 1) rv = min(rv, st[a++]);

        if(b % 2 == 0) rv = min(rv, st[b--]);

        a /= 2; b /= 2;

    }

    return rv;

}





void add(int k, int x) {

    k += offset;

    st[k] = x;

    for(k /= 2; k >= 1; k /= 2) {

        st[k] = min(st[k * 2], st[k * 2 + 1]);

    }

}



int main() {

    int n, k;

    scanf("%d %d", &n, &k);



    for(int i = 0; i < n; i++) {

        scanf("%d", &in[i]);

        add(i, in[i]);

    }



    int maxx = 0;

    for(int i = 1; i < n; ++i) {

        int v = minimum(0, i - 1);

        if(in[i] - v > maxx) {

           maxx = in[i] - v;

        }

    }



    int res = 0;

    set< int> st;

    st.insert(in[0]);

    for(int i = 1; i < n; ++i) {

        if(st.count(in[i] - maxx)) res++;

        st.insert(in[i]);

    }

    printf("%d\n", res);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



// Header files, namespaces,

// macros as defined above

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>





#define f first

#define s second

#define db long double

#define pb push_back

#define sz(c) (c).size()

#define all(c) (c).begin(),(c).end()



typedef long long ll;

typedef pair <int , int> ii;

typedef pair <ii , int> iii;

typedef vector <int> vi;

typedef vector <ii> vii;

typedef vector <iii> viii;

typedef vector <vi> vvi;

typedef vector <vii> vvii;



const ll mod = 1e9+7;

const int MAXN = 1e4+5;

const int MAXK = 1e2+5;

const db eps = 1e-13;



int memo[MAXN][MAXK], n , k;

string num;

int dp( int pos , int sum , int d , bool ok ) {



    if( !ok && (d > (num[pos]-48)) )

        return 0;



    if( pos == (n-1) ) {

        return sum==0;

    }





    ok |= (d < (num[pos]-48));

    int &res = memo[pos][sum];



    if( ok && res != -1 )

        return res;



    res = 0;



    for( int dig = 0; dig < 10 ; dig++ ) {

        res = ( res + dp( pos+1, (sum + dig)%k , dig , ok ) ) % mod;

    }



    return res;

}





int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

    cout<<setprecision(11)<<fixed;

    memset( memo , -1 , sizeof memo );

    cin>>num;

    n = sz(num);

    cin>>k;



    int ans = 0;

    for( int dig = 0 ; dig < 10 ; dig++ )

        ans = ( ans + dp( 0 , dig%k , dig , false ) )%mod;

    cout<<( ans - 1 + mod ) % mod<<"\n";

}

/*

10

8 5

10 8

6 5

1 5

4 8

2 10

3 6

9 2

1 7

*/

// Optimized solution to the same problem (faster):
//bayemirov                                       

#include <bits/stdc++.h>

 

using namespace std;

 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 

typedef long long ll;

 

#define pb push_back

 

const int MOD = 1e9 + 7;

const int N = 1e5;

 

int dp[N][100];

 

void add(int& x, int y) {

	x += y;

	if (x > MOD) x -= MOD;

}

 

int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	string a;

	cin >> a;

	int b;

	cin >> b;

	int k = a.size();

	dp[0][0] = 1;

	for (int i = 1; i < k; i++) 

		for (int j = 0; j < b; j++) 

			for(int x = 0; x < 10; ++x)

				add(dp[i][j], dp[i - 1][((j - x) % b + b) % b]);

	int ans = 0;

	int sum = 0;

	for (int i = 0; i < k; i++) {

		for (int j = 0; j < (a[i] - '0'); j++)

			add(ans, dp[k - i - 1][((b - sum - j) % b + b) % b]);

		sum += (a[i] - '0');

		sum %= b;

	}

	if(sum == 0)

		ans++;

	cout << ans - 1;

	return 0;

}                    

 

// Fastest known solution for this problem: