#include <stdio.h>

void	swap(int *a, int *b)
{
	int c;

	c = *a;
	*a = *b;
	*b = c;
}

void		sort(int *arr, int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
		for (j = 0; j < n-i-1; j++)
			if (arr[j] <  arr[j+1])
				swap(&arr[j], &arr[j+1]);
}

int		main(void)
{
	int n, i, j, sum;

	scanf("%d", &n);
	int board[n][n];
	int tab[n];
	if (1 <= n && n <= 1000)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < 4; j++)
				scanf("%d", &board[i][j]);
		}
		for (i = 0; i < n ; i++)
		{
			sum = 0;
			for (j = 0; j < 4; j++)
				tab[i] = tab[i] + board[i][j];
		}

		int tscore = tab[0];
		sort(tab, n);

		for (i = 0; i < n; i++)
		{
			if (tab[i] == tscore)
			{
				printf("%d\n", i + 1);
				return (0);
			}
		}
	}
	return (0);
}


#include <stdio.h>

void    swap(int *a, int *b)
{
	int c;

	c = *a;
	*a = *b;
	*b = c;
}

void        sort(int *arr, int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
		for (j = 0; j < n-i-1; j++)
			if (arr[j] <  arr[j+1])
				swap(&arr[j], &arr[j+1]);
}

int     main(void)
{
	int n, i, j, sum;

	scanf("%d", &n);
	int board[n][n];
	int tab[n];
	if (1 <= n && n <= 1000)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < 4; j++)
				scanf("%d", &board[i][j]);
		}
		for (i = 0; i < n ; i++)
		{
			sum = 0;
			for (j = 0; j < 4; j++)
				tab[i] = tab[i] + board[i][j];
		}

		int tscore = tab[0];
		sort(tab, n);

		for (i = 0; i < n; i--)
		{
			if (tab[i] == tscore)
			{
				printf("%d\n", i + 1);
				return (0);
			}
		}
	}
	return (0);
}


#include <stdio.h>

void    swap(int *a, int *b)
{
	int c;

	c = *a;
	*a = *b;
	*b = c;
}

void        sort(int *arr, int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
		for (j = 0; j < n-i-1; j++)
			if (arr[j] <  arr[j+1])
				swap(&arr[j], &arr[j+1]);
}

int     main(void)
{
	int n, i, j, sum;

	scanf("%d", &n);
	int board[n][n];
	int tab[n];
	if (1 <= n && n <= 1000)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < 4; j++)
				scanf("%d", &board[i][j]);
		}
		for (i = 0; i < n ; i++)
		{
			sum = 0;
			for (j = 0; j < 4; j++)
				tab[i] = tab[i] + board[i][j];
		}

		int tscore = tab[0];
		sort(tab, n);

		for (i = 0; i < n; i++)
		{
			if (tab[i] == tscore)
			{
				printf("%d\n", i + 1);
				return (0);
			}
		}
	}
	return (0);
}


#include <stdio.h>

void    swap(int *a, int *b)
{
	int c;

	c = *a;
	*a = *b;
	*b = c;
}

void        sort(int *arr, int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
		for (j = 0; j < n-i-1; j++)
			if (arr[j] <  arr[j+1])
				swap(&arr[j], &arr[j+1]);
}

int     main(void)
{
	int n, i, j, sum, tab[1000] = {0};

	scanf("%d", &n);
	int board[n][4];
	if (1 <= n && n <= 1000)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < 4; j++)
				scanf("%d", &board[i][j]);
		}
		for (i = 0; i < n ; i++)
		{
			sum = 0;
			for (j = 0; j < 4; j++)
				tab[i] = tab[i] + board[i][j];
		}

		int tscore = tab[0];
		sort(tab, n);

		for (i = 0; i < n; i++)
		{
			if (tab[i] == tscore)
			{
				printf("%d\n", i + 1);
				return (0);
			}
		}
	}
	return (0);
}


#include<stdio.h>
int main()
{
	int i,n,a,b,c,d,s,t,r;
printf("enter the value of n");
scanf("%d",&n);

r=1;
scanf("%d %d %d %d",&a,&b,&c,&d);
t=a+b+c+d;
for(int i=2;i<n+1;i++)
{
scanf("%d %d %d %d",&a,&b,&c,&d);
s=a+b+c+d;
if(s>t)
r++;
else
r=r;
}
printf("%d",r);
return 0;
}


