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

#include <set>

using namespace std;

const int N=200005;

int n,pre[N],cnex[N];

int h[N],tot;

struct Edge{

	int v,next;

}e[N*2];

int a[N],len,mex[N][2];

inline void addEdge(int u,int v){

	e[++tot]=(Edge){v,h[u]}; h[u]=tot;

}

void readData(){

	scanf("%d",&n);

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

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

		addEdge(pre[i],i);

	}

}

void findCircle(int u){

	static int stk[N],top=0;

	static bool vis[N];

	stk[++top]=u;

	vis[u]=true;

	if(vis[pre[u]]){

		int v=pre[u];

		cnex[v]=u;

		for(;stk[top]!=v;top--){

			cnex[stk[top]]=stk[top-1];

			a[++len]=stk[top];

		}

		a[++len]=v;

		return;

	}

	findCircle(pre[u]);

}

void dfs(int u,int dep){

	for(int i=h[u],v;i;i=e[i].next)

		if((v=e[i].v)!=cnex[u])

			dfs(v,dep+1);

	multiset<int> s;

	s.clear();

	for(int i=h[u],v;i;i=e[i].next)

		if((v=e[i].v)!=cnex[u])

			s.insert(mex[v][0]);

	for(mex[u][0]=0;s.find(mex[u][0])!=s.end();mex[u][0]++);

	if(dep==0)

		for(mex[u][1]=mex[u][0]+1;s.find(mex[u][1])!=s.end();mex[u][1]++);

}

bool run(int x){

	int last=x;

	for(int i=len-1;i>=1;i--){

		int u=a[i];

		last=(mex[u][0]==last)?mex[u][1]:mex[u][0];

	}

	last=(mex[a[len]][0]==last)?mex[a[len]][1]:mex[a[len]][0];

	return x==last;

}

bool judge(){

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

		dfs(a[i],0);

	return run(mex[a[len]][0])||run(mex[a[len]][1]);

}

int main(){

	readData();

	findCircle(1);

	puts(judge()?"POSSIBLE":"IMPOSSIBLE");

	return 0;

}

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

using namespace std;

const int N=200005;

int n,pre[N],cnex[N];

int h[N],tot;

struct Edge{

	int v,next;

}e[N*2];

int a[N],len,mex[N][2];

inline void addEdge(int u,int v){

	e[++tot]=(Edge){v,h[u]}; h[u]=tot;

}

void readData(){

	scanf("%d",&n);

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

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

		addEdge(pre[i],i); 

	}

}

void findCircle(int u){

	static int stk[N],top=0;

	static bool vis[N];

	stk[++top]=u;

	vis[u]=true;

	if(vis[pre[u]]){

		int v=pre[u];

		cnex[v]=u;

		for(;stk[top]!=v;top--){

			cnex[stk[top]]=stk[top-1];

			a[++len]=stk[top];

		}

		a[++len]=v;

		return;

	}

	findCircle(pre[u]);

}

void dfs(int u,int dep){

	for(int i=h[u],v;i;i=e[i].next)

		if((v=e[i].v)!=cnex[u])

			dfs(v,dep+1);

	static int cnt[N];

	for(int i=h[u],v;i;i=e[i].next)

		if((v=e[i].v)!=cnex[u])

			cnt[mex[v][0]]++;

	for(mex[u][0]=0;cnt[mex[u][0]];mex[u][0]++);

	if(dep==0)

		for(mex[u][1]=mex[u][0]+1;cnt[mex[u][1]];mex[u][1]++);

	for(int i=h[u],v;i;i=e[i].next)

		if((v=e[i].v)!=cnex[u])

			cnt[mex[v][0]]--;

}

bool run(int x){

	int last=x;

	for(int i=len-1;i>=1;i--){

		int u=a[i];

		last=(mex[u][0]==last)?mex[u][1]:mex[u][0];

	}

	last=(mex[a[len]][0]==last)?mex[a[len]][1]:mex[a[len]][0];

	return x==last;

}

bool judge(){

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

		dfs(a[i],0);

	return run(mex[a[len]][0])||run(mex[a[len]][1]);

}

int main(){

	readData();

	findCircle(1);

	puts(judge()?"POSSIBLE":"IMPOSSIBLE");

	return 0;

}

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

#include <iostream>

#include <cstdlib>

#include <cstring>

#include <cstdio>

