#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005;
int n,k,m;
LL a[maxn],b[maxn];
LL sumv[maxn<<2][5];
LL dp[maxn][5];

int ID(int x)
{
    int L=1,R=m;
    while(L<R)
	{
		int M=L+(R-L)/2;
		if(b[M]>=x)R=M;
		else L=M+1;
	}
	return L;
}

int p,op;
LL v;

void update(int o,int L,int R)
{
    if(L==R)
	{
		sumv[o][op]+=v;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)update(lc,L,M);
	else update(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
LL query(int o,int L,int R)
{
    if(L==R)return sumv[o][op];
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)return query(lc,L,M);
	else return query(rc,M+1,R);
}
LL c[maxn];
void build(int o,int L,int R)
{
	if(L==R)
	{
		for(int i=1;i<=3;i++)sumv[o][i]=0;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	build(lc,L,M);build(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int main()
{
//	freopen("input.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%I64d",&a[i]);
			b[i]=a[i];
		}
		LL ans=0;

		sort(b+1,b+1+n);
		m=unique(b+1,b+1+n)-b-1;

		build(1,1,m);

		for(int i=1;i<=n;i++)
			for(int j=1;j<=3;j++)dp[i][j]=0;

		for(int i=1;i<=n;i++)
		{
			if(a[i]%k==0)
			{
				p=ID(a[i]/k);
				op=2;
				if(b[p]==a[i]/k)dp[i][3]=query(1,1,m);
				op=1;
				if(b[p]==a[i]/k)dp[i][2]=query(1,1,m);
			}
			dp[i][1]=1;
			p=ID(a[i]);v=dp[i][1];op=1;
			update(1,1,m);
			v=dp[i][2];op=2;
			update(1,1,m);
		}
		for(int i=1;i<=n;i++)ans+=dp[i][3];

		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=100005;
int n,k,m;
LL a[maxn],b[maxn];
LL sumv[maxn<<2][5];
LL dp[maxn][5];
int ID(int x)
{
    int L=1,R=m;
    while(L<R)
	{
		int M=L+(R-L)/2;
		if(b[M]>=x)R=M;
		else L=M+1;
	}
	return L;
}
int p,v,op;
void update(int o,int L,int R)
{
    if(L==R)
	{
		sumv[o][op]+=v;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)update(lc,L,M);
	else update(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int query(int o,int L,int R)
{
    if(L==R)return sumv[o][op];
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)return query(lc,L,M);
	else return query(rc,M+1,R);
}
int c[maxn];
void build(int o,int L,int R)
{
//	cout<<o<<' '<<L<<' '<<R<<' '<<endl;
	if(L==R)
	{
		for(int i=1;i<=3;i++)sumv[o][i]=0;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	build(lc,L,M);build(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int main()
{
//	freopen("input.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			c[i]=a[i];
		}
		LL ans=0;
		int cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]>=0)
				{
					a[++cnt]=c[i];
					b[cnt]=c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;
		if(m)
		{
			build(1,1,m);

			for(int i=1;i<=cnt;i++)for(int j=1;j<=3;j++)dp[i][j]=0;
			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
	//				printf("i=%d p=%d\n",i,p);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);
	//			v=dp[i][3];op=3;
	//			update(1,1,m);
			}

			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

		}

		cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]<0)
				{
					a[++cnt]=-c[i];
					b[cnt]=-c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;

        if(m)
		{
			build(1,1,m);
			for(int i=1;i<=cnt;i++)for(int j=1;j<=3;j++)dp[i][j]=0;

			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
	//				printf("i=%d p=%d\n",i,p);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);
	//			v=dp[i][3];op=3;
	//			update(1,1,m);
			}

			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

		}

		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=100005;
int n,k,m;
LL a[maxn],b[maxn];
LL sumv[maxn<<2][5];
LL dp[maxn][5];
int ID(int x)
{
    int L=1,R=m;
    while(L<R)
	{
		int M=L+(R-L)/2;
		if(b[M]>=x)R=M;
		else L=M+1;
	}
	return L;
}
int p,v,op;
void update(int o,int L,int R)
{
    if(L==R)
	{
		sumv[o][op]+=v;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)update(lc,L,M);
	else update(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int query(int o,int L,int R)
{
    if(L==R)return sumv[o][op];
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)return query(lc,L,M);
	else return query(rc,M+1,R);
}
int main()
{
//	freopen("input.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(int i=1;i<=n;i++){scanf("%d",&a[i]);b[i]=a[i];}
		sort(b+1,b+1+n);
		m=unique(b+1,b+1+n)-b-1;
		memset(sumv,0,sizeof(sumv));
		memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
		{
            if(a[i]%k==0)
			{
				p=ID(a[i]/k);
//				printf("i=%d p=%d\n",i,p);
				op=2;
				if(p>=1&&p<=m)dp[i][3]=query(1,1,n);
//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
				op=1;
				if(p>=1&&p<=m)dp[i][2]=query(1,1,n);
//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
			}
			dp[i][1]=1;
			p=ID(a[i]);v=dp[i][1];op=1;
			update(1,1,n);
			v=dp[i][2];op=2;
			update(1,1,n);
			v=dp[i][3];op=3;
			update(1,1,n);
		}
		LL ans=0;
		for(int i=1;i<=n;i++)ans+=dp[i][3];
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005;
int n,k,m;
LL a[maxn],b[maxn];
LL sumv[maxn<<2][5];
LL dp[maxn][5];

int ID(int x)
{
    int L=1,R=m;
    while(L<R)
	{
		int M=L+(R-L)/2;
		if(b[M]>=x)R=M;
		else L=M+1;
	}
	return L;
}

int p,op;
LL v;

void update(int o,int L,int R)
{
    if(L==R)
	{
		sumv[o][op]+=v;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)update(lc,L,M);
	else update(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
LL query(int o,int L,int R)
{
    if(L==R)return sumv[o][op];
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)return query(lc,L,M);
	else return query(rc,M+1,R);
}
LL c[maxn];
void build(int o,int L,int R)
{
	if(L==R)
	{
		for(int i=1;i<=3;i++)sumv[o][i]=0;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	build(lc,L,M);build(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int main()
{
//	freopen("input.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			c[i]=a[i];
		}
		LL ans=0;

		int cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]>0)
				{
					a[++cnt]=c[i];
					b[cnt]=c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;

		if(m)
		{
			build(1,1,m);

			for(int i=1;i<=cnt;i++)
				for(int j=1;j<=3;j++)dp[i][j]=0;

			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);
			}
			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

		}

		cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]<0)
				{
					a[++cnt]=-c[i];
					b[cnt]=-c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;

        if(m)
		{
			build(1,1,m);

			for(int i=1;i<=cnt;i++)
				for(int j=1;j<=3;j++)dp[i][j]=0;

			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);;
			}
			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

		}

		LL tot=0;
		for(int i=1;i<=n;i++)if(!c[i])tot++;
		if(tot>=3)ans+=tot*(tot-1)/2*(tot-2)/3;

		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=100005;
int n,k,m;
LL a[maxn],b[maxn];
LL sumv[maxn<<2][5];
LL dp[maxn][5];
int ID(int x)
{
    int L=1,R=m;
    while(L<R)
	{
		int M=L+(R-L)/2;
		if(b[M]>=x)R=M;
		else L=M+1;
	}
	return L;
}
int p,v,op;
void update(int o,int L,int R)
{
    if(L==R)
	{
		sumv[o][op]+=v;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)update(lc,L,M);
	else update(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int query(int o,int L,int R)
{
    if(L==R)return sumv[o][op];
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	if(p<=M)return query(lc,L,M);
	else return query(rc,M+1,R);
}
int c[maxn];
void build(int o,int L,int R)
{
//	cout<<o<<' '<<L<<' '<<R<<' '<<endl;
	if(L==R)
	{
		for(int i=1;i<=3;i++)sumv[o][i]=0;
		return;
	}
	int M=L+(R-L)/2;
	int lc=o*2,rc=o*2+1;
	build(lc,L,M);build(rc,M+1,R);
	for(int i=1;i<=3;i++)
		sumv[o][i]=sumv[lc][i]+sumv[rc][i];
}
int main()
{
//	freopen("input.txt","r",stdin);
	while(scanf("%d%d",&n,&k)==2)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			c[i]=a[i];
		}
		LL ans=0;

		int cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]>=0)
				{
					a[++cnt]=c[i];
					b[cnt]=c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;

		if(m)
		{
			build(1,1,m);

			for(int i=1;i<=cnt;i++)
				for(int j=1;j<=3;j++)dp[i][j]=0;

			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
	//				printf("i=%d p=%d\n",i,p);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);
	//			v=dp[i][3];op=3;
	//			update(1,1,m);
			}
//			for(int i=1;i<=cnt;i++)
//			{
//				for(int j=1;j<=3;j++)printf("dp[%d][%d]=%d ",i,j,dp[i][j]);
//				printf("\n");
//			}

			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

			if(k!=1)
			{
				build(1,1,m);

				for(int i=cnt;i>=1;i--)
				{
					if(a[i]%k==0)
					{
						p=ID(a[i]/k);
		//				printf("i=%d p=%d\n",i,p);
						op=2;
						if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
		//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
						op=1;
						if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
		//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
					}
					dp[i][1]=1;
					p=ID(a[i]);v=dp[i][1];op=1;
					update(1,1,m);
					v=dp[i][2];op=2;
					update(1,1,m);
		//			v=dp[i][3];op=3;
		//			update(1,1,m);
				}
	//			for(int i=1;i<=cnt;i++)
	//			{
	//				for(int j=1;j<=3;j++)printf("dp[%d][%d]=%d ",i,j,dp[i][j]);
	//				printf("\n");
	//			}

				for(int i=1;i<=cnt;i++)ans+=dp[i][3];

			}
		}

		cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i]<0)
				{
					a[++cnt]=-c[i];
					b[cnt]=-c[i];
				}
		sort(b+1,b+1+cnt);
		m=unique(b+1,b+1+cnt)-b-1;

        if(m)
		{
			build(1,1,m);

			for(int i=1;i<=cnt;i++)
				for(int j=1;j<=3;j++)dp[i][j]=0;

			for(int i=1;i<=cnt;i++)
			{
				if(a[i]%k==0)
				{
					p=ID(a[i]/k);
	//				printf("i=%d p=%d\n",i,p);
					op=2;
					if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
					op=1;
					if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
	//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
				}
				dp[i][1]=1;
				p=ID(a[i]);v=dp[i][1];op=1;
				update(1,1,m);
				v=dp[i][2];op=2;
				update(1,1,m);
	//			v=dp[i][3];op=3;
	//			update(1,1,m);
			}
//			for(int i=1;i<=cnt;i++)
//			{
//				for(int j=1;j<=3;j++)printf("dp[%d][%d]=%d ",i,j,dp[i][j]);
//				printf("\n");
//			}

			for(int i=1;i<=cnt;i++)ans+=dp[i][3];

			if(k!=1)
			{
				build(1,1,m);

				for(int i=cnt;i>=1;i--)
				{
					if(a[i]%k==0)
					{
						p=ID(a[i]/k);
		//				printf("i=%d p=%d\n",i,p);
						op=2;
						if(p>=1&&p<=m)dp[i][3]=query(1,1,m);
		//				printf("dp[%d][%d]=%I64d\n",i,3,dp[i][3]);
						op=1;
						if(p>=1&&p<=m)dp[i][2]=query(1,1,m);
		//				printf("dp[%d][%d]=%I64d\n",i,2,dp[i][2]);
					}
					dp[i][1]=1;
					p=ID(a[i]);v=dp[i][1];op=1;
					update(1,1,m);
					v=dp[i][2];op=2;
					update(1,1,m);
		//			v=dp[i][3];op=3;
		//			update(1,1,m);
				}
	//			for(int i=1;i<=cnt;i++)
	//			{
	//				for(int j=1;j<=3;j++)printf("dp[%d][%d]=%d ",i,j,dp[i][j]);
	//				printf("\n");
	//			}

				for(int i=1;i<=cnt;i++)ans+=dp[i][3];

			}
		}

		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
struct node{
node*left,*right;
int data; int count;int height;
};
int height(node*a){
if(a==NULL)return 0;
else return a->height;
}
int getb(node*a){
if(a==NULL)return 0;
return height(a->left)-height(a->right);
}
node* leftrotate(node*a){
node*ptr=a->right;
node*ptr1=ptr->left;
a->right=ptr1;
ptr->left=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node* rightrotate(node*a){
node*ptr=a->left;
node*ptr1=ptr->right;
a->left=ptr1;
ptr->right=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node*insert(node*a,node* bn){
if(a==NULL){
a=bn;
return bn;
}else if(a->data<bn->data){
a->right=insert(a->right,bn);
}else if(a->data>bn->data){
a->left=insert(a->left,bn);
}else{
a->count++;
return a;
}
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&a->left->data>bn->data){
return rightrotate(a);
}else if(b>1&&a->left->data<bn->data){
a->left=leftrotate(a->left);
return rightrotate(a);
}
else if(b<-1&&a->right->data<bn->data){
return leftrotate(a);
}else if (b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
node *min(node*a){
node*cur=a;
while(cur->left)cur=cur->left;
return cur;
}
node* del(node*a,node* bn){
if(a==NULL){
return a;
}else if(a->data>bn->data){
a->left=del(a->left,bn);
}else if(a->data<bn->data){
a->right=del(a->right,bn);
}else{
if(a->count>0){
a->count--;return a;
}/*
node*ptr=a;
if(a->left==NULL||a->right==NULL){
node*temp=(a->left)?a->left:a->right;
if(temp==NULL){
a=NULL;
//delete ptr;
}else{
*a=*temp;//delete ptr;
}
}
else{
node*mn=min(a->right);
a->data=mn->data;
a->count=mn->count;
a->right=del(a->right,mn);
}
*/
}
if(a==NULL)return a;
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&getb(a->left)>=0){
return rightrotate(a);
}else if(b>1){
a->left=leftrotate(a->left);
return rightrotate(a);
}else if(b<-1&&getb(a->right)<=0){
return leftrotate(a);
}else if(b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
void inorder(node*a){
if(a==NULL)return;
inorder(a->left);
for(int i=0;i<a->count;i++)cout<<a->data<<" ";
inorder(a->right);
}

int search(node*root,int data){
if(root==NULL)return 0;
if(root->data==data)return root->count;
else if (root->data<data)return search(root->right,data);
else return search(root->left,data);
}
int main(){
int n,k;
cin>>n>>k;
node*l=NULL,*r=NULL;int final=0;node a[n];node b[n];
for(int i=0;i<n;i++){
cin>>a[i].data;
a[i].left=NULL;
a[i].right=NULL;
a[i].height=1;
a[i].count=1;
b[i].data=a[i].data;
b[i].left=NULL;
b[i].right=NULL;
b[i].height=1;
b[i].count=1;
}
for(int i=1;i<n;i++){
r=insert(r,&a[i]);
}
//inorder(r),
//cout<<endl;
l=insert(l,&b[0]);
int s=0;
for(int i=1;i<n-1;i++){
r=del(r,&a[i]);
//cout<<"ho "<<i<<" ";
//inorder(l);
//cout<<endl;
//inorder(r);
//cout<<endl;
if(a[i].data%k==0){
s=search(l,a[i].data/k);
//cout<<s<<endl;
if(s>0){
s*=search(r,b[i].data*k);
}
final+=s;
}

l=insert(l,&b[i]);
}
cout<<final<<endl;
}


#include<iostream>
using namespace std;
struct node{
node*left,*right;
int data; int count;int height;
};
int height(node*a){
if(a==NULL)return 0;
else return a->height;
}
int getb(node*a){
if(a==NULL)return 0;
return height(a->left)-height(a->right);
}
node* leftrotate(node*a){
node*ptr=a->right;
node*ptr1=ptr->left;
a->right=ptr1;
ptr->left=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node* rightrotate(node*a){
node*ptr=a->left;
node*ptr1=ptr->right;
a->left=ptr1;
ptr->right=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node*insert(node*a,node* bn){
if(a==NULL){
a=bn;
return bn;
}else if(a->data<bn->data){
a->right=insert(a->right,bn);
}else if(a->data>bn->data){
a->left=insert(a->left,bn);
}else{
a->count++;
return a;
}
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&a->left->data>bn->data){
return rightrotate(a);
}else if(b>1&&a->left->data<bn->data){
a->left=leftrotate(a->left);
return rightrotate(a);
}
else if(b<-1&&a->right->data<bn->data){
return leftrotate(a);
}else if (b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
node *min(node*a){
node*cur=a;
while(cur->left)cur=cur->left;
return cur;
}
node* del(node*a,node* bn){
if(a==NULL){
return a;
}else if(a->data>bn->data){
a->left=del(a->left,bn);
}else if(a->data<bn->data){
a->right=del(a->right,bn);
}else{
if(a->count>0){
a->count--;return a;
}/*
node*ptr=a;
if(a->left==NULL||a->right==NULL){
node*temp=(a->left)?a->left:a->right;
if(temp==NULL){
a=NULL;
//delete ptr;
}else{
*a=*temp;//delete ptr;
}
}
else{
node*mn=min(a->right);
a->data=mn->data;
a->count=mn->count;
a->right=del(a->right,mn);
}
*/
}
if(a==NULL)return a;
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&getb(a->left)>=0){
return rightrotate(a);
}else if(b>1){
a->left=leftrotate(a->left);
return rightrotate(a);
}else if(b<-1&&getb(a->right)<=0){
return leftrotate(a);
}else if(b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
void inorder(node*a){
if(a==NULL)return;
inorder(a->left);
for(int i=0;i<a->count;i++)cout<<a->data<<" ";
inorder(a->right);
}

int search(node*root,int data){
if(root==NULL)return 0;
if(root->data==data)return root->count;
else if (root->data<data)return search(root->right,data);
else return search(root->left,data);
}
int main(){
int n,k;
cin>>n>>k;
node*l=NULL,*r=NULL;long long  final=0;node a[n];node b[n];
for(int i=0;i<n;i++){
cin>>a[i].data;
a[i].left=NULL;
a[i].right=NULL;
a[i].height=1;
a[i].count=1;
b[i].data=a[i].data;
b[i].left=NULL;
b[i].right=NULL;
b[i].height=1;
b[i].count=1;
}
for(int i=1;i<n;i++){
r=insert(r,&a[i]);
}
//inorder(r),
//cout<<endl;
l=insert(l,&b[0]);
long long s=0;
for(int i=1;i<n-1;i++){
r=del(r,&a[i]);
//cout<<"ho "<<i<<" ";
//inorder(l);
//cout<<endl;
//inorder(r);
//cout<<endl;
if(a[i].data%k==0){
s=search(l,a[i].data/k);
//cout<<s<<endl;
if(s>0){
s*=search(r,b[i].data*k);
}
final+=s;
}

l=insert(l,&b[i]);
}
cout<<final<<endl;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	int data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
node rv[400000];
node rv1[400000];
int used = -1;
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rl(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}node*rr(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}
node*insert(node*a, node* n){
	if (a == NULL){

		//n->left = NULL;
		//n->right = NULL;
		//n->height = 1;
		//n->count = 1;
		return n;
	}
	else if(a->data<n->data){
		a->right = insert(a->right, n);
	}
	else if (a->data > n->data){
		a->left = insert(a->left, n);
	}
	else{
		a->count++;
		return a;
	}
	int data = n->data;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && a->data < data){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && a->data>data){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else {
		return a
			;
	}
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, int data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
		   return a;
		}
		else{
			if (a->left==NULL || a->right==NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height=1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else return a;
}
long long search(node*a, int data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left,data);
	else if (a->data < data)return search(a->right,data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		used++;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		if (i>0)
			right = insert(right, &rv[used]);
		else
			left = insert(left, &rv1[used]);
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}

	for (int i = 1; i < used; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
	}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
//	system("pause");
	return 0;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	long long data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rotatel(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}node*rotater(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rotater(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return rotatel(a);
	}
	else if (b<-1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	return a;
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, long long data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>0){
			a->count--;
			return a;
		}return a;
		/*else{
			if (a->left == NULL || a->right == NULL){
			node*temp = (a->left) ? a->left : a->right;
			if (temp == NULL){
			//temp = rvp[used1];
			//used1--;
			//a->left = NULL;
			//a->right = NULL;
			//a->count = 1;
			//a->height = 1;
			a = NULL;
			//return NULL;
			}
			else{
			a->left = NULL;
			a->right = NULL;
			a->count = 1;
			a->height = 1;
			//*a = *temp;
			return temp;
			}
			}
			else{
			node*mn = min(a->right);
			a->data = mn->data;
			a->count = mn->count;
			a->right = del(a->right, mn->data);
			}
			}
			}*/
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rotatel(a);
	}
	else if (b < -1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rotater(a);
	}
	else if (b>1){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else return a;
}
long long search(node*a, long long data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left, data);
	else if (a->data < data)return search(a->right, data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	node rv[n], rv1[n]; int used;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		//	cout<<"ho " <<i<<" "<<n<<endl;
		used = i;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}
	for (int i = 1; i<n; i++){
		//	cout<<"hmm "<<i<<endl;
		right = insert(right, &rv[i]);
	}
	left = insert(left, &rv1[0]);

	for (int i = 1; i < n - 1; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
		}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;
struct node{
node*left,*right;
int data; int count;int height;
node(int d){
count=1;data=d;height=1;left=NULL;right=NULL;
}
};
int height(node*a){
if(a==NULL)return 0;
else return a->height;
}
int getb(node*a){
if(a==NULL)return 0;
return height(a->left)-height(a->right);
}
node* leftrotate(node*a){
node*ptr=a->right;
node*ptr1=ptr->left;
a->right=ptr1;
ptr->left=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node* rightrotate(node*a){
node*ptr=a->left;
node*ptr1=ptr->right;
a->left=ptr1;
ptr->right=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node*insert(node*a,int data){
if(a==NULL){
node*ptr=new node(data);
a=ptr;
return ptr;
}else if(a->data<data){
a->right=insert(a->right,data);
}else if(a->data>data){
a->left=insert(a->left,data);
}else{
a->count++;
return a;
}
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&a->left->data>data){
return rightrotate(a);
}else if(b>1&&a->left->data<data){
a->left=leftrotate(a->left);
return rightrotate(a);
}
else if(b<-1&&a->right->data<data){
return leftrotate(a);
}else if (b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
node *min(node*a){
node*cur=a;
while(cur->left)cur=cur->left;
return cur;
}
node* del(node*a,int data){
if(a==NULL){
return a;
}else if(a->data>data){
a->left=del(a->left,data);
}else if(a->data<data){
a->right=del(a->right,data);
}else{
if(a->count>1){
a->count--;return a;
}
node*ptr=a;
if(a->left==NULL||a->right==NULL){
node*temp=(a->left)?a->left:a->right;
if(temp==NULL){
a=NULL;
delete ptr;
}else{
*a=*temp;delete ptr;
}
}
else{
node*mn=min(a->right);
a->data=mn->data;
a->right=del(a->right,mn->data);
}

}
if(a==NULL)return a;
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&getb(a->left)>=0){
return rightrotate(a);
}else if(b>1){
a->left=leftrotate(a->left);
return rightrotate(a);
}else if(b<-1&&getb(a->right)<=0){
return leftrotate(a);
}else if(b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
void inorder(node*a){
if(a==NULL)return;
inorder(a->left);
for(int i=0;i<a->count;i++)cout<<a->data<<" ";
inorder(a->right);
}

int search(node*root,int data){
if(root==NULL)return 0;
if(root->data==data)return root->count;
else if (root->data<data)return search(root->right,data);
else return search(root->left,data);
}
int main(){
int n,k;
cin>>n>>k;
int a[n];
node*l=NULL,*r=NULL;int final=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
r=insert(r,a[i]);
}
//inorder(r),
//cout<<endl;
l=insert(l,a[0]);
int s=0;
for(int i=1;i<n-1;i++){
r=del(r,a[i]);
//cout<<"ho "<<i<<" ";
//inorder(l);
//cout<<endl;
//inorder(r);
//cout<<endl;
if(a[i]%k==0){
s=search(l,a[i]/k);
//cout<<s<<endl;
if(s>0){
s*=search(r,a[i]*k);
}
final+=s;
}

l=insert(l,a[i]);
}
cout<<final<<endl;
}


#include<iostream>
using namespace std;
struct node{
node*left,*right;
int data; int count;int height;
};
int height(node*a){
if(a==NULL)return 0;
else return a->height;
}
int getb(node*a){
if(a==NULL)return 0;
return height(a->left)-height(a->right);
}
node* leftrotate(node*a){
node*ptr=a->right;
node*ptr1=ptr->left;
a->right=ptr1;
ptr->left=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node* rightrotate(node*a){
node*ptr=a->left;
node*ptr1=ptr->right;
a->left=ptr1;
ptr->right=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node*insert(node*a,node* bn){
if(a==NULL){
a=bn;
return bn;
}else if(a->data<bn->data){
a->right=insert(a->right,bn);
}else if(a->data>bn->data){
a->left=insert(a->left,bn);
}else{
a->count++;
return a;
}
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&a->left->data>bn->data){
return rightrotate(a);
}else if(b>1&&a->left->data<bn->data){
a->left=leftrotate(a->left);
return rightrotate(a);
}
else if(b<-1&&a->right->data<bn->data){
return leftrotate(a);
}else if (b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
node *min(node*a){
node*cur=a;
while(cur->left)cur=cur->left;
return cur;
}
node* del(node*a,node* bn){
if(a==NULL){
return a;
}else if(a->data>bn->data){
a->left=del(a->left,bn);
}else if(a->data<bn->data){
a->right=del(a->right,bn);
}else{
if(a->count>0){
a->count--;return a;
}/*
node*ptr=a;
if(a->left==NULL||a->right==NULL){
node*temp=(a->left)?a->left:a->right;
if(temp==NULL){
a=NULL;
//delete ptr;
}else{
*a=*temp;//delete ptr;
}
}
else{
node*mn=min(a->right);
a->data=mn->data;
a->count=mn->count;
a->right=del(a->right,mn);
}
*/
}
if(a==NULL)return a;
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&getb(a->left)>=0){
return rightrotate(a);
}else if(b>1){
a->left=leftrotate(a->left);
return rightrotate(a);
}else if(b<-1&&getb(a->right)<=0){
return leftrotate(a);
}else if(b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
void inorder(node*a){
if(a==NULL)return;
inorder(a->left);
for(int i=0;i<a->count;i++)cout<<a->data<<" ";
inorder(a->right);
}

int search(node*root,int data){
if(root==NULL)return 0;
if(root->data==data)return root->count;
else if (root->data<data)return search(root->right,data);
else return search(root->left,data);
}
int main(){
int n,k;
cin>>n>>k;
node*l=NULL,*r=NULL;long long int final=0;node a[n];node b[n];
for(int i=0;i<n;i++){
cin>>a[i].data;
a[i].left=NULL;
a[i].right=NULL;
a[i].height=1;
a[i].count=1;
b[i].data=a[i].data;
b[i].left=NULL;
b[i].right=NULL;
b[i].height=1;
b[i].count=1;
}
for(int i=1;i<n;i++){
r=insert(r,&a[i]);
}
//inorder(r),
//cout<<endl;
l=insert(l,&b[0]);
int s=0;
for(int i=1;i<n-1;i++){
r=del(r,&a[i]);
//cout<<"ho "<<i<<" ";
//inorder(l);
//cout<<endl;
//inorder(r);
//cout<<endl;
if(a[i].data%k==0){
s=search(l,a[i].data/k);
//cout<<s<<endl;
if(s>0){
s*=search(r,b[i].data*k);
}
final+=s;
}

l=insert(l,&b[i]);
}
cout<<final<<endl;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	long long data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node* rl(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node* rr(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}

node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rr(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = rl(a->left);
		return rr(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return rl(a);
	}
	else if (b<-1){
		a->right = rr(a->right);
		return rl(a);
	}
	return a;
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, long long data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
			return a;
		}
		else{
			if (a->left == NULL || a->right == NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height = 1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else return a;
}
long long search(node*a, long long data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left, data);
	else if (a->data < data)return search(a->right, data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	node rv[n], rv1[n]; int used;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		//	cout<<"ho " <<i<<" "<<n<<endl;
		used = i;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}
	for (int i = 1; i<n; i++){
		//	cout<<"hmm "<<i<<endl;
		right = insert(right, &rv[i]);
	}
	left = insert(left, &rv1[0]);

	for (int i = 1; i < n - 1; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
		}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	int count;
	int data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
node rv[400000];
node rv1[400000];
int used = -1;
int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rl(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}node*rr(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}
node*insert(node*a, node* n){
	if (a == NULL){

		n->left = NULL;
		n->right = NULL;
		n->height = 1;
		n->count = 1;
		return n;
	}
	else if(a->data<n->data){
		a->right = insert(a->right, n);
	}
	else if (a->data > n->data){
		a->left = insert(a->left, n);
	}
	else{
		a->count++;
		return a;
	}
	int data = n->data;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && a->data < data){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && a->data>data){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else {
		return a
			;
	}
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, int data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
		   return a;
		}
		else{
			if (a->left==NULL || a->right==NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height=1;
					*a = *temp;
					return a;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else return a;
}
int search(node*a, int data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left,data);
	else if (a->data < data)return search(a->right,data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	int res = 0;
	for (int i = 0; i < n; i++){
		cin >> a;
		used++;
		rv[used].data = a;
		rv1[used].data = a;
		if (i>0)
			right = insert(right, &rv[used]);
		else
			left = insert(left, &rv1[used]);
	}
	for (int i = 1; i < used ; i++){
		right = del(right, rv[i].data);

		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
	}
		int l = search(left, rv[i].data / k);
		int r = search(right, rv[i].data*k);

	//	cout << rv[i].data << " "<<l<<" "<<r<<endl;
		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	long long data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rotatel(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}node*rotater(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rotater(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return rotatel(a);
	}
	else if (b<-1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	return a;
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, long long data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
			return a;
		}
		else{
			if (a->left == NULL || a->right == NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height = 1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rotatel(a);
	}
	else if (b < -1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rotater(a);
	}
	else if (b>1){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else return a;
}
long long search(node*a, long long data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left, data);
	else if (a->data < data)return search(a->right, data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	node rv[n], rv1[n]; int used;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		//	cout<<"ho " <<i<<" "<<n<<endl;
		used = i;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}
	for (int i = 1; i<n; i++){
		//	cout<<"hmm "<<i<<endl;
		right = insert(right, &rv[i]);
	}
	left = insert(left, &rv1[0]);

	for (int i = 1; i < n - 1; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
		}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	int count;
	int data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
node rv[400000];
node rv1[400000];
int used = -1;
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rl(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}node*rr(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}
node*insert(node*a, node* n){
	if (a == NULL){

		//n->left = NULL;
		//n->right = NULL;
		//n->height = 1;
		//n->count = 1;
		return n;
	}
	else if(a->data<n->data){
		a->right = insert(a->right, n);
	}
	else if (a->data > n->data){
		a->left = insert(a->left, n);
	}
	else{
		a->count++;
		return a;
	}
	int data = n->data;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && a->data < data){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && a->data>data){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else {
		return a
			;
	}
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, int data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
		   return a;
		}
		else{
			if (a->left==NULL || a->right==NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height=1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else return a;
}
int search(node*a, int data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left,data);
	else if (a->data < data)return search(a->right,data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	int res = 0;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		used++;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		if (i>0)
			right = insert(right, &rv[used]);
		else
			left = insert(left, &rv1[used]);
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}

	for (int i = 1; i < used; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
	}
		int l = search(left, rv1[i].data / k);
		int r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
//	system("pause");
	return 0;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	int count;
	int data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
node rv[400000];
node rv1[400000];
int used = -1;
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rl(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}node*rr(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	//ptr->count = 1 + count(ptr->left) + count(ptr->right);
	//a->count = 1 + count(a->left) + count(a->right);
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	a->height = 1 + max(height(a->left), height(a->right));
	return ptr;
}
node*insert(node*a, node* n){
	if (a == NULL){

		//n->left = NULL;
		//n->right = NULL;
		//n->height = 1;
		//n->count = 1;
		return n;
	}
	else if(a->data<n->data){
		a->right = insert(a->right, n);
	}
	else if (a->data > n->data){
		a->left = insert(a->left, n);
	}
	else{
		a->count++;
		return a;
	}
	int data = n->data;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && a->data < data){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && a->data>data){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else {
		return a
			;
	}
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, int data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>1){
			a->count--;
		   return a;
		}
		else{
			if (a->left==NULL || a->right==NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height=1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rl(a);
	}
	else if (b < -1){
		a->right = rr(a->right);
		return rl(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rr(a);
	}
	else if (b>1){
		a->left = rl(a->left);
		return rr(a);
	}
	else return a;
}
int search(node*a, int data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left,data);
	else if (a->data < data)return search(a->right,data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		used++;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		if (i>0)
			right = insert(right, &rv[used]);
		else
			left = insert(left, &rv1[used]);
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}

	for (int i = 1; i < used; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
	}
		int l = search(left, rv1[i].data / k);
		int r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
//	system("pause");
	return 0;
}


#include<iostream>
using namespace std;
struct node{
node*left,*right;
long long data; int count;int height;
};
int height(node*a){
if(a==NULL)return 0;
else return a->height;
}
int getb(node*a){
if(a==NULL)return 0;
return height(a->left)-height(a->right);
}
node* leftrotate(node*a){
node*ptr=a->right;
node*ptr1=ptr->left;
a->right=ptr1;
ptr->left=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node* rightrotate(node*a){
node*ptr=a->left;
node*ptr1=ptr->right;
a->left=ptr1;
ptr->right=a;
a->height=1+max(height(a->left),height(a->right));
ptr->height=1+max(height(ptr->left),height(ptr->right));
return ptr;
}
node*insert(node*a,node* bn){
if(a==NULL){
a=bn;
return bn;
}else if(a->data<bn->data){
a->right=insert(a->right,bn);
}else if(a->data>bn->data){
a->left=insert(a->left,bn);
}else{
a->count++;
return a;
}
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&a->left->data>bn->data){
return rightrotate(a);
}else if(b>1&&a->left->data<bn->data){
a->left=leftrotate(a->left);
return rightrotate(a);
}
else if(b<-1&&a->right->data<bn->data){
return leftrotate(a);
}else if (b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
node *min(node*a){
node*cur=a;
while(cur->left)cur=cur->left;
return cur;
}
node* del(node*a,node* bn){
if(a==NULL){
return a;
}else if(a->data>bn->data){
a->left=del(a->left,bn);
}else if(a->data<bn->data){
a->right=del(a->right,bn);
}else{
if(a->count>0){
a->count--;return a;
}/*
node*ptr=a;
if(a->left==NULL||a->right==NULL){
node*temp=(a->left)?a->left:a->right;
if(temp==NULL){
a=NULL;
//delete ptr;
}else{
*a=*temp;//delete ptr;
}
}
else{
node*mn=min(a->right);
a->data=mn->data;
a->count=mn->count;
a->right=del(a->right,mn);
}
*/
}
if(a==NULL)return a;
a->height=1+max(height(a->left),height(a->right));
int b=getb(a);
if(b>1&&getb(a->left)>=0){
return rightrotate(a);
}else if(b>1){
a->left=leftrotate(a->left);
return rightrotate(a);
}else if(b<-1&&getb(a->right)<=0){
return leftrotate(a);
}else if(b<-1){
a->right=rightrotate(a->right);
return leftrotate(a);
}
return a;
}
void inorder(node*a){
if(a==NULL)return;
inorder(a->left);
for(int i=0;i<a->count;i++)cout<<a->data<<" ";
inorder(a->right);
}

int search(node*root,long long data){
if(root==NULL)return 0;
if(root->data==data)return root->count;
else if (root->data<data)return search(root->right,data);
else return search(root->left,data);
}
int main(){
int n,k;
cin>>n>>k;
node*l=NULL,*r=NULL;long long  final=0;node a[n];node b[n];
for(int i=0;i<n;i++){
cin>>a[i].data;
a[i].left=NULL;
a[i].right=NULL;
a[i].height=1;
a[i].count=1;
b[i].data=a[i].data;
b[i].left=NULL;
b[i].right=NULL;
b[i].height=1;
b[i].count=1;
}
for(int i=1;i<n;i++){
r=insert(r,&a[i]);
}
//inorder(r),
//cout<<endl;
l=insert(l,&b[0]);
long long s=0;
for(int i=1;i<n-1;i++){
r=del(r,&a[i]);
//cout<<"ho "<<i<<" ";
//inorder(l);
//cout<<endl;
//inorder(r);
//cout<<endl;
if(a[i].data%k==0){
s=search(l,a[i].data/k);
//cout<<s<<endl;
if(s>0){
s*=search(r,b[i].data*k);
}
final+=s;
}

l=insert(l,&b[i]);
}
cout<<final<<endl;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	long long data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rotatel(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}node*rotater(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rotater(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return rotatel(a);
	}
	else if (b<-1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	return a;
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, long long data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>0){
			a->count--;
			return a;
		}
		/*else{
			if (a->left == NULL || a->right == NULL){
				node*temp = (a->left) ? a->left : a->right;
				if (temp == NULL){
					//temp = rvp[used1];
					//used1--;
					//a->left = NULL;
					//a->right = NULL;
					//a->count = 1;
					//a->height = 1;
					a = NULL;
					//return NULL;
				}
				else{
					a->left = NULL;
					a->right = NULL;
					a->count = 1;
					a->height = 1;
					//*a = *temp;
					return temp;
				}
			}
			else{
				node*mn = min(a->right);
				a->data = mn->data;
				a->count = mn->count;
				a->right = del(a->right, mn->data);
			}
		}
	}*/
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rotatel(a);
	}
	else if (b < -1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rotater(a);
	}
	else if (b>1){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else return a;
}
long long search(node*a, long long data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left, data);
	else if (a->data < data)return search(a->right, data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	node rv[n], rv1[n]; int used;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		//	cout<<"ho " <<i<<" "<<n<<endl;
		used = i;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}
	for (int i = 1; i<n; i++){
		//	cout<<"hmm "<<i<<endl;
		right = insert(right, &rv[i]);
	}
	left = insert(left, &rv1[0]);

	for (int i = 1; i < n - 1; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
		}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;
struct node{
	node*left, *right;
	long long data; int count; int height;
};
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
node* leftrotate(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node* rightrotate(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rightrotate(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = leftrotate(a->left);
		return rightrotate(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return leftrotate(a);
	}
	else if (b<-1){
		a->right = rightrotate(a->right);
		return leftrotate(a);
	}
	return a;
}
node *min(node*a){
	node*cur = a;
	while (cur->left)cur = cur->left;
	return cur;
}
node* del(node*a, node* bn){
	if (a == NULL){
		return a;
	}
	else if (a->data>bn->data){
		a->left = del(a->left, bn);
	}
	else if (a->data<bn->data){
		a->right = del(a->right, bn);
	}
	else{
		if (a->count>0){
			a->count--; return a;
		}/*
		 node*ptr=a;
		 if(a->left==NULL||a->right==NULL){
		 node*temp=(a->left)?a->left:a->right;
		 if(temp==NULL){
		 a=NULL;
		 //delete ptr;
		 }else{
		 *a=*temp;//delete ptr;
		 }
		 }
		 else{
		 node*mn=min(a->right);
		 a->data=mn->data;
		 a->count=mn->count;
		 a->right=del(a->right,mn);
		 }
		 */
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && getb(a->left) >= 0){
		return rightrotate(a);
	}
	else if (b>1){
		a->left = leftrotate(a->left);
		return rightrotate(a);
	}
	else if (b<-1 && getb(a->right) <= 0){
		return leftrotate(a);
	}
	else if (b<-1){
		a->right = rightrotate(a->right);
		return leftrotate(a);
	}
	return a;
}
void inorder(node*a){
	if (a == NULL)return;
	inorder(a->left);
	for (int i = 0; i<a->count; i++)cout << a->data << " ";
	inorder(a->right);
}

int search(node*root, long long data){
	if (root == NULL)return 0;
	if (root->data == data)return root->count;
	else if (root->data<data)return search(root->right, data);
	else return search(root->left, data);
}
int main(){
	int n, k;
	cin >> n >> k;
	node*l = NULL, *r = NULL; long long  final = 0; node a[n]; node b[n];
	for (int i = 0; i<n; i++){
		cin >> a[i].data;
		a[i].left = NULL;
		a[i].right = NULL;
		a[i].height = 1;
		a[i].count = 1;
		b[i].data = a[i].data;
		b[i].left = NULL;
		b[i].right = NULL;
		b[i].height = 1;
		b[i].count = 1;
	}
	for (int i = 1; i<n; i++){
		r = insert(r, &a[i]);
	}
	//inorder(r),
	//cout<<endl;
	l = insert(l, &b[0]);
	long long s = 0;
	for (int i = 1; i<n - 1; i++){
		r = del(r, &a[i]);
		//cout<<"ho "<<i<<" ";
		//inorder(l);
		//cout<<endl;
		//inorder(r);
		//cout<<endl;
		if (a[i].data%k == 0){
			s = search(l, a[i].data / k);
			//cout<<s<<endl;
			if (s>0){
				s *= search(r, b[i].data*k);
			}
			final += s;
		}

		l = insert(l, &b[i]);
	}
	cout << final << endl;
}


// AVLTree.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
using namespace std;
int max(int a, int b){
	return (a > b) ? a : b;
}
struct node{
	node*left;
	node*right;
	long long count;
	long long data;
	int height;
	node(){
		left = NULL;
		right = NULL;
		count = 1;
		data = -1;
		height = 1;
	}

};
//int used1 = -1;
int height(node*a){
	if (a == NULL)return 0;
	else return a->height;
}
int getb(node*a){
	if (a == NULL)return 0;
	return height(a->left) - height(a->right);
}
int count(node*a){
	if (a == NULL)return 0;
	return a->count;
}
node*rotatel(node*a){
	node*ptr = a->right;
	node*ptr1 = ptr->left;
	a->right = ptr1;
	ptr->left = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}node*rotater(node*a){
	node*ptr = a->left;
	node*ptr1 = ptr->right;
	a->left = ptr1;
	ptr->right = a;
	a->height = 1 + max(height(a->left), height(a->right));
	ptr->height = 1 + max(height(ptr->left), height(ptr->right));
	return ptr;
}
node*insert(node*a, node* bn){
	if (a == NULL){
		a = bn;
		return bn;
	}
	else if (a->data<bn->data){
		a->right = insert(a->right, bn);
	}
	else if (a->data>bn->data){
		a->left = insert(a->left, bn);
	}
	else{
		a->count++;
		return a;
	}
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b>1 && a->left->data>bn->data){
		return rotater(a);
	}
	else if (b>1 && a->left->data<bn->data){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else if (b<-1 && a->right->data<bn->data){
		return rotatel(a);
	}
	else if (b<-1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	return a;
}
node* min(node*a){
	if (a == NULL)return NULL;
	while (a->left)a = a->left;
	return a;
}
node *del(node*a, long long data){
	if (a == NULL){
		return NULL;
	}if (a->data > data){
		a->left = del(a->left, data);
	}
	else if (a->data < data){
		a->right = del(a->right, data);
	}
	else{
		if (a->count>0){
			a->count--;
			return a;
		}
		/*else{
			if (a->left == NULL || a->right == NULL){
			node*temp = (a->left) ? a->left : a->right;
			if (temp == NULL){
			//temp = rvp[used1];
			//used1--;
			//a->left = NULL;
			//a->right = NULL;
			//a->count = 1;
			//a->height = 1;
			a = NULL;
			//return NULL;
			}
			else{
			a->left = NULL;
			a->right = NULL;
			a->count = 1;
			a->height = 1;
			//*a = *temp;
			return temp;
			}
			}
			else{
			node*mn = min(a->right);
			a->data = mn->data;
			a->count = mn->count;
			a->right = del(a->right, mn->data);
			}
			}
			}*/
	}
	if (a == NULL)return a;
	a->height = 1 + max(height(a->left), height(a->right));
	int b = getb(a);
	if (b < -1 && getb(a->right) <= 0){
		return rotatel(a);
	}
	else if (b < -1){
		a->right = rotater(a->right);
		return rotatel(a);
	}
	else if (b>1 && getb(a->left) >= 0){
		return rotater(a);
	}
	else if (b>1){
		a->left = rotatel(a->left);
		return rotater(a);
	}
	else return a;
}
long long search(node*a, long long data){
	if (a == NULL)return 0;
	if (a->data > data)return search(a->left, data);
	else if (a->data < data)return search(a->right, data);
	else return a->count;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	node*right = NULL;
	node*left = NULL;
	long long  res = 0;
	node rv[n], rv1[n]; int used;
	//cout << "n" << n << endl;
	for (int i = 0; i < n; i++){
		cin >> a;
		//	cout<<"ho " <<i<<" "<<n<<endl;
		used = i;
		rv[used].data = a;
		rv[used].left = NULL;
		rv[used].right = NULL;
		rv[used].height = 1;
		rv[used].count = 1;
		rv1[used].data = a;
		rv1[used].left = NULL;
		rv1[used].right = NULL;
		rv1[used].height = 1;
		rv1[used].count = 1;
		//cout<<rv[used].data << " " << rv1[used].data <<" "<<used<< endl;
	}
	for (int i = 1; i<n; i++){
		//	cout<<"hmm "<<i<<endl;
		right = insert(right, &rv[i]);
	}
	left = insert(left, &rv1[0]);

	for (int i = 1; i < n - 1; i++){
		//cout << rv[i].data << " " << " " << endl;
		right = del(right, rv[i].data);

		//cout <<"ho "<< i << " "<<used << endl;
		if (rv[i].data%k != 0){

			left = insert(left, &rv1[i]);
			continue;
		}
		long long l = search(left, rv1[i].data / k);
		long long r = search(right, rv[i].data*k);

		res += (l*r);
		left = insert(left, &rv1[i]);
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair <int, int> pii;
const int INF = 1000000000;
#define mp(x,y) make_pair((x),(y))

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long tot = 0;
    map <pii, int> mmap;

    for (int i = n-1; i >= 0; i--){
	int num = arr[i];
	if (num == 0) continue;
	long long mul = (long long) num * k;
	if (mul <= INF && mul >= -INF){
	    if (mmap.count(mp(mul, 1))){
		tot += mmap[mp(mul, 1)];
	    }
	    if (mmap.count(mp(mul, 0))){
		mmap[ mp(num, 1) ] += mmap[ mp(mul, 0) ];
	    }
	}
	mmap[mp(num, 0)]++;
    }
    cout << tot << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, div;
    cin >> n >> div;
    vector <int> arr(n);
    for (int i = 0; i < n; i++){
	cin >> arr[i];
    }
    long long tot = 0;
    for (int i = 0; i < n; i++)
	for (int j = i+1; j < n; j++)
	    for (int k = j + 1; k < n; k++){
		if (arr[k] % arr[j] == 0 && arr[k] / arr[j] == div){
		    if (arr[j] % arr[i] == 0 && arr[j] / arr[i] == div)
			tot++;
		}
	    }

    cout << tot << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair <int, int> pii;
const int INF = 1000000000;
#define mp(x,y) make_pair((x),(y))

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long tot = 0;
    map <pii, int> mmap;

    for (int i = n-1; i >= 0; i--){
	int num = arr[i];
	long long mul = (long long) num * k;
	if (mul <= INF && mul >= -INF){
	    if (mmap.count(mp(mul, 1))){
		tot += mmap[mp(mul, 1)];
	    }
	    if (mmap.count(mp(mul, 0))){
		mmap[ mp(num, 1) ] += mmap[ mp(mul, 0) ];
	    }
	}
	mmap[mp(num, 0)]++;
    }
    cout << tot << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair <int, int> pii;
const int INF = 1000000000;
#define mp(x,y) make_pair((x),(y))

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long tot = 0;
    map <pii, long long> mmap;

    for (int i = n-1; i >= 0; i--){
	int num = arr[i];
	long long mul = (long long) num * k;
	if (mul <= INF && mul >= -INF){
	    if (mmap.count(mp(mul, 1))){
		tot += mmap[mp(mul, 1)];
	    }
	    if (mmap.count(mp(mul, 0))){
		mmap[ mp(num, 1) ] += mmap[ mp(mul, 0) ];
	    }
	}
	mmap[mp(num, 0)]++;
    }
    cout << tot << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair <int, int> pii;
const int INF = 1000000000;
#define mp(x,y) make_pair((x),(y))

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long tot = 0;
    map <pii, int> mmap;

    for (int i = n-1; i >= 0; i--){
	int num = arr[i];
	long long mul = (long long) num * k;
	if (mul <= INF && mul >= -INF){
	    if (mmap.count(mp(mul, 1))){
		if (k == 1 || num == 0 || (num % k))
		    tot += mmap[mp(mul, 1)];
	    }
	    if (mmap.count(mp(mul, 0))){
		mmap[ mp(num, 1) ] += mmap[ mp(mul, 0) ];
	    }
	}
	mmap[mp(num, 0)]++;
    }
    cout << tot << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, div;
    cin >> n >> div;
    vector <int> arr(n);
    for (int i = 0; i < n; i++){
	cin >> arr[i];
    }
    long long tot = 0;
    for (int i = 0; i < n; i++)
	for (int j = i+1; j < n; j++)
	    for (int k = j + 1; k < n; k++){
		if (arr[k] % arr[j] == 0 && arr[k] / arr[j] == div){
		    if (arr[j] % arr[i] == 0 && arr[j] / arr[i] == div)
			if (arr[i] % div)
			    tot++;
		}
	    }

    cout << tot << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, div;
    cin >> n >> div;
    vector <int> arr(n);
    for (int i = 0; i < n; i++){
	cin >> arr[i];
    }
    long long tot = 0;
    for (int i = 0; i < n; i++)
	for (int j = i+1; j < n; j++)
	    for (int k = j + 1; k < n; k++){
		if (arr[k] % arr[j] == 0 && arr[k] / arr[j] == div){
		    if (arr[j] % arr[i] == 0 && arr[j] / arr[i] == div)
			if (arr[i] % div || arr[i] == 1)
			    tot++;
		}
	    }

    cout << tot << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair <int, int> pii;
const int INF = 1000000000;
#define mp(x,y) make_pair((x),(y))

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long tot = 0;
    map <pii, int> mmap;

    for (int i = n-1; i >= 0; i--){
	int num = arr[i];
	long long mul = (long long) num * k;
	if (mul <= INF && mul >= -INF){
	    if (mmap.count(mp(mul, 1))){
		if (k == 1 || (num % k))
		    tot += mmap[mp(mul, 1)];
	    }
	    if (mmap.count(mp(mul, 0))){
		mmap[ mp(num, 1) ] += mmap[ mp(mul, 0) ];
	    }
	}
	mmap[mp(num, 0)]++;
    }
    cout << tot << endl;

    return 0;
}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,int64_t> dp;
  map<int64_t,map<int64_t,int64_t> > temp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }
  for(int i=n-1;i>=0;i--){

      dp[a[i]] = (dp[a[i]*k] + 1);
      int x = dp[a[i]];
      //cout<<x<<" ";
      if(x == 1){
          temp[a[i]][1]++;
      }
      else if(x == 2){
          temp[a[i]][2] += temp[a[i]*k][1];
      }
      if(x == 3){
          temp[a[i]][x] += temp[a[i]*k][2];
          ans+=temp[a[i]*k][2];
      }
      if(x > 3){
          int y = temp[a[i]*k].size();
          temp[a[i]][x] += y*(y-1)/2;
          ans += y*(y-1)/2;
      }

     // cout<<a[i]<<"="<<ans<<"\n";

  }

  cout<<ans;

}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,map<int64_t,int64_t> > dp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }

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

      if(dp[a[i]*k][2] > 0){
          dp[a[i]][3] += dp[a[i]*k][2];
      }
      if(dp[a[i]*k][1] > 0){
          dp[a[i]][2] += dp[a[i]*k][1];
      }

      dp[a[i]][1]++;
      ans += dp[a[i]][3];
      dp[a[i]][3] = 0;

  }

  cout<<ans;

}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,int64_t> dp;
  map<int64_t,map<int64_t,int64_t> > temp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }
  for(int i=n-1;i>=0;i--){

      dp[a[i]] = (dp[a[i]*k] + 1);
      x[i] = dp[a[i]];
     // cout<<x[i]<<" ";
      if(x[i] == 1){
          temp[a[i]][x[i]]++;
      }
      else if(x[i] == 2){
          temp[a[i]][2] += temp[a[i]*k][1];
      }
      if(x[i] >= 3){
          ans += temp[a[i]*k][x[i]-1];
      }
     // cout<<a[i]<<"="<<ans<<"\n";

  }
//   for(int i=0;i<n;i++){
//       cout<<x[i]<<" ";
//   }
//   cout<<"\n";
  cout<<ans;

}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,map<int64_t,int64_t> > dp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }

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

      if(dp[a[i]*k][2] > 0){
          dp[a[i]][3] += dp[a[i]*k][2];
      }
      if(dp[a[i]*k][1] > 0){
          dp[a[i]][2] += dp[a[i]*k][1];
      }

      dp[a[i]][1]++;
      ans += dp[a[i]][3];

  }

  cout<<ans;

}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,int64_t> dp;
  map<int64_t,map<int64_t,int64_t> > temp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }
  for(int i=n-1;i>=0;i--){

      dp[a[i]] = (dp[a[i]*k] + 1);
      int x = dp[a[i]];
     // cout<<x[i]<<" ";
      if(x == 1){
          temp[a[i]][1]++;
      }
      else if(x == 2){
          temp[a[i]][2] += temp[a[i]*k][1];
      }
      if(x >= 3){
          ans += temp[a[i]*k][x-1];
      }
     // cout<<a[i]<<"="<<ans<<"\n";

  }
//   for(int i=0;i<n;i++){
//       cout<<x[i]<<" ";
//   }
//   cout<<"\n";
  cout<<ans;

}


#include<bits/stdc++.h>
#include<stdint.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int64_t a[200005];
int main(){

  map<int64_t,int64_t> dp;
  map<int64_t,map<int64_t,int64_t> > temp;
  int n,k;
  int64_t ans = 0;
  scanf("%d%d",&n,&k);

  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
  }
  for(int i=n-1;i>=0;i--){

      dp[a[i]] = (dp[a[i]*k] + 1);
      int x = dp[a[i]];
      //cout<<x<<" ";
      if(x == 1){
          temp[a[i]][1]++;
      }
      else if(x == 2){
          temp[a[i]][2] += temp[a[i]*k][1];
      }
      if(x >= 3){
          temp[a[i]][x] += temp[a[i]*k][x-1];
          ans += temp[a[i]*k][x-1];
      }
     // cout<<a[i]<<"="<<ans<<"\n";

  }

  cout<<"\n"<<ans;

}


#include <cstdio>
#include <iostream>
#include <map>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int main(){
  ll ans = 0;
  int N, K, arr[200000];
  map<int, int> Al, Ar;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(Ar.find(arr[i])==Ar.end()){
      Ar.insert(ii(arr[i], 0)); Al.insert(ii(arr[i], 0));
    }
    Ar[arr[i]]++;
  }
  for(int i=0; i<N; i++){
    Ar[arr[i]]--; int num1 = arr[i]/K; ll num2 = (ll)arr[i]*K;
    if(arr[i]%K || num2>1000000000 || Al.find(num1)==Al.end() ||
	Ar.find((int)num2)==Ar.end()){ Al[arr[i]]++; continue; }
    ans+=(ll)Al[num1]*Ar[(int)num2];
    Al[arr[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <map>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int main(){
  ll ans = 0;
  int N, K, arr[200000];
  map<int, int> Al, Ar;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(Ar.find(arr[i])==Ar.end()){
      Ar.insert(ii(arr[i], 0)); Al.insert(ii(arr[i], 0));
    }
    Ar[arr[i]]++;
  }
  for(int i=0; i<N; i++){
    Ar[arr[i]]--; int num1 = arr[i]/K; ll num2 = (ll)arr[i]*K;
    if(arr[i]%K || num2>1000000000 || num2<-1000000000 ||
	Al.find(num1)==Al.end() || Ar.find((int)num2)==Ar.end()){
      Al[arr[i]]++; continue;
    }
    ans+=(ll)Al[num1]*Ar[(int)num2];
    Al[arr[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <cstring>

typedef long long ll;

int N, K, arr[200000];
ll dp[200000][4];

ll f(int, int);

int main(){
  ll ans = 0;
  scanf("%d %d", &N, &K); memset(dp, 0xff, sizeof dp);
  for(int i=0; i<N; i++) scanf("%d", &arr[i]);
  for(int i=0; i<N; i++) ans+=f(i, 3);
  printf("%I64d\n", ans);
  return 0;
}

ll f(int i, int len){
  if(len==1) return 1;
  if(i+len>N) return 0;
  if(dp[i][len]!=-1) return dp[i][len];
  ll &ans = dp[i][len]; ans = 0;
  for(int j=i+1; j<N; j++)
    if(!(arr[j]%arr[i]) && arr[j]/arr[i]==K) ans+=f(j, len-1);
  return ans;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, vi> ivi;
typedef vi::iterator viitr;
typedef map<int, vi>::iterator mitr;

int main(){
  ll ans = 0;
  int N, K, arr[200000];
  map<int, vi> indexMap, csum;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(indexMap.find(arr[i])==indexMap.end())
      indexMap.insert(ivi(arr[i], vi()));
    indexMap[arr[i]].push_back(i);
  }
  for(mitr itr=indexMap.begin(); itr!=indexMap.end(); itr++){
    ll num = (ll)(itr->first)*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()){
      csum.insert(ivi(itr->first, vi((itr->second).size(), 0)));
      continue;
    }
    vi temp = itr->second, indexList = indexMap[(int)num], arr2;
    int size = temp.size();
    for(int i=0; i<size; i++)
      arr2.push_back(indexList.end()-upper_bound(indexList.begin(), indexList.end(), temp[i]));
    for(int i=size-1; i>=0; i--) arr2[i]+=arr2[i+1];
    csum.insert(ivi(itr->first, arr2));
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()) continue;
    vi indexList = indexMap[(int)num];
    int index = upper_bound(indexList.begin(), indexList.end(), i)-indexList.begin();
    ans+=csum[(int)num][index];
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, vi> ivi;
typedef vi::iterator viitr;

int main(){
  ll ans = 0;
  int N, K, arr[200000], arr2[200000] = {0};
  map<int, vi> indexMap;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(indexMap.find(arr[i])==indexMap.end())
      indexMap.insert(ivi(arr[i], vi()));
    indexMap[arr[i]].push_back(i);
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()) continue;
    arr2[i] = indexMap[num].end()-upper_bound(indexMap[num].begin(), indexMap[num].end(), i);
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K*K, num2 = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end() ||
	indexMap.find((int)num2)==indexMap.end()) continue;
    viitr end = indexMap[(int)num2].end();
    for(viitr itr=upper_bound(indexMap[(int)num2].begin(), end, i); itr!=end; itr++) ans+=arr2[*itr];
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, vi> ivi;
typedef vi::iterator viitr;
typedef map<int, vi>::iterator mitr;

int main(){
  ll ans = 0;
  int N, K, arr[200000];
  map<int, vi> indexMap, csum;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(indexMap.find(arr[i])==indexMap.end())
      indexMap.insert(ivi(arr[i], vi()));
    indexMap[arr[i]].push_back(i);
  }
  for(mitr itr=indexMap.begin(); itr!=indexMap.end(); itr++){
    ll num = (ll)(itr->first)*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()){
      csum.insert(ivi(itr->first, vi((itr->second).size(), 0)));
      continue;
    }
    vi temp = itr->second, indexList = indexMap[(int)num], arr2;
    int size = temp.size();
    for(int i=0; i<size; i++){
      arr2.push_back(indexList.end()-upper_bound(indexList.begin(), indexList.end(), temp[i]));
    }
    for(int i=size-2; i>=0; i--) arr2[i]+=arr2[i+1];
    csum.insert(ivi(itr->first, arr2));
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()) continue;
    vi indexList = indexMap[(int)num];
    int index = upper_bound(indexList.begin(), indexList.end(), i)-indexList.begin();
    if(index==indexList.size()) continue;
    ans+=csum[(int)num][index];
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, vi> ivi;
typedef vi::iterator viitr;

int main(){
  ll ans = 0;
  int N, K, arr[200000], arr2[200000] = {0};
  map<int, vi> indexMap;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(indexMap.find(arr[i])==indexMap.end())
      indexMap.insert(ivi(arr[i], vi()));
    indexMap[arr[i]].push_back(i);
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()) continue;
    arr2[i] = indexMap[num].end()-upper_bound(indexMap[num].begin(), indexMap[num].end(), i);
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end() ||
	indexMap.find((int)num/K)==indexMap.end()) continue;
    for(viitr itr=upper_bound(indexMap[arr[i]*K].begin(), indexMap[arr[i]*K].end(), i); itr!=indexMap[arr[i]*K].end(); itr++) ans+=arr2[*itr];
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, vi> ivi;
typedef vi::iterator viitr;
typedef map<int, vi>::iterator mitr;

int main(){
  ll ans = 0;
  int N, K, arr[200000];
  map<int, vi> indexMap, csum;
  scanf("%d %d", &N, &K);
  for(int i=0; i<N; i++){
    scanf("%d", &arr[i]);
    if(indexMap.find(arr[i])==indexMap.end())
      indexMap.insert(ivi(arr[i], vi()));
    indexMap[arr[i]].push_back(i);
  }
  for(mitr itr=indexMap.begin(); itr!=indexMap.end(); itr++){
    ll num = (ll)(itr->first)*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end()){
      vi a; a.assign((itr->second).size(), 0); csum.insert(ivi(itr->first, a));
      continue;
    }
    vi temp = itr->second, arr2; int size = temp.size();
    for(int i=0; i<size; i++)
      arr2.push_back(indexMap[num].end()-upper_bound(indexMap[num].begin(), indexMap[num].end(), temp[i]));
    for(int i=size-1; i>=0; i--) arr2[i]+=arr2[i+1];
    csum.insert(ivi(itr->first, arr2));
  }
  for(int i=0; i<N; i++){
    ll num = (ll)arr[i]*K*K, num2 = (ll)arr[i]*K;
    if(num>1000000000 || indexMap.find((int)num)==indexMap.end() ||
	indexMap.find((int)num2)==indexMap.end()) continue;
    int index = upper_bound(indexMap[(int) num2].begin(), indexMap[(int)num2].end(), i)-indexMap[(int)num2].begin();
    ans+=csum[(int)num2][index];
  }
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map <int,ll> a,b;
int arr[1000003];
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0; i<n; i++)
        cin>>arr[i];
    ll ans=0;
    // a[i] store how many time i occurs
    // b[i] store how many time i/k occurs
    // at each index we add the current value of b[i]
    for (int i=0; i<n; ++i)
    {
        a[arr[i]]++;
        if(arr[i]%k==0)
        {
            int div=arr[i]/k;
            //cout<<div<<endl;
            ll c1=a[div]; //how many time div occurs
            ll c2=b[div];
            ans+=c2;
            b[arr[i]]+=c1;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
map <int,ll> a,b;
int arr[1000003];
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=0; i<n; i++)
        cin>>arr[i];
    ll ans=0;
    // a[i] store how many time i occurs
    // b[i] store how many time i/k occurs
    // at each index we add the current value of b[i]
    for (int i=0; i<n; ++i)
    {
        if(arr[i]%k!=0){
            a[arr[i]]++;
            continue;
        }
            int div=arr[i]/k;
            //cout<<div<<endl;
            ll c1=a[div];
            ll c2=b[div];
            ans+=c2;
            //cout<<ans<<" ";
            a[arr[i]]++;
            b[arr[i]]+=c1;
    }
    cout<<ans;
}


//written by raj_0jaiswal
#include <bits/stdc++.h>
using namespace std;
#define crt()  int t; cin>>t; while(t--)
#define ll long long
#define mod 1000000007
#define mxx 100005
#define sc(n) scanf("%d",&n)
#define out(x) #x << " = " << x << "   "
#define DBG(vari) cerr<<#vari<<" ==> "<<(vari)<<endl;
#define pb                      push_back
#define vt                      vector<int>
#define pi                      pair<int,int>
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define maX(a,b)                ((a)>(b)?(a):(b))
#define miN(a,b)                ((a)<(b)?(a):(b))
#define INF                     (int)1e9
#define SORT(_a,_b)             sort(_a,_b,greater<int>())
#define dbg(n)                  cout<<n<<" i'm here "<<endl;
#define DPdbg(n)                for(int i=0;i<=n;i++){for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";cout<<endl;}
/*inline int scan(){ register int t=0;char c=getchar_unlocked();while(c<'0' || c>'9')c=getchar_unlocked();
while(c>='0' && c<='9'){t=(t<<3)+(t<<1)+c-'0';c=getchar_unlocked();} return(t);}*/
ll power(ll aa,ll pp){ ll xx=1,yy=aa%mod; while(pp>0){ if(pp&1) xx=(xx*yy)%mod; yy=(yy*yy)%mod; pp=pp>>1;} return xx%mod;}
bool cmp(pi a,pi b){if(a.ff!=b.ff)return a.ff<b.ff; else return a.ss<b.ss;}
pair<int,int> A[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,k,q1,q2,h1,h2,id;
    ll h,q,ans=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>A[i].ff;
        A[i].ss=i;
    }
    sort(A,A+n);
    //for(i=0;i<n;i++)
        //cout<<i<<" "<<A[i].ff<<" "<<A[i].ss<<endl;
    for(i=1;i<=n;i++){
        if(abs(A[i].ff)%k==0 ){
            id=A[i].ss;
            int pre=(A[i].ff)/k;
            int next=(A[i].ff)*k;
            q1=lower_bound(A,A+n,mp(pre,0))-A;
            q2=lower_bound(A,A+n,mp(pre,id))-A;
            //cout<<q1<<" "<<q2<<endl;
            q=q2-q1;
            h1=lower_bound(A,A+n,mp(next,id+1))-A;
            h2=lower_bound(A,A+n,mp(next,n))-A;
            h=h2-h1;
            ans+=q*h;
        }
    }
    cout<<ans<<endl;
    return 0;
}

//12 3
//1 2 6 2 3 6 9 18 3 9 2 3


//written by raj_0jaiswal
#include <bits/stdc++.h>
using namespace std;
#define crt()  int t; cin>>t; while(t--)
#define ll long long
#define mod 1000000007
#define mxx 100005
#define sc(n) scanf("%d",&n)
#define out(x) #x << " = " << x << "   "
#define DBG(vari) cerr<<#vari<<" ==> "<<(vari)<<endl;
#define pb                      push_back
#define vt                      vector<int>
#define pi                      pair<int,int>
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define maX(a,b)                ((a)>(b)?(a):(b))
#define miN(a,b)                ((a)<(b)?(a):(b))
#define INF                     (int)1e9
#define SORT(_a,_b)             sort(_a,_b,greater<int>())
#define dbg(n)                  cout<<n<<" i'm here "<<endl;
#define DPdbg(n)                for(int i=0;i<=n;i++){for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";cout<<endl;}
/*inline int scan(){ register int t=0;char c=getchar_unlocked();while(c<'0' || c>'9')c=getchar_unlocked();
while(c>='0' && c<='9'){t=(t<<3)+(t<<1)+c-'0';c=getchar_unlocked();} return(t);}*/
ll power(ll aa,ll pp){ ll xx=1,yy=aa%mod; while(pp>0){ if(pp&1) xx=(xx*yy)%mod; yy=(yy*yy)%mod; pp=pp>>1;} return xx%mod;}
bool cmp(pi a,pi b){if(a.ff!=b.ff)return a.ff<b.ff; else return a.ss<b.ss;}
pair<int,int> A[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,k,q1,q2,h1,h2,id;
    ll h,q,ans=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>A[i].ff;
        A[i].ss=i;
    }
    sort(A,A+n);
    //for(i=0;i<n;i++)
        //cout<<i<<" "<<A[i].ff<<" "<<A[i].ss<<endl;
    for(i=0;i<n;i++){
        if(abs(A[i].ff)%k==0 && abs(1LL*A[i].ff*k)<1e9+7){
            id=A[i].ss;
            int pre=(A[i].ff)/k;
            int next=(A[i].ff)*k;
            q1=lower_bound(A,A+n,mp(pre,0))-A;
            q2=lower_bound(A,A+n,mp(pre,id))-A;
            //cout<<q1<<" "<<q2<<endl;
            q=q2-q1;
            h1=lower_bound(A,A+n,mp(next,id+1))-A;
            h2=lower_bound(A,A+n,mp(next,n))-A;
            h=h2-h1;
            ans+=q*h;
        }
    }
    cout<<ans<<endl;
    return 0;
}


//written by raj_0jaiswal
#include <bits/stdc++.h>
using namespace std;
#define crt()  int t; cin>>t; while(t--)
#define ll long long
#define mod 1000000007
#define mxx 100005
#define sc(n) scanf("%d",&n)
#define out(x) #x << " = " << x << "   "
#define DBG(vari) cerr<<#vari<<" ==> "<<(vari)<<endl;
#define pb                      push_back
#define vt                      vector<int>
#define pi                      pair<int,int>
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define maX(a,b)                ((a)>(b)?(a):(b))
#define miN(a,b)                ((a)<(b)?(a):(b))
#define INF                     (int)1e9
#define SORT(_a,_b)             sort(_a,_b,greater<int>())
#define dbg(n)                  cout<<n<<" i'm here "<<endl;
#define DPdbg(n)                for(int i=0;i<=n;i++){for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";cout<<endl;}
/*inline int scan(){ register int t=0;char c=getchar_unlocked();while(c<'0' || c>'9')c=getchar_unlocked();
while(c>='0' && c<='9'){t=(t<<3)+(t<<1)+c-'0';c=getchar_unlocked();} return(t);}*/
ll power(ll aa,ll pp){ ll xx=1,yy=aa%mod; while(pp>0){ if(pp&1) xx=(xx*yy)%mod; yy=(yy*yy)%mod; pp=pp>>1;} return xx%mod;}
bool cmp(pi a,pi b){if(a.ff!=b.ff)return a.ff<b.ff; else return a.ss<b.ss;}
pair<int,int> A[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,k,q1,q2,h1,h2,id;
    ll h,q,ans=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>A[i].ff;
        A[i].ss=i;
    }
    sort(A,A+n);
    //for(i=0;i<n;i++)
        //cout<<i<<" "<<A[i].ff<<" "<<A[i].ss<<endl;
    for(i=1;i<=n;i++){
        if(abs(A[i].ff)%k==0 && abs(1LL*A[i].ff*k)<1e9+7){
            id=A[i].ss;
            int pre=(A[i].ff)/k;
            int next=(A[i].ff)*k;
            q1=lower_bound(A,A+n,mp(pre,0))-A;
            q2=lower_bound(A,A+n,mp(pre,id))-A;
            //cout<<q1<<" "<<q2<<endl;
            q=q2-q1;
            h1=lower_bound(A,A+n,mp(next,id+1))-A;
            h2=lower_bound(A,A+n,mp(next,n))-A;
            h=h2-h1;
            ans+=q*h;
        }
    }
    cout<<ans<<endl;
    return 0;
}

//12 3
//1 2 6 2 3 6 9 18 3 9 2 3


//written by raj_0jaiswal
#include <bits/stdc++.h>
using namespace std;
#define crt()  int t; cin>>t; while(t--)
#define ll long long
#define mod 1000000007
#define mxx 100005
#define sc(n) scanf("%d",&n)
#define out(x) #x << " = " << x << "   "
#define DBG(vari) cerr<<#vari<<" ==> "<<(vari)<<endl;
#define pb                      push_back
#define vt                      vector<int>
#define pi                      pair<int,int>
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define maX(a,b)                ((a)>(b)?(a):(b))
#define miN(a,b)                ((a)<(b)?(a):(b))
#define INF                     (int)1e9
#define SORT(_a,_b)             sort(_a,_b,greater<int>())
#define dbg(n)                  cout<<n<<" i'm here "<<endl;
#define DPdbg(n)                for(int i=0;i<=n;i++){for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";cout<<endl;}
/*inline int scan(){ register int t=0;char c=getchar_unlocked();while(c<'0' || c>'9')c=getchar_unlocked();
while(c>='0' && c<='9'){t=(t<<3)+(t<<1)+c-'0';c=getchar_unlocked();} return(t);}*/
ll power(ll aa,ll pp){ ll xx=1,yy=aa%mod; while(pp>0){ if(pp&1) xx=(xx*yy)%mod; yy=(yy*yy)%mod; pp=pp>>1;} return xx%mod;}
bool cmp(pi a,pi b){if(a.ff!=b.ff)return a.ff<b.ff; else return a.ss<b.ss;}
pair<int,int> A[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,k,q1,q2,h1,h2,id;
    ll h,q,ans=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>A[i].ff;
        A[i].ss=i;
    }
    sort(A,A+n);
    //for(i=0;i<n;i++)
        //cout<<i<<" "<<A[i].ff<<" "<<A[i].ss<<endl;
    for(i=0;i<n;i++){
        if(abs(A[i].ff)%k==0 && abs(1LL*A[i].ff*k)<1e9+7){
            id=A[i].ss;
            int pre=(A[i].ff)/k;
            int next=(A[i].ff)*k;
            q1=lower_bound(A,A+n,mp(pre,0))-A;
            q2=lower_bound(A,A+n,mp(pre,id))-A;
            //cout<<q1<<" "<<q2<<endl;
            q=q2-q1;
            h1=lower_bound(A,A+n,mp(next,id+1))-A;
            h2=lower_bound(A,A+n,mp(next,n))-A;
            h=h2-h1;
            ans+=q*h;
        }
    }
    cout<<ans<<endl;
    return 0;
}

//12 3
//1 2 6 2 3 6 9 18 3 9 2 3