#include <stdio.h>

int main()
{
	int n,a,b,c,d,s,t,r;
	r=1;
	scanf("%d",&n);
	scanf("%d %d %d %d", &a, &b, &c, &d);
	t=a+b+c+d;
	for(int i=2;i<n+1;i++)
	{
		scanf("%d %d %d %d", &a, &b, &c, &d);
		s=a+b+c+d;
		if(s>t)
		{
			r++;
		}
	}
	printf("%d",r);
	return 0;
}


#include<stdio.h>
int main()
{
    int n,a,b,c,d,s,t,r;
    r=1;
    scanf("%d",&n);
    scanf("%d %d %d",&a,&b,&c,&d);
    t=a+b+c+d;
    for(int i=2;i{
        scanf("%d %d %d",&a,&b,&c,&d);
        s=a+b+c+d;
        if(s>t);
        {
            r++;
        }
    }
    printf("%d",r);
    return 0;
}


#include<stdio.h>
int main()
{
	int n,a,b,c,d,s,t,r;
printf("enter the value of n");
scanf("%d",&n);
scanf("%d %d %d %d",&a,&b,&c,&d);
t=a+b+c+d;
r=1;
for(int i=2;i<n+1;i++)
{
scanf("%d %d %d %d",&a,&b,&c,&d);
s=a+b+c+d;
if(s>t)
r++;
else
r=r;
}
printf("%d",r);
return 0;
}


#include <stdio.h>

int main() {
int i,n,a,b,c,d,s,t,r;
printf("enter the value of n");
scanf("%d",&n);

r=1;
scanf("%d %d %d %d",&a,&b,&c,&d);
t=a+b+c+d;
for(int i=2;i<n+1;i++)
{
scanf("%d %d %d %d",&a,&b,&c,&d);
s=a+b+c+d;
if(s>t)
r++;
else
r=r;
}
printf("%d",r);
	return 0;
}


#include<stdio.h>

int main()
{
	int n, ma[n], k, i, j, tm;
	scanf("%d", &n);
	struct student
	{
		int a;
		int b;
		int c;
		int d;
	}stu[n];
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&stu[i].a, &stu[i].b, &stu[i].c, &stu[i].d);
		ma[i]=stu[i].a+stu[i].b+stu[i].c+stu[i].d;
	}
	tm=ma[0];

	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(ma[i+1]>ma[i])
			{
				k=ma[i+1];
				ma[i+1]=ma[i];
				ma[i]=k;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		if(ma[i]==tm)
		{
			printf("%d", i+1);
			break;
		}
	}
	return 0;
}


#include<stdio.h>

int main()
{
	int n, ma[n], k, i, j, tm;
	scanf("%d", &n);
	struct student
	{
		int a;
		int b;
		int c;
		int d;
	}stu[n];
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&stu[i].a, &stu[i].b, &stu[i].c, &stu[i].d);
		ma[i]=stu[i].a+stu[i].b+stu[i].c+stu[i].d;
	}
	tm=ma[0];

	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(ma[i+1]>ma[i])
			{
				k=ma[i+1];
				ma[i+1]=ma[i];
				ma[i]=k;
			}
		}
	}
	for(i=1;i<n;i++)
	{
		if(ma[i]==tm)
		{
			printf("%d", i);
			break;
		}
	}
	return 0;
}


#include<stdio.h>

int main()
{
	int n, i, k, pos=1;
	scanf("%d", &n);
	int ar[n];
	int a, b, c, d;

	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d", &a, &b, &c, &d);
		ar[i]=a+b+c+d;
		if(i==0) k=ar[i];
		if(ar[i]>k) pos=pos+1;
	}
	printf("%d", pos);
}


#include <stdio.h>
int main()
{
    long long int  num,i,sum=0,s[100005],max=0,c,j,mat[10005][5],count=0,c2=0;
    scanf("%lld",&num);
    for(i=0;i<num;i++)
    {
        for(j=0;j<4;j++)
        {
            scanf("%lld",&mat[i][j]);
        }
    }
     for(i=0;i<1;i++)
     {
         for(j=0;j<4;j++)
         {
             max=max+mat[i][j];
         }
     }
     //printf("%d\n",max);
     for(i=1;i<num;i++)
    {
        //sum=0;
        for(j=0;j<4;j++)
        {
            sum=sum+mat[i][j];

        }
        if(sum<max)
            {
                count++;
            }
        else if(sum>max)
        {
            c2++;
        }
        sum=0;

    }
    printf("%lld\n",c2+1);

}


