import java.io.*;
import java.io.PrintWriter;
import java.util.*;
import java.io.InputStream;
import java.io.DataInputStream;

public class Main
{//static{ System.out.println("hello");}

   public static void main(String[] args) throws IOException
     {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader scn = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HashMap<Integer,ArrayList<Integer>> hm=new HashMap<Integer,ArrayList<Integer>>();
   int n=scn.ni();
   int k=scn.ni();
int a[]=new int[n];
   int cnt=0;
   for (int i=0; i<n; i++)
{   a[i]=scn.ni();

   if (hm.containsKey(a[i]))
   {
   	hm.get(a[i]).add(i);
   }
   else
   {
   	hm.put(a[i],new ArrayList<Integer>() );
   	hm.get(a[i]).add(i);
   }

 }
 long ans=0l;

          for (int i=0; i<n; i++)
    {int idx1=0;
        if (hm.containsKey(a[i]*k))
       { idx1=Collections.binarySearch(hm.get(a[i]*k),i);
//    System.out.println(idx1+"hi"+i);
        if (idx1<0){ idx1=-idx1-1; idx1=hm.get(a[i]*k).size()-idx1; }
        else { idx1=hm.get(a[i]).size()-1-idx1; }

       }

        int idx2=0;
        if (a[i]%k==0 && hm.containsKey(a[i]/k))
       { idx2=Collections.binarySearch(hm.get(a[i]/k),i);

        if (idx2<0){ idx2=-idx2-1;  }
        else { idx2=Math.max(idx2,0);}
       }
        //   out.println(idx1+" "+idx2);
        ans+=(idx1*idx2);

    }
    out.println(ans);

      out.close();
   }

 }

  class num implements Comparator<num>
    {

        public int ff;
        public int ss;

        num()
        {

        }
        num(int x,int y)
        {
            this.ff = x;
            this.ss =y;

        }
        public int getff()
        {
        return ff;
        }
        public int getss()
        {
        return ss;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.ff==n.ff && this.ss==n.ss) return true;
        else return false;

        }

         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ff;
        result = prime * result+ss;

        return result;
       }

       public int compare(num o1, num o2) {
              if (o1.ff!=o2.ff)
               return o1.ff-o2.ff;
               else
               return o1.ss-o2.ss;
        }

    }

class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {

            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


import java.io.*;
import java.io.PrintWriter;
import java.util.*;
import java.io.InputStream;
import java.io.DataInputStream;

public class Main
{//static{ System.out.println("hello");}

   public static void main(String[] args) throws IOException
     {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader scn = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HashMap<Long,ArrayList<Integer>> hm=new HashMap<Long,ArrayList<Integer>>();
   int n=scn.ni();
   int k=scn.ni();
int a[]=new int[n];
   int cnt=0;
   for (int i=0; i<n; i++)
{   a[i]=scn.ni();

   if (hm.containsKey(a[i]*1l))
   {
    hm.get(a[i]*1l).add(i);
   }
   else
   {
    hm.put(a[i]*1l,new ArrayList<Integer>() );
    hm.get(a[i]*1l).add(i);
   }

 }
 long ans=0l;

          for (int i=0; i<n; i++)
    {long idx1=0;
        if (hm.containsKey(a[i]*1l*k))
       { idx1=Collections.binarySearch(hm.get(a[i]*1l*k),i);
//    System.out.println(idx1+"hi"+i);
        if (idx1<0){ idx1=-idx1-1; idx1=hm.get(a[i]*1l*k).size()-idx1; }
        else { idx1=hm.get(a[i]*1l).size()-1-idx1; }

       }

       long idx2=0;
        if (a[i]%k==0 && hm.containsKey(1l*a[i]/k))
       { idx2=Collections.binarySearch(hm.get(1l*a[i]/k),i);

        if (idx2<0){ idx2=-idx2-1;  }
        else { idx2=Math.max(idx2,0);}
       }
        //   out.println(idx1+" "+idx2);
        ans+=(idx1*idx2);

    }
    out.println(ans);

      out.close();
   }

 }

  class num implements Comparator<num>
    {

        public int ff;
        public int ss;

        num()
        {

        }
        num(int x,int y)
        {
            this.ff = x;
            this.ss =y;

        }
        public int getff()
        {
        return ff;
        }
        public int getss()
        {
        return ss;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.ff==n.ff && this.ss==n.ss) return true;
        else return false;

        }

         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ff;
        result = prime * result+ss;

        return result;
       }

       public int compare(num o1, num o2) {
              if (o1.ff!=o2.ff)
               return o1.ff-o2.ff;
               else
               return o1.ss-o2.ss;
        }

    }

class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {

            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


import java.io.*;
import java.io.PrintWriter;
import java.util.*;
import java.io.InputStream;
import java.io.DataInputStream;

public class Main
{//static{ System.out.println("hello");}