#include <vector>

#define N 200011

using namespace std;

int ti,All[N],siz,tot,indexx[N],dp[N],vist[N],hashh[N],n,fa[N],cir[N],cnt;

vector<int> V[N];

struct apple{

	int v,nxt;

}edge[N*4];

void addedge(int x,int y){

	edge[++tot].v=y;

	edge[tot].nxt=indexx[x];

	indexx[x]=tot;

}

void dfs(int u,int f){

	int t=indexx[u],vv;

	while(t){

		vv=edge[t].v;

		if(!cir[vv] || vv==f){

			dfs(vv,u);

			V[u].push_back(dp[vv]);

		}

		t=edge[t].nxt;

	}

	ti++;

	int len=V[u].size();

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

		hashh[V[u][i]]=ti;

	}

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

		if(hashh[i]!=ti){

			dp[u]=i;

			break;

		}

	}

}

int main(){

	scanf("%d",&n);

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

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

		addedge(fa[i],i);

	}

	int x=1;

	while(1){

		if(vist[x]) break;

		vist[x]=1;

		x=fa[x];

	}

	memset(vist,0,sizeof(vist));

	int u=x;

	while(1){

		if(cir[u]) break;

		cir[u]=1;

		cnt++;

		u=fa[u];

	}

	if(cnt%2==0){

		printf("POSSIBLE");

		return 0;

	}

	u=x;

	while(1){

		if(vist[u]) break;

		vist[u]=1;

		dfs(u,0);

		All[++siz]=dp[u];

		u=fa[u];

	}

	sort(All+1,All+siz+1);

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

		if(All[i]!=All[i+1]){

			printf("POSSIBLE");

			return 0;

		}

	}

	printf("IMPOSSIBLE");

	return 0;

}

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

using namespace std;

#define int long long

inline int read()

{

    int f=1,w=0;char x=0;

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

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

    return w*f;

}

const int N=200010;

const int INF=1e18;

int num_edge,n,Cnt;

int Cir[N],Vis[N],Val[N];

int head[N<<1],fa[N],Jud[N];

struct Edge{int next,to;} edge[N<<1];

inline void Add(int from,int to)

{

	edge[++num_edge].next=head[from];

	edge[num_edge].to=to;

	head[from]=num_edge;

}

inline void Dfs(int pos)

{

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Dfs(edge[i].to);

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Jud[Val[edge[i].to]]=1;

	for(;Jud[Val[pos]];Val[pos]++);

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Jud[Val[edge[i].to]]=0;

}