#include <stdio.h>
int main()
{
    long long int  num,i,sum=0,s[100005],max=0,c,j,mat[10005][5],count=0,c2=0;
    scanf("%lld",&num);
    for(i=0;i<num;i++)
    {
        for(j=0;j<4;j++)
        {
            scanf("%lld",&mat[i][j]);
        }
    }
     for(i=0;i<1;i++)
     {
         for(j=0;j<4;j++)
         {
             max=max+mat[i][j];
         }
     }
     printf("%d\n",max);
     for(i=1;i<num;i++)
    {
        //sum=0;
        for(j=0;j<4;j++)
        {
            sum=sum+mat[i][j];

        }
        if(sum<max)
            {
                count++;
            }
        else if(sum>max)
        {
            c2++;
        }
        sum=0;

    }
    printf("%lld\n",c2+1);

}


#include <stdio.h>
int main()
{
    long long int  num,i,sum=0,s[100005],max=0,c,j,mat[10005][5];
    scanf("%lld",&num);
    for(i=0;i<num;i++)
    {
        for(j=0;j<4;j++)
        {
            scanf("%lld",&mat[i][j]);
        }
    }
     for(i=0;i<num;i++)
    {
        //sum=0;
        for(j=0;j<4;j++)
        {
            sum=sum+mat[i][j];
            if(sum>max)
            {
                max=sum;
                c=i;
            }

        }
        sum=0;

    }
    printf("%lld",c+1);

}


#include<stdio.h>
int main(){

int t,a,b,c,d,e,f=0,g=0,i;
scanf("%d",&t);

for(i=1;i<=t;i++)
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    e=a+b+c+d;
    if(f<e)
    {
        f=e;
        g=i;
    }

}
if(f==0)
    printf("1");
else
    printf("%d",g);

return 0;
}


#include<stdio.h>
int main(){

int t,a,b,c,d,e,f=0,g=0,i;
scanf("%d",&t);

for(i=1;i<=t;i++)
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    e=a+b+c+d;
    if(f<e)
    {
        f=e;
        g=i;
    }

}
printf("%d",g);

return 0;
}


#include<stdio.h>
int main()
{
	int i,a,j,tot=0,n,max,x;

	scanf("%d",&n);
	for (j=1;j<=n;j++)
	{
		tot=0;
		for (i=1;i<=4;i++)
		{
			scanf("%d",&a);
			tot=tot+a;
		}
		if (max<tot)
		{
			max=tot;
			x=j;
		}
	}
printf("%d",x);
return(0);
}


#include<stdio.h>
int total(int s,int tot)
{
	tot=tot+s;
	return(tot);
}
int main()
{
	int i,a,j,tot=0,n,max,x;

	scanf("%d",&n);
	for (j=1;j<=n;j++)
	{
		tot=0;
		for (i=1;i<=4;i++)
		{
			scanf("%d",&a);
			tot=total(a,tot);
		}
		if (max<tot)
		{
			max=tot;
			x=j;
		}
	}
printf("%d",x);
return(0);
}


#include<stdio.h>
int main()
{
	int i,a,j,tot,n,max,x=1;

	scanf("%d",&n);
	for (j=1;j<=n;j++)
	{
		tot=0;
		for (i=1;i<=4;i++)
		{
			scanf("%d",&a);
			tot=tot+a;
			if (j==1)
			{
				max=tot;
			}
		}
		if (max<tot)
		{
			x=x+1;
		}
	}
printf("%d",x);
return(0);
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d ,i=0 ,k=1 , sum[k] , max=0 , ind=0 ;
	scanf("%d",&n);
	for(i=1;i<n+1;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		sum[k] = a + b + c + d;
		k += 1;
	}
	for(i=1;i<n+1;i++){
		if(sum[i]>max){
		    max = sum[i];
			ind = i;
		}
	}
	printf("%d",ind+1);
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d ,i=0 ,k=0 , sum[k] , max=0 , ind=0 ;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		sum[k] = a + b + c + d;
		k += 1;
	}
	for(i=0;i<n;i++){
		if(sum[i]>max){
			max = sum[i];
			ind = i;
		}
	}
	printf("%d",ind+1);
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d ,i=0 ,k=1 , sum[k] , max=0 , ind=0  , j=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		sum[k] = a + b + c + d;
		k += 1;
	}
	for(j=0;j<n;j++){
		if(sum[j]>max){
			max = sum[j];
			ind = j;
		}
	}
	printf("%d",ind);

}