   public static void main(String[] args) throws IOException
     {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader scn = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HashMap<Integer,ArrayList<Integer>> hm=new HashMap<Integer,ArrayList<Integer>>();
   int n=scn.ni();
   int k=scn.ni();
int a[]=new int[n];
   int cnt=0;
   for (int i=0; i<n; i++)
{   a[i]=scn.ni();

   if (hm.containsKey(a[i]))
   {
   	hm.get(a[i]).add(i);
   }
   else
   {
   	hm.put(a[i],new ArrayList<Integer>() );
   	hm.get(a[i]).add(i);
   }

 }
 long ans=0l;

          for (int i=0; i<n; i++)
    {long idx1=0;
        if (hm.containsKey(a[i]*k))
       { idx1=Collections.binarySearch(hm.get(a[i]*k),i);
//    System.out.println(idx1+"hi"+i);
        if (idx1<0){ idx1=-idx1-1; idx1=hm.get(a[i]*k).size()-idx1; }
        else { idx1=hm.get(a[i]).size()-1-idx1; }

       }

       long idx2=0;
        if (a[i]%k==0 && hm.containsKey(a[i]/k))
       { idx2=Collections.binarySearch(hm.get(a[i]/k),i);

        if (idx2<0){ idx2=-idx2-1;  }
        else { idx2=Math.max(idx2,0);}
       }
        //   out.println(idx1+" "+idx2);
        ans+=(idx1*idx2);

    }
    out.println(ans);

      out.close();
   }

 }

  class num implements Comparator<num>
    {

        public int ff;
        public int ss;

        num()
        {

        }
        num(int x,int y)
        {
            this.ff = x;
            this.ss =y;

        }
        public int getff()
        {
        return ff;
        }
        public int getss()
        {
        return ss;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.ff==n.ff && this.ss==n.ss) return true;
        else return false;

        }

         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ff;
        result = prime * result+ss;

        return result;
       }

       public int compare(num o1, num o2) {
              if (o1.ff!=o2.ff)
               return o1.ff-o2.ff;
               else
               return o1.ss-o2.ss;
        }

    }