main(){

	int pos=1;n=read();

	for(int i=1;i<=n;i++) fa[i]=read(),Add(fa[i],i);

	for(;!Vis[pos];pos=fa[pos]) Vis[pos]=1;

	for(;!Cir[pos];pos=fa[pos]) Cir[pos]=1;

	int Max=-1,Min=INF;

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

		if(Cir[i]) Cnt++,Dfs(i),Max=max(Max,Val[i]),Min=min(Min,Val[i]);

	if(Max==Min&&Cnt&1) puts("IMPOSSIBLE");

	else puts("POSSIBLE");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// Code by ajcxsu

// Problem: namori grundy



#include<bits/stdc++.h>

using namespace std;



const int N=2e5+10;

int h[N], to[N], nexp[N], p=1;

inline void ins(int a, int b) { nexp[p]=h[a], h[a]=p, to[p]=b, p++; }



char tak[N], vis[N], viis[N];

int mex[N], smex[N], cir[N], nd[N], fa[N], idx, flag;

void dfs2(int x) {

    int siz=0;

    for(int u=h[x];u;u=nexp[u])

        if(!cir[to[u]]) dfs2(to[u]), ++siz;

    fill(tak, tak+siz+5, 0);

    for(int u=h[x];u;u=nexp[u])

        if(!cir[to[u]]) tak[mex[to[u]]]=1;

    for(mex[x]=0;tak[mex[x]];mex[x]++);

    for(smex[x]=mex[x]+1;tak[smex[x]];smex[x]++);

}



int rm[N];



int main() {

    ios::sync_with_stdio(false), cin.tie(0);

    int n;

    cin>>n;

    int u;

    for(int i=1;i<=n;i++) cin>>fa[i], ins(fa[i], i);

    int na=1, rt;

    while(!vis[na]) vis[na]=1, na=fa[na];

    rt=na;

    do { cir[na]=++idx, nd[idx]=na, na=fa[na]; } while(rt!=na);

    for(int i=1;i<=idx;i++) dfs2(nd[i]);

    rm[1]=mex[nd[1]];

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

        rm[i]=(rm[i-1]==mex[nd[i]]?smex[nd[i]]:mex[nd[i]]);

    if(rm[idx]!=rm[1]) cout<<"POSSIBLE"<<endl, exit(0);

    rm[1]=smex[nd[1]];

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

        rm[i]=(rm[i-1]==mex[nd[i]]?smex[nd[i]]:mex[nd[i]]);

    // for(int i=1;i<=idx;i++) cout<<mex[i]<<" \n"[i==idx];

    if(rm[idx]==mex[nd[1]]) cout<<"POSSIBLE"<<endl;

    else cout<<"IMPOSSIBLE"<<endl;

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

const int N = 200050;

template<typename T>

inline void read(T&x)

{

	T f = 1,c = 0;char ch=getchar();

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

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

	x = f*c;

}

int n,fa[N],hed[N],cnt;

struct EG

{

	int to,nxt;

}e[N];

void ae(int f,int t)

{

	e[++cnt].to = t;

	e[cnt].nxt = hed[f];

	hed[f] = cnt;

}

bool cir[N];

int sta[N],tl;

void get_cir()

{

	int u = 1;

	while(!cir[u])cir[u]=1,u=fa[u];

	memset(cir,0,sizeof(cir));

	while(!cir[u])sta[++tl]=u,cir[u]=1,u=fa[u];

}

int sg[N];

int vis[N],tim;

void dfs(int u)

{

	for(int j=hed[u];j;j=e[j].nxt)

	{

		int to = e[j].to;

		if(!cir[to])dfs(to);

	}

	tim++;

	for(int j=hed[u];j;j=e[j].nxt)

	{

		int to = e[j].to;

		if(!cir[to])vis[sg[to]]=tim;

	}

	sg[u]=0;

	while(vis[sg[u]]==tim)sg[u]++;

}

int main()

{

	read(n);

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

	{

		read(fa[i]);

		ae(fa[i],i);

	}

	get_cir();

	int mx = -1,mn = n+1;

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

		dfs(sta[i]),mx=max(mx,sg[sta[i]]),mn=min(mn,sg[sta[i]]);

	if(mx==mn&&(tl&1))puts("IMPOSSIBLE");

	else puts("POSSIBLE");

	return 0;

}


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

#include <vector>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn = 200005;

int n, fa[maxn], sg[maxn], pos = 1, tot, maxi = -1, mini = 0x3f3f3f3f;

bool vis[maxn], bucket[maxn];

vector<int> e[maxn];

void dfs(int u) {

	for(auto v : e[u]) 

		if(!vis[v]) dfs(v);

	for(auto v : e[u])

		if(!vis[v]) bucket[sg[v]] = true;

	while(bucket[sg[u]]) ++sg[u];

	for(auto v : e[u])

		if(!vis[v]) bucket[sg[v]] = false;

}

int main() {

	ios :: sync_with_stdio(false);

	cin >> n;

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

		cin >> fa[i], e[fa[i]].push_back(i);

	while(!vis[pos]) vis[pos] = true, pos = fa[pos];

	memset(vis, 0, sizeof vis);

	while(!vis[pos]) vis[pos] = true, pos = fa[pos], ++tot;

	if(tot & 1) for(int i = 1; i <= n; ++i)

		if(vis[i]) dfs(i), maxi = max(maxi, sg[i]), mini = min(mini, sg[i]);

	puts(tot & 1 and maxi == mini ? "IMPOSSIBLE" : "POSSIBLE");

}

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

using namespace std;

#define int long long

inline int read()

{

    int f=1,w=0;char x=0;

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

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

    return w*f;

}

const int N=200010;

const int INF=1e18;

int num_edge,n,Cnt;

int Cir[N],Vis[N],Val[N];

int head[N<<1],fa[N],Jud[N];

struct Edge{int next,to;} edge[N<<1];

inline void Add(int from,int to)

{

	edge[++num_edge].next=head[from];

	edge[num_edge].to=to;

	head[from]=num_edge;

}

inline void Dfs(int pos)

{

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Dfs(edge[i].to);

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Jud[Val[edge[i].to]]=1;

	for(;Jud[Val[pos]];Val[pos]++);

	for(int i=head[pos];i;i=edge[i].next)

		if(!Cir[edge[i].to]) Jud[Val[edge[i].to]]=0;

}

main(){

	int pos=1;n=read();

	for(int i=1;i<=n;i++) fa[i]=read(),Add(fa[i],i);

	for(;!Vis[pos];pos=fa[pos]) Vis[pos]=1;

	for(;!Cir[pos];pos=fa[pos]) Cir[pos]=1;

	int Max=-1,Min=INF;

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

		if(Cir[i]) Cnt++,Dfs(i),Max=max(Max,Val[i]),Min=min(Min,Val[i]);

	if(Max==Min&&Cnt&1) puts("IMPOSSIBLE");

	else puts("POSSIBLE");

}


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

#include <cstdio>

#include <cstdlib>

using namespace std;



int ExGCD(int a, int b, int &x, int &y){

    int d=a;

    x=1; y=0;

    if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }

    return d;

}



int main(){

    int n;

    cin >> n;

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

        int a,b;

        cin >> a >> b;

        int x,y,d;

        d = ExGCD(a, b, x, y);

        if(d <= 50000){

            printf("3\n0 0\n%d %d\n%d %d\n", a, b, abs(y), abs(x));

        }else{

            printf("4\n0 0\n%d %d\n%d %d\n%d %d\n", a-1, b, a/d, b/d, a, b-1);

        }

    }

    return 0;

}




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