#include <stdio.h>

int main()
{
    int n , a , b , c , d , s , r , i=0 , rank=1 ;
    scanf("%d",&n);
    scanf("%d%d%d%d",&a,&b,&c,&d);
    s = a + b + c +d;
    for(i=1;i<n;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        r = a + b + c + d;
        if(r>s){
            rank++;
        }
    }
    printf("%d",rank);
}


#include <stdio.h>

int max(int [],int);

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=0,ind;
	int rank[1000];
	scanf("%d",&n);
	while(i<n)
	{
		scanf("%d%d%d%d", &a,&b,&c,&d);
		rank[i]=a+b+c+d;
		i++;
	}
	ind=max(rank, n);
	printf("%d", ind+1);
	return 0;
}

int max(int rank[], int n)
{
	int i, ind;
	ind=0;
	for(i=1;i<n; i++)
	{
		if(rank[i]>rank[ind])
		{
			ind=i;
		}
	}
	return ind;
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d, sum, temp , r=0 , i=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d%d%d%d",&a,&b,&c,&d);
	    sum =a+b+c+d;
	    if(i == 0){
	        temp = sum;
	        r = 1;
	    }
	    else if(sum > temp){
	        temp = sum;
	        r++;
	    }

	}
	printf("%d",r);
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d ,i=0 ,k=0 , sum[k] , max=0 , ind=0 ;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		sum[k] = a + b + c + d;
		k += 1;
	}
	for(i=0;i<n;i++){
		if(sum[i]>max){
			max = sum[i];
			ind = i;
		}
	}
	printf("%d",ind);
}


#include <stdio.h>

int main()
{
	int n , a, b , c, d ,i=0 ,k=0 , sum[k] , max=0 , ind=0 ;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		sum[k] = a + b + c + d;
		k += 1;
	}
	for(i=1;i<=n;i++){
		if(sum[i]>max){
			max = sum[i];
			ind = i;
		}
	}
	printf("%d",ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, max=-1;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>=max)
				{
					ind=i;
					max=s1;
				}
			i++;
			}
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, max=-1;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>max)
				{
					ind=i;
					max=s1;
					i++;
				}

			}
	}
	printf("%d", ind);
}


#include<stdio.h>
int main ()
{
	int n,s1,a,b,c,d;
	int s2,r,i;
	scanf ("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf ("%d%d%d%d",&a,&b,&c,&d);
		s1=a+b+c+d;
		if (i==0)
		{
			s2=s1;
			r=1;
		}
		else if(s1>s2)
		r++;
	}
	printf ("%d",r);
	return 0;
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, s2=0;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("1");
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>s2)
				{
					ind=i;
					s2=s1;
				}
			i++;
			}
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, max=-1;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>max)
				{
					ind=i;
					max=s1;
				}
			i++;
			}
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, s2=0;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>s2)
				{
					ind=i;
					s2=s1;
				}
			i++;
			}
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, s2=0;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		s1=a+b+c+d;
		if(s1>s2)
		{
			ind=i;
			s2=s1;
		}

		i++;
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, max=-1;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d %d %d %d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			a:while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>max)
				{
					ind=i;
					max=s1;
				}
				else
					goto a ;
			i++;
			}
	}
	printf("%d", ind);
}


#include <stdio.h>

int main(int argc, char **argv)
{
	int n, a, b, c, d;
	int i=1,ind,s1=0, max=-1;
	scanf("%d",&n);
	if(n==1)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ind=1;
	}
	else
	{
			while(n--)
			{
				scanf("%d%d%d%d",&a,&b,&c,&d);
				s1=a+b+c+d;
				if(s1>=max)
				{
					ind=i;
					max=s1;
					i++;
				}

			}
	}
	printf("%d", ind);
}


#include <stdio.h>
#include <string.h>

int students,lessonsc,scores[1002],studentsum,thomas;