class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {

            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Solution {

	public static void main(String args[])
	{
		FasterScanner s=new FasterScanner ();
		int n=s.nextInt();
		int k=s.nextInt();

		long a[]=s.nextLongArray(n);

		long ans=0;
		Hashtable<Long, Long> hash=new Hashtable<>();

		if(k==1)
		{
			for(int i=n-1;i>=0;i--)
			{
				if(hash.containsKey(a[i]))
					hash.put(a[i],hash.get(a[i])+1);
				else
					hash.put(a[i], 1l);
			}
			for(Long key:hash.keySet())
			{
				long x=hash.get(key);
				ans+=x*(x-1)*(x-2)/3/2;
			}
			System.out.println(ans);
			return;
		}
		Hashtable<Long,Long> count=new Hashtable<>();
		for(int i=n-1;i>=0;i--)
		{
			if(count.containsKey(a[i]*k))
				ans+=count.get(a[i]*k);
			if(hash.containsKey(a[i]*k))
			{
				if(count.containsKey(a[i]))
					count.put(a[i], count.get(a[i])+hash.get(a[i]*k));
				else
					count.put(a[i], hash.get(a[i]*k));
			}
			if(hash.containsKey(a[i]))
				hash.put(a[i],hash.get(a[i])+1);
			else
				hash.put(a[i], 1l);
		}
		System.out.println(ans);
	}

	static class Node implements Comparable<Node>
	{
		char c;
		int d;
		int x;
		int y;
		@Override
		public int compareTo(Node o) {

			if(d>o.d)
				return 1;
			if(d<o.d)
				return -1;
			if(x>o.x)
				return 1;
			if(x<o.x)
				return -1;
			if(y>o.y)
				return 1;
			if(y<o.y)
				return -1;
			return 0;
		}

	}

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Solution {

	public static void main(String args[])
	{
		FasterScanner s=new FasterScanner ();
		int n=s.nextInt();
		int k=s.nextInt();

		long a[]=s.nextLongArray(n);

		long ans=0;
		Hashtable<Long, Integer> hash=new Hashtable<>();

		if(k==1)
		{
			for(int i=n-1;i>=0;i--)
			{
				if(hash.containsKey(a[i]))
					hash.put(a[i],hash.get(a[i])+1);
				else
					hash.put(a[i], 1);
			}
			for(Long key:hash.keySet())
			{
				int x=hash.get(key);
				ans+=x*(x-1)*(x-2)/3/2;
			}
			System.out.println(ans);
			return;
		}
		Hashtable<Long,Integer> count=new Hashtable<>();
		for(int i=n-1;i>=0;i--)
		{
			if(count.containsKey(a[i]*k))
				ans+=count.get(a[i]*k);
			if(hash.containsKey(a[i]*k))
			{
				if(count.containsKey(a[i]))
					count.put(a[i], count.get(a[i])+hash.get(a[i]*k));
				else
					count.put(a[i], hash.get(a[i]*k));
			}
			if(hash.containsKey(a[i]))
				hash.put(a[i],hash.get(a[i])+1);
			else
				hash.put(a[i], 1);
//			System.out.println(hash);
//			System.out.println(count);
//			System.out.println(ans);
		}
		System.out.println(ans);
	}

	static class Node implements Comparable<Node>
	{
		char c;
		int d;
		int x;
		int y;
		@Override
		public int compareTo(Node o) {

			if(d>o.d)
				return 1;
			if(d<o.d)
				return -1;
			if(x>o.x)
				return 1;
			if(x<o.x)
				return -1;
			if(y>o.y)
				return 1;
			if(y<o.y)
				return -1;
			return 0;
		}

	}

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Solution {

	public static void main(String args[])
	{
		FasterScanner s=new FasterScanner ();
		int n=s.nextInt();
		int k=s.nextInt();

		long a[]=s.nextLongArray(n);

		long ans=0;
		Hashtable<Long, Integer> hash=new Hashtable<>();

		if(k==1)
		{
			for(int i=n-1;i>=0;i--)
			{
				if(hash.containsKey(a[i]))
					hash.put(a[i],hash.get(a[i])+1);
				else
					hash.put(a[i], 1);
			}
			for(Long key:hash.keySet())
			{
				int x=hash.get(key);
				ans+=x*(x-1)*(x-2)/3/2;
			}
			System.out.println(ans);
			return;
		}
		int zero=0;
		Hashtable<Long,Integer> count=new Hashtable<>();
		for(int i=n-1;i>=0;i--)
		{
			if(a[i]==0)
				zero++;
			if(count.containsKey(a[i]*k))
				ans+=count.get(a[i]*k);
			if(hash.containsKey(a[i]*k))
			{
				if(count.containsKey(a[i]))
					count.put(a[i], count.get(a[i])+hash.get(a[i]*k));
				else
					count.put(a[i], hash.get(a[i]*k));
			}
			if(hash.containsKey(a[i]))
				hash.put(a[i],hash.get(a[i])+1);
			else
				hash.put(a[i], 1);
		}
		System.out.println(ans+(zero*(zero-1)*(zero-2)/3/2));
	}

	static class Node implements Comparable<Node>
	{
		char c;
		int d;
		int x;
		int y;
		@Override
		public int compareTo(Node o) {

			if(d>o.d)
				return 1;
			if(d<o.d)
				return -1;
			if(x>o.x)
				return 1;
			if(x<o.x)
				return -1;
			if(y>o.y)
				return 1;
			if(y<o.y)
				return -1;
			return 0;
		}

	}

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Solution {

	public static void main(String args[])
	{
		FasterScanner s=new FasterScanner ();
		int n=s.nextInt();
		int k=s.nextInt();

		long a[]=s.nextLongArray(n);

		long ans=0;
		Hashtable<Long, Integer> hash=new Hashtable<>();

//		if(k==1)
//		{
//			for(int i=n-1;i>=0;i--)
//			{
//				if(hash.containsKey(a[i]))
//					hash.put(a[i],hash.get(a[i])+1);
//				else
//					hash.put(a[i], 1);
//			}
//			for(Long key:hash.keySet())
//			{
//				int x=hash.get(key);
//				ans+=x*(x-1)*(x-2)/3/2;
//			}
//			System.out.println(ans);
//			return;
//		}
		Hashtable<Long,Integer> count=new Hashtable<>();
		for(int i=n-1;i>=0;i--)
		{
			if(count.containsKey(a[i]*k))
				ans+=count.get(a[i]*k);
			if(hash.containsKey(a[i]*k))
			{
				if(count.containsKey(a[i]))
					count.put(a[i], count.get(a[i])+hash.get(a[i]*k));
				else
					count.put(a[i], hash.get(a[i]*k));
			}
			if(hash.containsKey(a[i]))
				hash.put(a[i],hash.get(a[i])+1);
			else
				hash.put(a[i], 1);
//			System.out.println(hash);
//			System.out.println(count);
//			System.out.println(ans);
		}
		System.out.println(ans);
	}

	static class Node implements Comparable<Node>
	{
		char c;
		int d;
		int x;
		int y;
		@Override
		public int compareTo(Node o) {

			if(d>o.d)
				return 1;
			if(d<o.d)
				return -1;
			if(x>o.x)
				return 1;
			if(x<o.x)
				return -1;
			if(y>o.y)
				return 1;
			if(y<o.y)
				return -1;
			return 0;
		}

	}

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[][] cnt = new int[n][4];
            Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
            int ways = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                cnt[i][1] = 1;
                if (a % k == 0 && map.containsKey(a / k)) {
                    for (int index : map.get(a / k)) {
                        cnt[i][2] += cnt[index][1];
                        cnt[i][3] += cnt[index][2];
                    }
                }
                if (!map.containsKey(a)) map.put(a, new LinkedList<Integer>());
                map.get(a).add(i);
                ways += cnt[i][3];
            }
            out.println(ways);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[][] cnt = new int[n][4];
            Map<Integer, List<Integer>> map = new HashMap<>();
            int ways = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                cnt[i][1] = 1;
                if (a % k == 0 && map.containsKey(a / k)) {
                    for (int index : map.get(a / k)) {
                        cnt[i][2] += cnt[index][1];
                        cnt[i][3] += cnt[index][2];
                    }
                }
                if (!map.containsKey(a)) map.put(a, new LinkedList<>());
                map.get(a).add(i);
                ways += cnt[i][3];
            }
            out.println(ways);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Map<Integer, List<Integer>> map = new HashMap<>();
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                set.add(a);
                if (!map.containsKey(a))
                    map.put(a, new ArrayList<>());
                map.get(a).add(i);
            }
            int ways = 0;
            for (int first : set) {
                int second = first * k;
                int third = second * k;
                if (set.contains(second) && set.contains(third)) {
                    for (int a : map.get(first)) {
                        List<Integer> cur = map.get(second);
                        for (int b : map.get(second)) {
                            if (b <= a) continue;
                            for (int c : map.get(third)) {
                                if (c <= b) continue;
                                ways++;
                            }
                        }
                    }
                }
            }
            out.println(ways);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Map<Integer, TaskC.Ways> map = new HashMap<Integer, TaskC.Ways>();
            long cnt = 0;
            for (int i = 0; i < n; i++) {
                int cur = in.nextInt();
                long two = 0;
                if (cur % k == 0 && map.containsKey(cur / k)) {
                    two = map.get(cur / k).one;
                    cnt += map.get(cur / k).two;
                }
                if (!map.containsKey(cur)) map.put(cur, new TaskC.Ways());
                map.get(cur).one = map.get(cur).one + 1;
                map.get(cur).two = map.get(cur).two + two;
            }
            out.println(cnt);
        }