#include <cstdlib>

using namespace std;



int ExGCD(int a, int b, int &x, int &y){

    int d=a;

    x=1; y=0;

    if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }

    return d;

}



int main(){

    int n;

    scanf("%d", &n);

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

        int a,b;

        scanf("%d%d", &a, &b);

        int x,y,d;

        d = ExGCD(a, b, x, y);

        if(d <= 50000){

            printf("3\n0 0\n%d %d\n%d %d\n", a, b, abs(y), abs(x));

        }else{

            printf("4\n0 0\n%d %d\n%d %d\n%d %d\n", a-1, b, a/d, b/d, a, b-1);

        }

    }

    return 0;

}




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

using namespace std;

int main()

{

    int a,b;

    while(cin>>a>>b)

    {

        if(a==b) cout<<"Yes"<<endl;

        else if((a==4 || a==6 || a==9 || a==11) && (a==b || b==6 || b==9 || b==11))

            cout<<"Yes"<<endl;

        else if((a==1 || a==3 || a==5 || a==7 || a==8 || a==10 || a==12) && (b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12))

            cout<<"Yes"<<endl;

        else cout<<"No"<<endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include<stdlib.h>

int main()

{

	int x,y;

	scanf("%d%d", &x, &y);

	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

	if (days[x - 1] == days[y - 1])

	{

		printf("Yes\n");

	}

	else

	{

		printf("No\n");

	}

	system("pause");

}

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

#include<stdio.h>

using namespace std;

int main()

{

    int a,b;

    while(scanf("%d%d",&a,&b)==2)

    {

        if(a==b)

            printf("Yes\n");

        else if((a==4 || a==6 || a==9 || a==11) && (b==4 || b==6 || b==9 || b==11))

            printf("Yes\n");

         else if((a==1 || a==3 || a==5 || a==7 || a==10|| a==8 || a==12) && (b==1 || b==3 || b==5 || b==7 || b==8|| b==10 || b==12))

            printf("Yes\n");

            else printf("No\n");

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include<stdlib.h>

int main()

{

	int x,y;

	scanf("%d%d", &x, &y);

	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

	if (days[x - 1] == days[y - 1])

	{

		printf("Yes\n");

	}

	else

	{

		printf("No\n");

	}

	system("pause");

}

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

using namespace std;



int main() {

	int x, y, grupx, grupy;

	scanf("%d%d", &x, &y);

	if(x == 2) grupx = 1;

		else if(x == 4 || x == 6 || x == 9 || x == 11) grupx = 2;

		else grupx = 3;

	if(y == 2) grupy = 1;

		else if(y == 4 || y == 6 || y == 9 || y == 11) grupy = 2;

		else grupy = 3;

	if(grupy == grupx) printf("Yes");

	else printf("No");

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>



int main()

{

    int s[7]={1,3,5,7,8,10,12};

    int t[4]={4,6,9,11};

    int i,j,x,y,a,b;

    while(~scanf("%d %d",&x,&y))

    {

        a=0,b=0;

        for(i=0;i<7;i++)

        {

            if(x==s[i]||y==s[i])

            {

                a++;

            }

        }

        for(j=0;j<4;j++)

        {

            if(x==t[j]||y==t[j])

            {

                b++;

            }

        }

        if(a==2||b==2)

        {

            printf("Yes\n");

        }

        else if(x==y)

        {

            printf("Yes\n");

        }

        else

        {

            printf("No\n");

        }

    }

    return 0;

}


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

using namespace std;



int x,y,gx,gy;



int main(){

    cin>>x>>y;

    if(x==2){

        gx=1;

    }else if((x==4)||(x==6)||(x==9)||(x==11)){

        gx=2;

    }else{

        gx=3;

    }



    if(y==2){

        gy=1;

    }else if((y==4)||(y==6)||(y==9)||(y==11)){

        gy=2;

    }else{

        gy=3;

    }



    if(gx==gy){

        cout<<"Yes"<<endl;

    }else{

        cout<<"No"<<endl;

    }

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>



int main()

{

    int s[7]={1,3,5,7,8,10,12};

    int t[4]={4,6,9,11};

    int i,j,x,y,a,b;

    while(~scanf("%d %d",&x,&y))

    {

        a=0,b=0;

        for(i=0;i<7;i++)

        {

            if(x==s[i]||y==s[i])

            {

                a++;

            }

        }

        for(j=0;j<4;j++)

        {

            if(x==t[j]||y==t[j])

            {

                b++;

            }

        }

        if(a==2||b==2)

        {

            printf("Yes\n");

        }

        else if(x==y)

        {

            printf("Yes\n");

        }

        else

        {

            printf("No\n");

        }

    }

    return 0;

}


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

using namespace std;

int main() {

	int n, m;

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

	int tmp = 1e9 + 7, ans = 0, am = 0;

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

		int a;

		scanf("%d", &a);

		tmp = min(a, tmp);

		if (tmp < a) {

			if (a - tmp > am) {

				ans = 1;

				am = a - tmp;

			}

			else if (a - tmp == am) {

				ans ++;

			}

		}

	}

	assert(ans);

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

}




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

#include <algorithm>

#include <cstring>



typedef long long ll;



int n, t, a[100005];



int main() {

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

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

		scanf("%d", a + i);

	

	int mxex = 0, mn = a[1], mx;

	int ans1 = 0, ans2 = 0;

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

		mxex = std::max(mxex, a[i] - mn);

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

	}

	if (mxex == 0) return puts("0"), 0;

	mn = a[1];

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

		if (a[i] - mn == mxex) ++ans1;

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

	}

	mx = a[n];

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

		if (mx - a[i] == mxex) ++ans2;

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

	}

	printf("%d\n", std::min(ans1, ans2));

	

	return 0;

}


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

#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)

#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)

#define re(i,a,n) for(int _tmp=n,i=a;i<_tmp;++i)

#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)

#define For(i,v,u) for(int i=H[u],v=to[i];i;i=nxt[i],v=to[i])

#define si(x) (int)x.size()

#define pb push_back

#define mp make_pair

#define mt make_tuple

#define X first

#define Y second

#define inf 1000000000

using namespace std;

template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}

template<class T> inline void read(T&x,T&y){read(x);read(y);}

template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}