int main ()
{
	//freopen ("cf.in","r",stdin),freopen("cf.out","w",stdout);
	scanf ("%d",&students);
	for (int i=0;i<students;i++)
	{
		studentsum = 0;
		for (int j=0;j<4;j++)
		{
			scanf ("%d",&lessonsc);
			studentsum += lessonsc;
		}
		scores [i] = studentsum;
	}
	thomas = scores[0];
	for (int i=0;i<students;i++)
	{
		for (int j=i;j<students-1;j++)
		{
			if (scores[j]<scores[j+1])
			{
				int temp = scores[j];
				scores [j] = scores[j+1];
				scores[j+1] = temp;
			}
		}
	}
	for (int i=0;i<students;i++)
	{
		if (thomas == scores[i])
		{
			printf ("%d\n",i+1);
			break;
		}
	}
}


#include <stdio.h>
#include <string.h>

int students,lessonsc,scores[1002],studentsum,thomas;

void swap (int *xp,int*yp)
{
	int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

int main ()
{
	//freopen ("cf.in","r",stdin),freopen("cf.out","w",stdout);
	scanf ("%d",&students);
	for (int i=0;i<students;i++)
	{
		studentsum = 0;
		for (int j=0;j<4;j++)
		{
			scanf ("%d",&lessonsc);
			studentsum += lessonsc;
		}
		scores [i] = studentsum;
	}
	thomas = scores[0];

	for (int i=0;i<students;i++)
	{
		for (int j=0;j<i;j++)
		{
			if (scores[j]<scores[i])
			{
				swap (&scores[j],&scores[i]);
			}
		}

	}

	for (int i=0;i<students;i++)
	{
		if (scores[i]==thomas)
		{
			printf ("%d\n",i+1);
			break;
		}
	}
}


#include <stdio.h>
#include <string.h>

int students,lessonsc,scores[100],studentsum,thomas;

int main ()
{
	//freopen ("cf.in","r",stdin),freopen("cf.out","w",stdout);
	scanf ("%d",&students);
	for (int i=0;i<students;i++)
	{
		studentsum = 0;
		for (int j=0;j<4;j++)
		{
			scanf ("%d",&lessonsc);
			studentsum += lessonsc;
		}
		scores [i] = studentsum;
	}
	thomas = scores[0];
	for (int i=0;i<students;i++)
	{
		for (int j=i;j<students-1;j++)
		{
			if (scores[j]<scores[j+1])
			{
				int temp = scores[j];
				scores [j] = scores[j+1];
				scores[j+1] = temp;
			}
		}
	}
	for (int i=0;i<students;i++)
	{
		if (thomas == scores[i])
		{
			printf ("%d\n",i+1);
			break;
		}
	}
}


function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const scores = new Array(n);
  for (let i = 0; i < n; i += 1) {
    scores[i] = is.nextArray(Number);
    scores[i] = [scores[i].reduce((accum, item) => accum + item, 0), i + 1];
  }
  scores.sort((a, b) => {
    if (a[0] === b[0])
      return a[1] - b[1];
    return b[0] - a[0];
  });

  for (let i = 0; i < n; i += 1) {
    if (scores[i][1] === 1) {
      console.log(i + 1);
      break;
    }
  }

}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });


const vIn = [];
let itIn = 0;
const getNext = () => vIn[itIn++];
const getInt = () => parseInt(getNext(), 10);
const forEachN = (n, cb, flagInt = false) => {
  const nextItIn = itIn + n;
  const fn = flagInt ? getInt : getNext;
  while (itIn !== nextItIn) cb(fn());
};

class SolveProblemClass {
  constructor() {
  }

  solveAll() {
    const n = getInt();
    const v = [];
    for (let i = 0; i < n ; i++) {
      let sum = 0;
      forEachN(4, (x) => {
        sum += x;
      }, true);
      v.push({ i, sum });
    }
    v.sort((a, b) => {
      if (b.sum > a.sum) return 1;
      if (b.sum < a.sum) return -1;
      return a.i - b.i;
    });
    const pos = v.reduce((i, obj, it) => {
      if (obj.i === 0) return it + 1;
      return i;
    }, -1);
    console.log(pos);
  }
}

const processData = (input) => {
  input.split('\n').forEach(line => {
    // vIn.push(line);
    line.split(' ').forEach(item => { vIn.push(item); });
  });
};

const solveP = new SolveProblemClass();
process.stdin.resume();
process.stdin.setEncoding("ascii");
let _input = "";
process.stdin.on("data", (input) => {
  _input += input;
});
process.stdin.on("end", () => {
  processData(_input);
  solveP.solveAll();
});