        private static class Ways {
            long one;
            long two;

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Map<Integer, TaskC.Ways> map = new HashMap<Integer, TaskC.Ways>();
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                int cur = in.nextInt();
                int two = 0;
                if (cur % k == 0 && map.containsKey(cur / k)) {
                    two = map.get(cur / k).one;
                    cnt += map.get(cur / k).two;
                }
                if (!map.containsKey(cur)) map.put(cur, new TaskC.Ways());
                map.get(cur).one = map.get(cur).one + 1;
                map.get(cur).two = map.get(cur).two + two;
            }
            out.println(cnt);
        }

        private static class Ways {
            int one;
            int two;

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String [] args) throws IOException{

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer tkn = new StringTokenizer(input.readLine());
		int N = Integer.parseInt(tkn.nextToken());
		int K = Integer.parseInt(tkn.nextToken());

		long answer = 0;

		HashMap<Long,Integer> firstLayer = new HashMap<Long,Integer>();
		HashMap<Long,Integer> secondLayer = new HashMap<Long,Integer>();

		tkn = new StringTokenizer(input.readLine());
		for(int i=0;i<N;i++) {

			Long rakam = Long.parseLong(tkn.nextToken());

			if(secondLayer.containsKey(rakam))
				answer+= secondLayer.get(rakam);

			if(firstLayer.containsKey(rakam)){

				if(secondLayer.containsKey(rakam*K))
					secondLayer.put(rakam*K, secondLayer.get(rakam*K)+firstLayer.get(rakam));
				else
					secondLayer.put(rakam*K, firstLayer.get(rakam));

			}

			if(firstLayer.containsKey(rakam*K))
				firstLayer.put(rakam*K, firstLayer.get(rakam*K)+1);

			else
			firstLayer.put(rakam*K, 1);

		}
		System.out.println(answer);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String [] args) throws IOException{

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer tkn = new StringTokenizer(input.readLine());
		int N = Integer.parseInt(tkn.nextToken());
		int K = Integer.parseInt(tkn.nextToken());

		long answer = 0;

		HashMap<Long,Long> firstLayer = new HashMap<Long,Long>();
		HashMap<Long,Long> secondLayer = new HashMap<Long,Long>();

		tkn = new StringTokenizer(input.readLine());
		for(int i=0;i<N;i++) {

			long rakam = Long.parseLong(tkn.nextToken());

			if(secondLayer.containsKey(rakam))
				answer+= secondLayer.get(rakam);

			if(firstLayer.containsKey(rakam)){

				if(secondLayer.containsKey(rakam*K))
					secondLayer.put(rakam*K, secondLayer.get(rakam*K)+firstLayer.get(rakam));
				else
					secondLayer.put(rakam*K, firstLayer.get(rakam));

			}

			if(firstLayer.containsKey(rakam*K))
				firstLayer.put(rakam*K, firstLayer.get(rakam*K)+1);

			else
			firstLayer.put(rakam*K,(long) 1);

		}
		System.out.println(answer);

	}

}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.*;
import java.math.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

    void solve() throws Exception {
    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	HashMap<Integer, Long>[] cnt = new HashMap[3];
    	for (int i = 0; i < 3; i++) {
    		cnt[i] = new HashMap<Integer, Long>();
    	}
    	long ans = 0;
    	for (int i = 0; i < n; i++) {
    		int x = sc.nextInt();
    		for (int j = 0; j < 3; j++) {
    			if (!cnt[j].containsKey(x))
    				cnt[j].put(x, 0L);
    		}
    		if (x % k == 0) {
    			int y = x / k;
    			if (cnt[1].containsKey(y)) {
    				cnt[2].put(x, cnt[2].get(x) + cnt[1].get(y));
    			}
    			if (cnt[0].containsKey(y)) {
    				cnt[1].put(x, cnt[1].get(x) + cnt[0].get(y));
    			}
    		}
			cnt[0].put(x, cnt[0].get(x) + 1);
    	}
    	for (Entry<Integer, Long> x : cnt[2].entrySet()) {
    		ans += x.getValue();
    	}
    	out.println(ans);
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    final String INPUT_FILE = "stdin";
    final String OUTPUT_FILE = "stdout";

    static Throwable throwable;

    public static void main(String[] args) throws Throwable {
        Thread thread = new Thread(null, new Solution(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (throwable != null)
            throw throwable;
    }

    public void run() {
        try {
            if (INPUT_FILE.equals("stdin"))
                in = new BufferedReader(new InputStreamReader(System.in));
            else
                in = new BufferedReader(new FileReader(INPUT_FILE));
            if (OUTPUT_FILE.equals("stdout"))
                out = new PrintWriter(System.out);
            else
                out = new PrintWriter(new FileWriter(OUTPUT_FILE));
            sc = new FastScanner(in);
            solve();
        } catch (Exception e) {
            throwable = e;
        } finally {
            out.close();
        }
    }
}

class FastScanner {
    BufferedReader reader;
    StringTokenizer strTok;

    FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws Exception {
        while (strTok == null || !strTok.hasMoreTokens())
            strTok = new StringTokenizer(reader.readLine());
        return strTok.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static HashMap<Integer,Integer> cnt = new HashMap<Integer,Integer>();
    static HashMap<Integer,Integer> M = new HashMap<Integer,Integer>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                if (!M.containsKey(x)) M.put(x, 0);
                ans+=M.get(x);
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                if (!M.containsKey(x)) M.put(x, 0);
                if (!cnt.containsKey(x)) cnt.put(x, 0);
                M.put(x,M.get(x)+cnt.get(x));
            }

            if (!cnt.containsKey(a[i])) cnt.put(a[i], 0);
            cnt.put(a[i], cnt.get(a[i])+1);
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static int cnt[] = new int[maxn];
    static int M[] = new int[maxn];

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*k)==0) {
                int x = a[i]/(k*k);
                ans+=M[x];
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                M[x] += cnt[x];
            }
            cnt[a[i]]++;
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static int cnt[] = new int[maxn];
    static int M[] = new int[maxn];

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                ans+=M[x];
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                M[x] += cnt[x];
            }
            cnt[a[i]]++;
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static long ans = 0;
    static HashMap<Integer,Integer> cnt = new HashMap<Integer,Integer>();
    static HashMap<Integer,Long> M = new HashMap<Integer,Long>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                if (!M.containsKey(x)) M.put(x, 0L);
                ans+=M.get(x);
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                if (!M.containsKey(x)) M.put(x, 0L);
                if (!cnt.containsKey(x)) cnt.put(x, 0);
                M.put(x,M.get(x)+cnt.get(x));
            }

            if (!cnt.containsKey(a[i])) cnt.put(a[i], 0);
            cnt.put(a[i], cnt.get(a[i])+1);
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static HashMap<Integer,Integer> cnt = new HashMap<Integer,Integer>();
    static HashMap<Integer,Integer> M = new HashMap<Integer,Integer>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                ans+=M.get(x);
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                if (!M.containsKey(x)) M.put(x, 0);
                M.put(x,M.get(x)+cnt.get(x));
            }
            if (!cnt.containsKey(a[i])) cnt.put(a[i], 0);
            cnt.put(a[i], cnt.get(a[i])+1);
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)1e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            int t = in.nextInt();
            if (map.containsKey(t)) {
                ArrayList<Integer> list = map.get(t);
                list.add(i);
                map.put(t, list);
            } else {
                ArrayList<Integer> list = new ArrayList<Integer>();
                list.add(i);
                map.put(t,list);
            }
        }

        for (Map.Entry<Integer, ArrayList<Integer>> entry : map.entrySet()) {
            ArrayList<Integer> list = entry.getValue();
            for (int i=0; i<list.size(); i++) {
                calc(list.get(i), entry.getKey(),1);
            }
        }

        out.println(ans);
    }

    private static void calc(int pos, int val, int cnt) {
        if (cnt==3) {
//          out.println(val);
            ans++;
            return;
        }

        if (map.containsKey(val*k)) {
            ArrayList<Integer> list = map.get(val*k);
            int ind = binarySearch(pos, list);
            if (ind>=list.size()) return;
            for (int j=ind; j<list.size(); j++) {
                calc(list.get(j),val*k,cnt+1);
            }
        }
    }

    private static int binarySearch(int val, ArrayList<Integer> list) {
        int l = 0;
        int r = list.size()-1;
        while (l<=r) {
            int mid = (l+r)/2;
            if (list.get(mid)<=val) {
                l = mid+1;
            } else {
                r = mid-1;
            }
        }

        return l;
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static int ans = 0;
    static HashMap<Integer,Integer> cnt = new HashMap<Integer,Integer>();
    static HashMap<Integer,Integer> M = new HashMap<Integer,Integer>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                if (!M.containsKey(x)) M.put(x, 0);
                ans+=M.get(x);
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                if (!M.containsKey(x)) M.put(x, 0);
                if (!cnt.containsKey(x)) cnt.put(a[i], 0);
                M.put(x,M.get(x)+cnt.get(x));
            }

            if (!cnt.containsKey(a[i])) cnt.put(a[i], 0);
            cnt.put(a[i], cnt.get(a[i])+1);
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.KeyStore.Entry;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)2e5+111;
    static int inf = (int)1e9;
    static int n,k;
    static int a[] = new int[maxn];
    static long ans = 0;
    static HashMap<Integer,Integer> cnt = new HashMap<Integer,Integer>();
    static HashMap<Integer,Integer> M = new HashMap<Integer,Integer>();

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }

        for (int i=1; i<=n; i++) {
            if (a[i]%(k*1L*k)==0) {
                int x = a[i]/k/k;
                if (!M.containsKey(x)) M.put(x, 0);
                ans+=M.get(x);
            }
            if (a[i]%k==0) {
                int x = a[i]/k;
                if (!M.containsKey(x)) M.put(x, 0);
                if (!cnt.containsKey(x)) cnt.put(x, 0);
                M.put(x,M.get(x)+cnt.get(x));
            }

            if (!cnt.containsKey(a[i])) cnt.put(a[i], 0);
            cnt.put(a[i], cnt.get(a[i])+1);
        }

        out.println(ans);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }

    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public void solve() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}
		scanner.close();

		if (K == 1) {
			Arrays.sort(a);

			long ans = 0;
			long cnt = 0;
			for (int i = 0; i < N; i++) {
				cnt++;
				if (i == N - 1 || a[i] != a[i + 1]) {
					if (cnt >= 3) {
						long tmp = 1;
						tmp *= cnt * (cnt - 1) * (cnt - 2);
						tmp /= 6;
						ans += tmp;
					}
					cnt = 0;
				}
			}
			System.out.println(ans);
			return;
		}

		long ans = 0;
		HashMap<Integer, Long> countMap = new HashMap<>();
		HashMap<Integer, Long> dimMap = new HashMap<>();
		for (int i = 0; i < N; i++) {
			// 一番下の時
			if (countMap.containsKey(a[i])) {
				countMap.put(a[i], countMap.get(a[i]) + 1);
			} else {
				countMap.put(a[i], 1L);
			}

			// 真ん中の時
			if (a[i] % K != 0) {
				continue;
			}
			if (dimMap.containsKey(a[i]) && countMap.containsKey(a[i] / K)) {
				dimMap.put(a[i], dimMap.get(a[i]) + countMap.get(a[i] / K));
			} else if (countMap.containsKey(a[i] / K)) {
				dimMap.put(a[i], countMap.get(a[i] / K));
			}

			// 一番上の時
			if (dimMap.containsKey(a[i] / K)) {
				ans += dimMap.get(a[i] / K);
			}
		}
		System.out.println(ans);

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public void solve() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}
		scanner.close();