template<class T> inline void MAX(T&x,T y){if(x<y)x=y;}

template<class T> inline void MIN(T&x,T y){if(x>y)x=y;}

typedef long long ll;

typedef pair<int,int> pii;

typedef tuple<int,int,int> tiii;

const int N=111111;

//head

int n,T,a[N],now,mx,cnt;

int main() {

	read(n,T);

	rep(i,1,n)read(a[i]);

	now=a[1];

	rep(i,2,n)if(now<a[i]){

		if(a[i]-now>mx){

			mx=a[i]-now;

			cnt=1;

		}else if(a[i]-now==mx)++cnt;

	}else now=a[i];

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

	return 0;

}


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

#include <algorithm>

#include <cstring>



typedef long long ll;



int n, t, a[100005];



int main() {

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

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

		scanf("%d", a + i);

	

	int mxex = 0, mn = a[1], mx;

	int ans1 = 0, ans2 = 0;

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

		mxex = std::max(mxex, a[i] - mn);

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

	}

	if (mxex == 0) return puts("0"), 0;

	mn = a[1];

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

		if (a[i] - mn == mxex) ++ans1;

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

	}

	mx = a[n];

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

		if (mx - a[i] == mxex) ++ans2;

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

	}

	printf("%d\n", std::min(ans1, ans2));

	

	return 0;

}


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

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <algorithm>