const readline = require('readline')
const rl = readline.createInterface({input: process.stdin})

let n, sums = [], numLines = 0
rl.on('line', line => {
    if (++numLines == 1) {
        n = parseInt(line)
    } else {
        const currentSum = line.split(' ').map(x => parseInt(x)).reduce((a, x) => a + x)
        sums.push(currentSum)
    }
}).on('close', () => {
    const thomasSum = sums.shift()
    const thomasRank = 1 + sums.filter(x => x > thomasSum).length
    process.stdout.write(`${thomasRank}`)
})


var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function (line) {
  console.log(2);
  process.exit()
});


#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>=    b;i--)
#define sz(a) ((int)a.size())
#define all(c) c.begin(), c.end()

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<long, long> mll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;

struct sort_pred{ bool operator() (const int &left, const  int &right){ return left > right; } };

int n, k;
mll lm, rm;
vll v;

int main(){

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

        int x;
        cin >> x;
        rm[x]++;
        v.pb(x);

    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll kl = 0, kr = 0;

        if (v[i] % k == 0) kl = lm[v[i] / k];
        rm[v[i]]--;
        kr = rm[k * v[i]];
        ans += (kl * kr);

        lm[v[i]]++;

    }

    cout << ans << endl;

    return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      long long mx=-1000000007, mn=1000000007;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
            mx=max(mx, 1LL*a[i].vl);
            mn=min(mn, 1LL*a[i].vl);
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>mx) || (((a[i].vl*1LL)*k)<mn))
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(mn>n-1)return data2(0LL, 0LL, 0LL);
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      long long mx=-1000000007, mn=1000000007;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
            mx=max(mx, 1LL*a[i].vl);
            mn=min(mn, 1LL*a[i].vl);
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>mx) || (((a[i].vl*1LL)*k)<mn))
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int j, k, aa[MX];

data2 bs(int x, int in)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(mn>j-1)return data2(0LL, 0LL, 0LL);
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

long long f()
{
      sort(a, a+j);
      sum[j]=data2(0LL, 0LL, 0LL);
      for(int i=j-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000LL) || (((a[i].vl*1LL)*k)<-1000000000LL))
            {
                  sum[i]=data2(sum[i+1].o+1LL, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      return sum[0].th;
}

int main()
{
      int i, n;
      long long mx=-1000000007, mn=1000000007, ans;
      scanf("%d %d", &n, &k);
      for(i=j=0; i<n; i++)
      {
            scanf("%d", &aa[i]);
            if(aa[i]>=0)a[j++]=data(aa[i], i);
      }
      ans+=f();

      for(i=j=0; i<n; i++)
      {
            if(aa[i]<0)a[j++]=data(-aa[i], i);
      }
      ans+=f();
      printf("%I64d\n", ans);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000LL) || (((a[i].vl*1LL)*k)<-1000000000LL))
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(int a, int b, int c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if(((a[i].vl*1LL)*k)>1000000000LL)
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int j, aa[MX];

data2 bs(int x, int in)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(mn>j-1)return data2(0LL, 0LL, 0LL);
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i, n;
      long long mx=-1000000007, mn=1000000007, ans;
      scanf("%d %d", &n, &k);
      for(i=j=0; i<n; i++)
      {
            scanf("%d", &aa[i]);
            if(aa[i]>=0)a[j++]=data(aa[i], i);
      }
      sort(a, a+j);
      sum[j]=data2(0LL, 0LL, 0LL);
      for(i=j-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000) || (((a[i].vl*1LL)*k)<-1000000000))
            {
                  sum[i]=data2(sum[i+1].o+1LL, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      ans=sum[0].th;

      for(i=j=0; i<n; i++)
      {
            if(aa[i]<0)a[j++]=data(-aa[i], i);
      }
      sort(a, a+j);
      sum[j]=data2(0LL, 0LL, 0LL);
      for(i=j-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000LL) || (((a[i].vl*1LL)*k)<-1000000000LL))
            {
                  sum[i]=data2(sum[i+1].o+1LL, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      ans+=sum[0].th;
      printf("%I64d\n", ans);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if(((a[i].vl*1LL)*k)>1000000000LL)
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int j, k, aa[MX];

data2 bs(int x, int in)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(mn>j-1)return data2(0LL, 0LL, 0LL);
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=j-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int f()
{
      sort(a, a+j);
      sum[j]=data2(0LL, 0LL, 0LL);
      for(int i=j-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000LL) || (((a[i].vl*1LL)*k)<-1000000000LL))
            {
                  sum[i]=data2(sum[i+1].o+1LL, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      return sum[0].th;
}

int main()
{
      int i, n;
      long long mx=-1000000007, mn=1000000007, ans;
      scanf("%d %d", &n, &k);
      for(i=j=0; i<n; i++)
      {
            scanf("%d", &aa[i]);
            if(aa[i]>=0)a[j++]=data(aa[i], i);
      }
      ans+=f();

      for(i=j=0; i<n; i++)
      {
            if(aa[i]<0)a[j++]=data(-aa[i], i);
      }
      ans+=f();
      printf("%I64d\n", ans);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if(((a[i].vl*1LL)*k)>1000000000LL)
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      int o, tw, th;
      data2(){}
      data2(int a, int b, int c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0, 0, 0);
      for(i=n-1; ~i; i--)
      {
            if(((a[i].vl*1LL)*k)>1000000000LL)
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      long long o, tw, th;
      data2(){}
      data2(long long a, long long b, long long c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<=in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0LL, 0LL, 0LL);
      if(a[mn].in<=in)return data2(0LL, 0LL, 0LL);
      mna=mn;

      mn=0;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0LL, 0LL, 0LL);
      for(i=n-1; ~i; i--)
      {
            if((((a[i].vl*1LL)*k)>1000000000LL) || (((a[i].vl*1LL)*k)<-1000000000LL))
            {
                  sum[i]=data2(sum[i+1].o+1, sum[i+1].tw, sum[i+1].th);
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1LL;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%I64d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      int o, tw, th;
      data2(){}
      data2(int a, int b, int c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      sum[n]=data2(0, 0, 0);
      for(i=n-1; ~i; i--)
      {
            if((a[i].vl*1LL)*k>1000000000LL)
            {
                  sum[i]=sum[i+1];
                  continue;
            }
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%d\n", sum[0].th);
      return 0;
}


//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<utility>

using namespace std;

#define dbg(args...) cerr << #args << ": "; DBG, args; cerr << endl;
#define debug(a, n) cerr << #a << ": { "; for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << "}" << endl;

struct debugger {
	template <typename T> debugger &operator , (const T &v) {
		cerr << v << ' ';
		return *this;
	}
} DBG;

#define MX 200007

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

struct data
{
      int vl, in;
      data(){}
      data(int a, int b)
      {
            vl=a;
            in=b;
      }
      bool operator<(const data& w)const
      {
            return vl==w.vl?in<w.in:vl<w.vl;
      }
};

struct data2
{
      int o, tw, th;
      data2(){}
      data2(int a, int b, int c)
      {
            o=a;
            tw=b;
            th=c;
      }
};

data a[MX];
data2 sum[MX];
int n;

data2 bs(int x, int in, int i)
{
      int mn, mx, mid, mna;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(a[mid].vl<x)mn=mid+1;
            else if(a[mid].vl>x)mx=mid-1;
            else
            {
                  if(a[mid].in<in)mn=mid+1;
                  else mx=mid;
            }
      }
      if(a[mn].vl!=x)return data2(0, 0, 0);
      if(a[mn].in<=in)return data2(0, 0, 0);
      mna=mn;

      mn=i+1;
      mx=n-1;
      while(mn<mx)
      {
            mid=(mn+mx)>>1;
            if(mn==mid)mid++;
            if(a[mid].vl>x)mx=mid-1;
            else mn=mid;
      }
      return data2(sum[mna].o-sum[mn+1].o, sum[mna].tw-sum[mn+1].tw, sum[mna].th-sum[mn+1].th);
}

int main()
{
      int k, i;
      scanf("%d %d", &n, &k);
      for(i=0; i<n; i++)
      {
            scanf("%d", &a[i].vl);
            a[i].in=i;
      }
      sort(a, a+n);
      for(i=n-1; ~i; i--)
      {
            sum[i]=bs(a[i].vl*k, a[i].in, i);
            sum[i].th=sum[i].tw;
            sum[i].tw=sum[i].o;
            sum[i].o=1;
            sum[i].o+=sum[i+1].o;
            sum[i].tw+=sum[i+1].tw;
            sum[i].th+=sum[i+1].th;
      }
      printf("%d\n", sum[0].th);
      return 0;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    ios_base::sync_with_stdio( 0 );
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k  );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k - 1 );
        v.insert( ( long long )A[ i ]*( long long )k  );
        v.insert( (long long )A[ i ]*(long long )k - 1 );
    }
    int p = 1;
    for ( set< long long > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            long long num1 = A[ i ]/k, num2 = (long long)A[ i ]*(long long)k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k  );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k - 1 );
        v.insert( ( long long )A[ i ]*( long long )k  );
        v.insert( (long long )A[ i ]*(long long )k - 1 );
    }
    int p = 1;
    for ( set< long long > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            long long num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    ios_base::sync_with_stdio( 0 );
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k  );
        if( A[ i ]%k == 0 ) v.insert( A[ i ]/k - 1 );
        v.insert( ( long long )A[ i ]*( long long )k  );
        v.insert( (long long )A[ i ]*(long long )k - 1 );
    }
    int p = 1;
    for ( set< long long > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            long long num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( ( long long )A[ i ]*( long long )k  );
        v.insert( (long long )A[ i ]*(long long )k - 1 );
    }
    int p = 1;
    for ( set< long long > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            long long num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< int , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< int > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        if( A[ i ] != 1 ) v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
        if( A[ i ] == 1 ) c1++;
    }
    int p = 1;
    for ( set< int > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += ( r1 )*( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< int , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< int > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        if( A[ i ] != 1 ) v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
        if( A[ i ] == 1 ) c1++;
    }
    int p = 1;
    for ( set< int > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
    }
    int p = 1;
    for ( set< long long > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< int , int > M;

int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< int > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
        if( A[ i ] == 1 ) c1++;
    }
    int p = 1;
    for ( set< int > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );

    if( k == 1 ){
        cout<<c1*( c1 - 1 )*( c1 -2 )/6<<endl;
        return 0;
    }
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += ( r1 )*( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
        BIT2.update( M[ A[ i ] ] , -1 );
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< int , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< int > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
    }
    int p = 1;
    for ( set< int > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int A[ 200003 ];
#define MAXVAL 1000000
struct FT{
    int bit[ MAXVAL + 5 ];
    FT(){ memset( bit , 0 , sizeof( bit ) ); }
    void update( int pos , int val ){
        while ( pos <= MAXVAL ){
            bit[ pos ] += val;
            pos += (pos & -pos);
        }
        return ;
    }
    int query( int pos ){
        int  sum = 0;
        while ( pos ){
            sum += bit[ pos ];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
map< long long , int > M;
int main(){
    int n ,k ,c1 = 0;
    FT BIT1 , BIT2;
    cin>>n>>k;
    set< long long > v;
    for ( int i = 0 ; i < n; i++ ){
        cin>>A[ i ];
        v.insert( A[ i ] );
        v.insert( A[ i ] - 1 );
        v.insert( A[ i ]/k  );
        v.insert( A[ i ]/k - 1 );
        v.insert( A[ i ]*k  );
        v.insert( A[ i ]*k - 1 );
    }
    int p = 1;
    for ( set< int > :: iterator it = v.begin() ; it != v.end() ; it ++ ){
        M[ *it ] = p++;
    }
    for ( int i = 0 ; i < n ; i++ ) BIT2.update( M[ A[ i ] ] , 1 );
    long long  ans = 0;
    for ( int i = 0 ; i < n ; i++ ){
        BIT2.update( M[ A[ i ] ] , -1 );
        if( A[ i ] % k == 0 ){
            int num1 = A[ i ]/k, num2 = A[ i ]*k;
            int r1 = BIT1.query( M[ num1 ]) - BIT1.query( M[ num1 - 1 ] );
            int r2 = BIT2.query( M[ num2 ]) - BIT2.query( M[ num2 - 1 ] );
            ans += (long long)( r1 )*(long long)( r2 );
        }
        BIT1.update( M[ A[ i ] ] , 1 );
    }
    cout<<ans<<endl;
}


#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,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);
		}
		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,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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

				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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

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

			}
		}

		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=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,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];

		}

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

		}

		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=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);
}
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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

				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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

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

			}
		}

		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 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,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);
        }
        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=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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

				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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

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

			}
		}

		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=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];
}
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);
}
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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

				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=1;i<=cnt;i++)
					for(int j=1;j<=3;j++)dp[i][j]=0;

				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;
}