//
//		if (K == 1) {
//			Arrays.sort(a);
//
//			long ans = 0;
//			long cnt = 0;
//			for (int i = 0; i < N; i++) {
//				cnt++;
//				if (i == N - 1 || a[i] != a[i + 1]) {
//					if (cnt >= 3) {
//						long tmp = 1;
//						tmp *= cnt * (cnt - 1) * (cnt - 2);
//						tmp /= 6;
//						ans += tmp;
//					}
//					cnt = 0;
//				}
//			}
//			System.out.println(ans);
//			return;
//		}

		long ans = 0;
		HashMap<Integer, Long> countMap = new HashMap<>();
		HashMap<Integer, Long> dimMap = new HashMap<>();
		for (int i = 0; i < N; i++) {
			// 一番下の時
			if (countMap.containsKey(a[i])) {
				countMap.put(a[i], countMap.get(a[i]) + 1);
			} else {
				countMap.put(a[i], 1L);
			}

			// 真ん中の時
			if (a[i] % K != 0) {
				continue;
			}
			int child = a[i] / K;
			if (dimMap.containsKey(a[i]) && countMap.containsKey(child)) {
				dimMap.put(a[i], dimMap.get(a[i]) + countMap.get(child));
			} else if (countMap.containsKey(child)) {
				dimMap.put(a[i], countMap.get(child));
			}

			// 一番上の時
			if (dimMap.containsKey(child)) {
				ans += dimMap.get(child);
			}
		}
		System.out.println(ans);

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public void solve() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}
		scanner.close();

		if (K == 1) {
			Arrays.sort(a);

			long ans = 0;
			long cnt = 0;
			for (int i = 0; i < N; i++) {
				cnt++;
				if (i == N - 1 || a[i] != a[i + 1]) {
					if (cnt >= 3) {
						long tmp = 1;
						tmp *= cnt * (cnt - 1) * (cnt - 2);
						tmp /= 6;
						ans += tmp;
					}
					cnt = 0;
				}
			}
			System.out.println(ans);
			return;
		}

		long ans = 0;
		HashMap<Integer, Integer> countMap = new HashMap<>();
		HashMap<Integer, Integer> dimMap = new HashMap<>();
		for (int i = 0; i < N; i++) {
			// 一番下の時
			if (countMap.containsKey(a[i])) {
				countMap.put(a[i], countMap.get(a[i]) + 1);
			} else {
				countMap.put(a[i], 1);
			}

			// 真ん中の時
			if (a[i] % K != 0) {
				continue;
			}
			if (dimMap.containsKey(a[i]) && countMap.containsKey(a[i] / K)) {
				dimMap.put(a[i], dimMap.get(a[i]) + countMap.get(a[i] / K));
			} else if (countMap.containsKey(a[i] / K)) {
				dimMap.put(a[i], countMap.get(a[i] / K));
			}

			// 一番上の時
			if (dimMap.containsKey(a[i] / K)) {
				ans += dimMap.get(a[i] / K);
			}
		}
		System.out.println(ans);

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public void solve() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}
		scanner.close();

		if (K == 1) {
			Arrays.sort(a);

			long ans = 0;
			long cnt = 0;
			for (int i = 0; i < N; i++) {
				cnt++;
				if (i == N - 1 || a[i] != a[i + 1]) {
					if (cnt >= 3) {
						long tmp = 1;
						tmp *= cnt * (cnt - 1) * (cnt - 2);
						tmp /= 6;
						ans += tmp;
					}
					cnt = 0;
				}
			}
			System.out.println(ans);
			return;
		}

		long ans = 0;
		long zeroCnt = 0;
		HashMap<Integer, Long> countMap = new HashMap<>();
		HashMap<Integer, Long> dimMap = new HashMap<>();
		for (int i = 0; i < N; i++) {
			// ゼロの時は別途対応
			if (a[i] == 0) {
				zeroCnt++;
				continue;
			}

			// 一番下の時
			if (countMap.containsKey(a[i])) {
				countMap.put(a[i], countMap.get(a[i]) + 1);
			} else {
				countMap.put(a[i], 1L);
			}

			// 真ん中の時
			if (a[i] % K != 0) {
				continue;
			}
			int child = a[i] / K;
			if (dimMap.containsKey(a[i]) && countMap.containsKey(child)) {
				dimMap.put(a[i], dimMap.get(a[i]) + countMap.get(child));
			} else if (countMap.containsKey(child)) {
				dimMap.put(a[i], countMap.get(child));
			}

			// 一番上の時
			if (dimMap.containsKey(child)) {
				ans += dimMap.get(child);
			}
		}

		// ゼロの中から3つゼロを取り出す組み合わせ
		long tmp = zeroCnt * (zeroCnt - 1) * (zeroCnt - 2);
		tmp /= 6;
		ans += tmp;

		System.out.println(ans);

	}

	public static void main(String[] args) {
		new Main().solve();
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main3 {
    public static int n, k, nk, b;
    public static void fact(int value)
    {
        nk = 0;
        while( value % k == 0)
        {
            nk++;
            value /= k;
        }
        b = value;

    }
public static void main(String[] args) throws IOException {
    BufferedReader in;
    StringBuilder out = new StringBuilder();
    File file = new File("in");
    if (file.exists())
        in = new BufferedReader(new FileReader(file));
    else
        in = new BufferedReader(new InputStreamReader(System.in));
    String line, lines[];

    lines = in.readLine().split(" ");
    n = Integer.parseInt(lines[0]);
    k = Integer.parseInt(lines[1]);
    lines = in.readLine().split(" ");
    int arr[] = new int[n];
    ArrayList<Integer> ls[] = new ArrayList[n];
    int keys[] = new int[n];
    int count= 0;
    for (  int i = 0; i < n; i++ )
    {
        arr[i] = Integer.parseInt(lines[i]);
    }
    if ( k != 1)
    {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        int value;
        for ( int i = 0; i < n; i++ )
        {
            fact(arr[i]);
            if ( map.containsKey(b))
            {
                value = map.get(b);
                ls[value].add(nk);
            }
            else
            {
                ls[count] = new ArrayList<Integer>();
                ls[count].add(nk);
                map.put(b, count);
                count++;
            }
        }
        long result = 0l;
        int l;
        long pow[];
        long pares[];
        for ( int i = 0; i < count; i++ )
        {
            pow = new long[30];
            pares = new long[30];
            for (int auxL : ls[i]) {
                if ( auxL >= 2)
                {
                    result += (long)(pares[auxL-1]);
                }
                if ( auxL >= 1)
                {
                    pares[auxL] += pow[auxL-1];
                }
                pow[auxL]++;
            }
        }
        System.out.println(result);
    }
    else
    {
        HashMap<Integer,Long> mapV = new HashMap<Integer, Long>();
        long r = 0l;
        long ot = 0l;
        BigInteger resp = new BigInteger("0");
        for ( int i = 0; i < n; i++ )
        {
            if ( !mapV.containsKey(arr[i]))
            {
                mapV.put(arr[i], 1l);
            }
            else
            {
                long aux = mapV.get(arr[i]);
                mapV.put(arr[i], aux+1l);
                if ( aux>= 2)
                {
                    ot = (long)(aux);
                    BigInteger auxB1 = new BigInteger(ot+"");
                    BigInteger auxB2 = new BigInteger((ot-1)+"");
                    auxB1 = auxB1.multiply(auxB2);
                    auxB1 = auxB1.divide(new BigInteger("2"));
                    resp = resp.add(auxB1);
                }
            }
        }
        System.out.println(resp.toString());
    }
}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main3 {
    public static int n, k, nk, b;
    public static void fact(int value)
    {
        nk = 0;
        while( value % k == 0)
        {
            nk++;
            value /= k;
        }
        b = value;

    }
public static void main(String[] args) throws IOException {
    BufferedReader in;
    StringBuilder out = new StringBuilder();
    File file = new File("in");
    if (file.exists())
        in = new BufferedReader(new FileReader(file));
    else
        in = new BufferedReader(new InputStreamReader(System.in));
    String line, lines[];

    lines = in.readLine().split(" ");
    n = Integer.parseInt(lines[0]);
    k = Integer.parseInt(lines[1]);
    lines = in.readLine().split(" ");
    int arr[] = new int[n];
    ArrayList<Integer> ls[] = new ArrayList[n];
    int keys[] = new int[n];
    int count= 0;
    for (  int i = 0; i < n; i++ )
    {
        arr[i] = Integer.parseInt(lines[i]);
    }
    if ( k != 1)
    {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        int value;
        for ( int i = 0; i < n; i++ )
        {
            fact(arr[i]);
            if ( map.containsKey(b))
            {
                value = map.get(b);
                ls[value].add(nk);
            }
            else
            {
                ls[count] = new ArrayList<Integer>();
                ls[count].add(nk);
                map.put(b, count);
                count++;
            }
        }
        long result = 0l;
        int l;
        int pow[];
        int pares[];
        for ( int i = 0; i < count; i++ )
        {
            pow = new int[30];
            pares = new int[30];
            for (int auxL : ls[i]) {
                if ( auxL >= 2)
                {
                    result += (long)(pares[auxL-1]);
                }
                if ( auxL >= 1)
                {
                    pares[auxL] += pow[auxL-1];
                }
                pow[auxL]++;
            }
        }
        System.out.println(result);
    }
    else
    {
        HashMap<Integer,Integer> mapV = new HashMap<Integer, Integer>();
        long r = 0;
        long ot = 0;
        for ( int i = 0; i < n; i++ )
        {
            if ( !mapV.containsKey(arr[i]))
            {
                mapV.put(arr[i], 1);
            }
            else
            {
                int aux = mapV.get(arr[i]);
                mapV.put(arr[i], aux+1);
                if ( aux>= 2)
                {
                    ot = (long)(aux);
                    r += (ot*(ot-1l))/2l;
                }
            }
        }
        System.out.println(r);
    }
}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main3 {
    public static int n, k, nk, b;
    public static void fact(int value)
    {
        nk = 0;
        while( value % k == 0)
        {
            nk++;
            value /= k;
        }
        b = value;

    }
public static void main(String[] args) throws IOException {
    BufferedReader in;
    StringBuilder out = new StringBuilder();
    File file = new File("in");
    if (file.exists())
        in = new BufferedReader(new FileReader(file));
    else
        in = new BufferedReader(new InputStreamReader(System.in));
    String line, lines[];

    lines = in.readLine().split(" ");
    n = Integer.parseInt(lines[0]);
    k = Integer.parseInt(lines[1]);
    lines = in.readLine().split(" ");
    int arr[] = new int[n];
    ArrayList<Integer> ls[] = new ArrayList[n];
    int keys[] = new int[n];
    int count= 0;
    for (  int i = 0; i < n; i++ )
    {
        arr[i] = Integer.parseInt(lines[i]);
    }
    if ( k != 1)
    {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        int value;
        for ( int i = 0; i < n; i++ )
        {
            fact(arr[i]);
            if ( map.containsKey(b))
            {
                value = map.get(b);
                ls[value].add(nk);
            }
            else
            {
                ls[count] = new ArrayList<Integer>();
                ls[count].add(nk);
                map.put(b, count);
                count++;
            }
        }
        long result = 0l;
        int l;
        int pow[];
        int pares[];
        for ( int i = 0; i < count; i++ )
        {
            pow = new int[30];
            pares = new int[30];
            for (int auxL : ls[i]) {
                if ( auxL >= 2)
                {
                    result += (long)(pares[auxL-1]);
                }
                if ( auxL >= 1)
                {
                    pares[auxL] += pow[auxL-1];
                }
                pow[auxL]++;
            }
        }
        System.out.println(result);
    }
    else
    {
        HashMap<Integer,Integer> mapV = new HashMap<Integer, Integer>();
        long r = 0;
        long ot = 0;
        for ( int i = 0; i < n; i++ )
        {
            if ( !mapV.containsKey(arr[i]))
            {
                mapV.put(arr[i], 1);
            }
            else
            {
                int aux = mapV.get(arr[i]);
                mapV.put(arr[i], aux+1);
                if ( aux>= 2)
                {
                    ot = aux;
                    r += (ot*(ot-1l))/2l;
                }
            }
        }
        System.out.println(r);
    }
}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main3 {
    public static int n, k, nk, b;
    public static void fact(int value)
    {
        nk = 0;
        while( value % k == 0)
        {
            nk++;
            value /= k;
        }
        b = value;

    }
public static void main(String[] args) throws IOException {
    BufferedReader in;
    StringBuilder out = new StringBuilder();
    File file = new File("in");
    if (file.exists())
        in = new BufferedReader(new FileReader(file));
    else
        in = new BufferedReader(new InputStreamReader(System.in));
    String line, lines[];

    lines = in.readLine().split(" ");
    n = Integer.parseInt(lines[0]);
    k = Integer.parseInt(lines[1]);
    lines = in.readLine().split(" ");
    int arr[] = new int[n];
    ArrayList<Integer> ls[] = new ArrayList[n];
    int keys[] = new int[n];
    int count= 0;
    for (  int i = 0; i < n; i++ )
    {
        arr[i] = Integer.parseInt(lines[i]);
    }
    if ( k != 1)
    {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        int value;
        for ( int i = 0; i < n; i++ )
        {
            fact(arr[i]);
            if ( map.containsKey(b))
            {
                value = map.get(b);
                ls[value].add(nk);
            }
            else
            {
                ls[count] = new ArrayList<Integer>();
                ls[count].add(nk);
                map.put(b, count);
                count++;
            }
        }
        long result = 0l;
        int l;
        int pow[];
        int pares[];
        for ( int i = 0; i < count; i++ )
        {
            pow = new int[30];
            pares = new int[30];
            for (int auxL : ls[i]) {
                if ( auxL >= 2)
                {
                    result += (long)(pares[auxL-1]);
                }
                if ( auxL >= 1)
                {
                    pares[auxL] += pow[auxL-1];
                }
                pow[auxL]++;
            }
        }
        System.out.println(result);
    }
    else
    {
        HashMap<Integer,Integer> mapV = new HashMap<Integer, Integer>();
        long r = 0;
        long ot = 0;
        for ( int i = 0; i < n; i++ )
        {
            if ( !mapV.containsKey(arr[i]))
            {
                mapV.put(arr[i], 1);
            }
            else
            {
                int aux = mapV.get(arr[i]);
                mapV.put(arr[i], aux+1);
                if ( aux>= 2)
                {
                    ot = aux;
                    r += (ot*(ot-1))/2l;
                }
            }
        }
        System.out.println(r);
    }
}
}