#include <set>

using namespace std;

inline int read()

{

	int res, ok = 1;

	char ch;

	for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())

	if (ch == '-')

	ok = -1;

	res = ch - '0';

	for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())

	res = res * 10 + ch - '0';

	return res * ok;

}

int n, T, a[100005], cnt, num;

set <int> s;

set <int> :: iterator it;

int main()

{

	n = read();

	T = read();

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

	a[i] = read();

	s.insert (a[1]);

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

	{

		it = s.begin();

		int now = *it;

		if (a[i] - now > num)

		{

			num = a[i] - now;

			cnt = 0;

		}

		if (a[i] - now == num)

		cnt++;

		s.insert (a[i]);

	}

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

	return 0;

}

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

#include <algorithm>

#include <cstring>



typedef long long ll;



int n, t, a[100005];



int main() {

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

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

		scanf("%d", a + i);

	

	int mxex = 0, mn = a[1], mx;

	int ans1 = 0, ans2 = 0;

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

		mxex = std::max(mxex, a[i] - mn);

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

	}

	if (mxex == 0) return puts("0"), 0;

	mn = a[1];

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

		if (a[i] - mn == mxex) ++ans1;

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

	}

	mx = a[n];

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

		if (mx - a[i] == mxex) ++ans2;

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

	}

	printf("%d\n", std::min(ans1, ans2));

	

	return 0;

}


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

using namespace std;



const int  maxn=200008;

int n,m; 

int a[maxn];

int main(){

  cin>>n>>m;

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

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

  int dis=0;

  int ans=0;

  int mx=a[n];

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

    {

     

    

      if ((mx-a[i])>dis)

        {

          dis=mx-a[i];

          ans=1;

          continue;

        } 

      

      if (mx-a[i]== dis) 

        {

          ans++;

          continue;

        }

      

      if (a[i]>mx) mx=a[i];

    }

  cout<<ans<<endl;

  return 0;

}

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

#include <algorithm>

#include <cstring>



typedef long long ll;



int n, t, a[100005];



int main() {

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

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

		scanf("%d", a + i);

	

	int mxex = 0, mn = a[1], mx;

	int ans1 = 0, ans2 = 0;

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

		mxex = std::max(mxex, a[i] - mn);

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

	}

	if (mxex == 0) return puts("0"), 0;

	mn = a[1];

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

		if (a[i] - mn == mxex) ++ans1;

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

	}

	mx = a[n];

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

		if (mx - a[i] == mxex) ++ans2;

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

	}

	printf("%d\n", std::min(ans1, ans2));

	

	return 0;

}


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

#include <cstring>

#include <algorithm>

#include <cmath>

#include <vector>

#include <set>

using namespace std;

typedef long long LL;

typedef long double DD;

const int inf = 1e9;

const int mo= 1e9+7;

const int N = 200010;

int n,m,a[N];

set<int> s;



int main(){

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

	int mn=inf,d=0;

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

		scanf("%d", a+i);

		d=max(d,a[i]-mn);

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

	}

	int ans=0;

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

		set<int>::iterator it=s.find(a[i]-d);

		if(it != s.end())

			ans++;

		s.insert(a[i]);

	}

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

	return 0;

}

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

#include <algorithm>

#include <cstring>



typedef long long ll;



int n, t, a[100005];



int main() {

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

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

		scanf("%d", a + i);

	

	int mxex = 0, mn = a[1], mx;

	int ans1 = 0, ans2 = 0;

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

		mxex = std::max(mxex, a[i] - mn);

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

	}

	if (mxex == 0) return puts("0"), 0;

	mn = a[1];

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

		if (a[i] - mn == mxex) ++ans1;

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

	}

	mx = a[n];

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

		if (mx - a[i] == mxex) ++ans2;

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

	}

	printf("%d\n", std::min(ans1, ans2));

	

	return 0;

}


// Fastest known solution for this problem: