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

public class MainC {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	long start = System.currentTimeMillis();
	long fin = System.currentTimeMillis();
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = sc.nextLongArray(n);
		long ans = 0;
		HashMap<Long, Long> one = new HashMap<Long, Long>();
		HashMap<Long, Long> two = new HashMap<Long, Long>();
		for (int i = 0; i < n; i++) {
			if (a[i] % k == 0 && two.containsKey(a[i] / k)) {
				ans += two.get(a[i] / k);
			}
			if (a[i] % k == 0 && one.containsKey(a[i] / k)) {
				two.put(a[i], two.containsKey(a[i]) ? two.get(a[i]) + one.get(a[i] / k) : one.get(a[i] / k));
			}
			one.put(a[i], one.containsKey(a[i]) ? one.get(a[i]) + 1 : 1);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new MainC().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	boolean palindrome(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

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

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

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

		char[][] nextCharField(int n, int m) {
			char[][] in = new char[n][m];
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				for (int j = 0; j < m; j++) {
					in[i][j] = s.charAt(j);
				}
			}
			return in;
		}
	}
}


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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	long start = System.currentTimeMillis();
	long fin = System.currentTimeMillis();
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = sc.nextIntArray(n);
		HashMap<Integer, Integer> one = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> two = new HashMap<Integer, Integer>();
		long cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] % k == 0 && two.containsKey(a[i] / k)) {
				cnt += two.get(a[i] / k);
			}
			if (a[i] % k == 0 && one.containsKey(a[i] / k)) {
				int t = two.containsKey(a[i]) ? two.get(a[i]) : 0;
				two.put(a[i], t + one.get(a[i] / k));
			}
			one.put(a[i], one.containsKey(a[i]) ? one.get(a[i]) + 1 : 1);
		}
		System.out.println(cnt);
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	boolean palindrome(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

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

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

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

		char[][] nextCharField(int n, int m) {
			char[][] in = new char[n][m];
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				for (int j = 0; j < m; j++) {
					in[i][j] = s.charAt(j);
				}
			}
			return in;
		}
	}
}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
	import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
	import java.util.Stack;
	import java.util.Vector;

	public class Main {

		static long count;
		static void progression(long a,long b,long c,long k){
			long k0=1;
			long k1=k;
			long k2=k*k;
			if((double)a/k0==(double)b/k1 && (double)b/k1==(double)c/k2){
				count++;
			}
		}

		static public void solve(int []tab,int k){
			for(int i=0;i<tab.length-2;i++){
				for(int j=i+1;j<tab.length-1;j++){
					for(int l=j+1;l<tab.length;l++){
						progression(tab[i], tab[j], tab[l], k);
					}
				}
			}
		}

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			int []tab = new int [n];

			for(int i=0;i<n;i++)
				tab[i]=sc.nextInt();

			//Arrays.sort(tab);

			solve(tab,k);
			System.out.println(count);

		}

	}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;

	public class Main {

		static long count;

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			long []tab = new long [n];

			Map<Long, Long> r = new TreeMap<Long,Long>();
			Map<Long, Long> l = new TreeMap<Long,Long>();

			for(int i=0;i<n;i++){
				tab[i]=sc.nextLong();
				if(r.get(tab[i])==null)
					r.put(tab[i], (long)1);
				else
					r.put(tab[i], r.get(tab[i])+1);
			}

			long s=0,xr,xl;

			for(int i=0;i<n;i++){
				if(tab[i]%k==0){
					xl = l.get(tab[i]/k)==null?0:l.get(tab[i]/k) ;
				}
				else
					xl=0;

				r.put(tab[i], r.get(tab[i])-1);
				xr = r.get(tab[i]*k) ;
				s+=xl*xr;
				if(l.get(tab[i])==null)
					l.put(tab[i], (long)1);
				else
					l.put(tab[i], l.get(tab[i])+1);

			}

			System.out.println(s);

		}

	}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
	import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
	import java.util.Stack;
	import java.util.Vector;

	public class Main {

		static long count;
		static void progression(long a,long b,long c,long k){
			long k0=1;
			long k1=k;
			long k2=k*k;
			if(a/k0==b/k1 && b/k1==c/k2){
				count++;
			}
		}

		static public void solve(int []tab,int k){
			for(int i=0;i<tab.length-2;i++){
				for(int j=i+1;j<tab.length-1;j++){
					for(int l=j+1;l<tab.length;l++){
						progression(tab[i], tab[j], tab[l], k);
					}
				}
			}
		}

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			int []tab = new int [n];

			for(int i=0;i<n;i++)
				tab[i]=sc.nextInt();

			solve(tab,k);
			System.out.println(count);

		}

	}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;

	public class Main {

		static long count;

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			long []tab = new long [n];

			Map<Long, Long> r = new TreeMap<Long,Long>();
			Map<Long, Long> l = new TreeMap<Long,Long>();

			for(int i=0;i<n;i++){
				tab[i]=sc.nextLong();
				if(r.get(tab[i])==null)
					r.put(tab[i], (long)1);
				else
					r.put(tab[i], r.get(tab[i])+1);
			}

			long s=0,xr,xl;

			for(int i=0;i<n;i++){
				if(tab[i]%k==0){
					xl = l.get(tab[i]/k)==null?0:l.get(tab[i]/k) ;
				}
				else
					xl=0;

				r.put(tab[i], r.get(tab[i])-1);

				xr = r.get(tab[i]*k)==null?0:r.get(tab[i]*k)  ;

				s+=xl*xr;
				if(l.get(tab[i])==null)
					l.put(tab[i], (long)1);
				else
					l.put(tab[i], l.get(tab[i])+1);

			}

			System.out.println(s);

		}

	}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;

	public class Main {

		static long count;

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			long []tab = new long [n];

			Map<Long, Long> r = new HashMap<Long,Long>();
			Map<Long, Long> l = new HashMap<Long,Long>();

			for(int i=0;i<n;i++){
				tab[i]=sc.nextLong();
				if(r.get(tab[i])==null)
					r.put(tab[i], (long)1);
				else
					r.put(tab[i], r.get(tab[i])+1);
			}

			long s=0,xr,xl;

			for(int i=0;i<n;i++){
				if(tab[i]%k==0){
					xl = l.get(tab[i]/k)==null?0:l.get(tab[i]/k) ;
				}
				else
					xl=0;

				r.put(tab[i], r.get(tab[i])-1);

				xr = r.get(tab[i]*k)==null?0:r.get(tab[i]*k)  ;

				s+=xl*xr;
				if(l.get(tab[i])==null)
					l.put(tab[i], (long)1);
				else
					l.put(tab[i], l.get(tab[i])+1);

			}

			System.out.println(s);

		}

	}


	import java.io.File;
	import java.io.FileNotFoundException;
	import java.math.BigInteger;
	import java.text.DecimalFormat;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
	import java.util.Stack;
	import java.util.Vector;

	public class Main {

		static long count;
		static Hashtable<String , Integer> hash = new Hashtable<>();
		static void progression(long a,long b,long c,long k){
			long k0=1;
			long k1=k;
			long k2=k*k;
			if((double)a/k0==(double)b/k1 && (double)b/k1==(double)c/k2){
				hash.put(""+a+b+c, 1);
				count++;
			}
			else{
				hash.put(""+a+b+c, 0);
			}
		}

		static public void solve(int []tab,int k){
			for(int i=0;i<tab.length-2;i++){
				for(int j=i+1;j<tab.length-1;j++){
					for(int l=j+1;l<tab.length;l++){
						if(!hash.containsKey(""+tab[i]+ tab[j]+ tab[l]))
							progression(tab[i], tab[j], tab[l], k);
						else
							count+=hash.get(""+tab[i]+ tab[j]+ tab[l]);
					}
				}
			}
		}

		public static void main(String[] args) throws FileNotFoundException {
			//Scanner sc = new Scanner (new File("in.in"));
			Scanner sc = new Scanner (System.in);

			int n  = sc.nextInt();
			int k  = sc.nextInt();
			int []tab = new int [n];

			for(int i=0;i<n;i++)
				tab[i]=sc.nextInt();

			//Arrays.sort(tab);

			solve(tab,k);
			System.out.println(count);

		}

	}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(process(in.readInt(), in.readIntArray(n)));
    }

    private static long countGP(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        long res = 0;
        HashMap<Long, Integer> left = new HashMap<Long, Integer>(ar.length);
        HashMap<Long, Integer> right = new HashMap<Long, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(1L * ar[i], 0);
            right.put(1L * ar[i], 0);
        }

        // let's populate left.
        left.put(1L * ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(1L * ar[i], right.get(1L * ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(1L * ar[i]);
            left.put(1L * ar[i], value + 1);
            value = right.get(1L * ar[i + 1]);
            right.put(1L * ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        int[] pos_ar = new int[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        int[] neg_ar = new int[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += countGP(k, pos_ar) + countGP(k, neg_ar);

        return res;
    }

    private static long getThree(int[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(int[] a) {
        int[] b = new int[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(int[] a, int[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(int[] a, int[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(process(in.readInt(), in.readIntArray(n)));
    }

    private static long process(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        int[] pos_ar = new int[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        int[] neg_ar = new int[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += compute(k, pos_ar) + compute(k, neg_ar);

        return res;
    }

    private static long getThree(int[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(int[] a) {
        int[] b = new int[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(int[] a, int[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(int[] a, int[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(process(in.readInt(), in.readIntArray(n)));
    }

    private static long countGP(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        long res = 0;
        HashMap<Integer, Integer> left =
            new HashMap<Integer, Integer>(ar.length);
        HashMap<Integer, Integer> right =
            new HashMap<Integer, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(ar[i], 0);
            right.put(ar[i], 0);
        }

        // let's populate left.
        left.put(ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(ar[i], right.get(ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(ar[i]);
            left.put(ar[i], value + 1);
            value = right.get(ar[i + 1]);
            right.put(ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        int[] pos_ar = new int[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        int[] neg_ar = new int[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += countGP(k, pos_ar) + countGP(k, neg_ar);

        return res;
    }

    private static long getThree(int[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(int[] a) {
        int[] b = new int[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(int[] a, int[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(int[] a, int[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(process(in.readInt(), in.readLongArray(n)));
    }

    private static long countGP(int k, long[] ar) {
        if (ar.length < 3)
            return 0;

        long res = 0;
        HashMap<Long, Integer> left = new HashMap<Long, Integer>(ar.length);
        HashMap<Long, Integer> right = new HashMap<Long, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(ar[i], 0);
            right.put(ar[i], 0);
        }

        // let's populate left.
        left.put(ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(ar[i], right.get(ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(ar[i]);
            left.put(ar[i], value + 1);
            value = right.get(ar[i + 1]);
            right.put(ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, long[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        long[] pos_ar = new long[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        long[] neg_ar = new long[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += countGP(k, pos_ar) + countGP(k, neg_ar);

        return res;
    }

    private static long getThree(long[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static void sort(long[] a) {
        long[] b = new long[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(long[] a, long[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(long[] a, long[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }

        public long readLong() throws IOException {
            long res = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                res = (res << 3) + (res << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            if (s == -1)
                res = -res;
            return res;
        }

        public long[] readLongArray(int n) throws IOException {
            long[] ar = new long[n];

            for (int i = 0; i < n; i++)
                ar[i] = readLong();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(process(in.readInt(), in.readLongArray(n)));
    }

    private static long countGP(int k, long[] ar) {
        if (ar.length < 3)
            return 0;

        long res = 0;
        HashMap<Long, Integer> left = new HashMap<Long, Integer>(ar.length);
        HashMap<Long, Integer> right = new HashMap<Long, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(ar[i], 0);
            right.put(ar[i], 0);
        }

        // let's populate left.
        left.put(ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(ar[i], right.get(ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(ar[i]);
            left.put(ar[i], value + 1);
            value = right.get(ar[i + 1]);
            right.put(ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, long[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        long[] pos_ar = new long[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        long[] neg_ar = new long[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += countGP(k, pos_ar) + countGP(k, neg_ar);

        return res;
    }

    private static long getThree(long[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(long[] a) {
        long[] b = new long[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(long[] a, long[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(long[] a, long[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }

        public long readLong() throws IOException {
            long res = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                res = (res << 3) + (res << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            if (s == -1)
                res = -res;
            return res;
        }

        public long[] readLongArray(int n) throws IOException {
            long[] ar = new long[n];

            for (int i = 0; i < n; i++)
                ar[i] = readLong();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(countGP(in.readInt(), in.readIntArray(n)));
    }

    private static long countGP(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        long res = 0;
        HashMap<Integer, Integer> left =
            new HashMap<Integer, Integer>(ar.length);
        HashMap<Integer, Integer> right =
            new HashMap<Integer, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(ar[i], 0);
            right.put(ar[i], 0);
        }

        // let's populate left.
        left.put(ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(ar[i], right.get(ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(ar[i]);
            left.put(ar[i], value + 1);
            value = right.get(ar[i + 1]);
            right.put(ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        int[] pos_ar = new int[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        int[] neg_ar = new int[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += compute(k, pos_ar) + compute(k, neg_ar);

        return res;
    }

    private static long getThree(int[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(int[] a) {
        int[] b = new int[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(int[] a, int[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(int[] a, int[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.HashMap;

/**
 * @author: Ashok Rajpurohit
 * problem: Geometric Progression
 * Link: http://codeforces.com/contest/567/problem/C
 */

public class CPiC {

    private static PrintWriter out;
    private static InputStream in;

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        in = System.in;
        out = new PrintWriter(outputStream);
        CPiC a = new CPiC();
        a.solve();
        out.close();
    }

    public void solve() throws IOException {
        InputReader in = new InputReader();
        int n = in.readInt();
        out.println(countGP(in.readInt(), in.readIntArray(n)));
    }

    private static long countGP(int k, int[] ar) {
        long res = 0;
        HashMap<Integer, Integer> left =
            new HashMap<Integer, Integer>(ar.length);
        HashMap<Integer, Integer> right =
            new HashMap<Integer, Integer>(ar.length);

        for (int i = 0; i < ar.length; i++) {
            left.put(ar[i], 0);
            right.put(ar[i], 0);
        }

        // let's populate left.
        left.put(ar[0], 1);

        // let's populate right.
        for (int i = 2; i < ar.length; i++)
            right.put(ar[i], right.get(ar[i]) + 1);

        for (int i = 1; i < ar.length - 1; i++) {
            if (ar[i] % k == 0) {
                if (left.containsKey(ar[i] / k) &&
                    right.containsKey(ar[i] * k))
                    res += 1L * left.get(ar[i] / k) * right.get(ar[i] * k);
            }

            int value = left.get(ar[i]);
            left.put(ar[i], value + 1);
            value = right.get(ar[i + 1]);
            right.put(ar[i + 1], value - 1);

        }

        return res;
    }

    private static long process(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        if (k == 1)
            return getThree(ar);

        int pos_count = 0; // count of positive numbers
        int neg_count = 0; // count of negative numbers

        for (int i = 0; i < ar.length; i++)
            if (ar[i] > 0)
                pos_count++;

        for (int i = 0; i < ar.length; i++)
            if (ar[i] < 0)
                neg_count++;

        int[] pos_ar = new int[pos_count];
        for (int i = 0, j = 0; i < ar.length && j < pos_count; i++)
            if (ar[i] > 0) {
                pos_ar[j] = ar[i];
                j++;
            }

        int[] neg_ar = new int[neg_count];
        for (int i = 0, j = 0; i < ar.length && j < neg_count; i++)
            if (ar[i] < 0) {
                neg_ar[j] = -ar[i];
                j++;
            }

        long res = 0, zero_count = ar.length - pos_count - neg_count;
        if (zero_count > 2)
            res = zero_count * (zero_count - 1) * (zero_count - 2) / 6;

        res += compute(k, pos_ar) + compute(k, neg_ar);

        return res;
    }

    private static long getThree(int[] ar) {
        sort(ar);
        int i = 0;
        long res = 0;
        while (i < ar.length) {
            int count = 0;
            int j = i;
            while (j < ar.length && ar[j] == ar[i]) {
                j++;
                count++;
            }

            if (count > 2)
                res += (1L * count * (count - 1) * (count - 2) / 6);

            i = j;
        }
        return res;
    }

    private static int compute(int k, int[] ar) {
        if (ar.length < 3)
            return 0;

        int res = 0;
        int[] sort = sortIndex(ar);

        int max_start = ar[sort[ar.length - 1]] / (k * k);
        if (ar[sort[0]] * k * k > ar[sort[ar.length - 1]])
            return 0;

        for (int i = 0; ar[sort[i]] <= max_start; i++) {
            int two = find(ar[sort[i]] * k, ar, sort);
            int three = find(ar[sort[i]] * k * k, ar, sort);
            if (two != -1 && three != -1) {
                for (int j = two;
                     j < ar.length && ar[sort[j]] == ar[sort[two]]; j++) {
                    if (sort[j] > sort[i]) {
                        for (int m = three;
                             m < ar.length && ar[sort[m]] == ar[sort[three]];
                             m++) {
                            if (sort[m] > sort[j])
                                res++;
                        }
                    }
                }
            }
        }
        return res;
    }

    private static int find(int value, int[] ar, int[] sort) {
        int start = 0, end = ar.length - 1, mid = (start + end) >>> 1;
        if (ar[sort[0]] == value)
            return 0;

        while (start < mid) {
            if (ar[sort[mid]] < value)
                start = mid;
            else
                end = mid;

            mid = (start + end) >>> 1;
        }

        if (ar[sort[end]] != value)
            return -1;
        //
        while (end > mid && ar[sort[end]] == value)
            end--;

        return end + 1;
    }

    private static void sort(int[] a) {
        int[] b = new int[a.length];
        sort(a, b, 0, a.length - 1);
    }

    private static void sort(int[] a, int[] b, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, begin, mid);
        sort(a, b, mid + 1, end);
        merge(a, b, begin, end);
    }

    private static void merge(int[] a, int[] b, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[i] > a[j]) {
                b[k] = a[j];
                j++;
            } else {
                b[k] = a[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = a[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = a[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            a[i] = b[i];
            i++;
        }
    }

    public static int[] sortIndex(int[] a) {
        int[] b = new int[a.length];
        int[] c = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = i;
        }
        sort(a, b, c, 0, a.length - 1);
        return c;
    }

    private static void sort(int[] a, int[] b, int[] c, int begin, int end) {
        if (begin == end) {
            return;
        }

        int mid = (begin + end) / 2;
        sort(a, b, c, begin, mid);
        sort(a, b, c, mid + 1, end);
        merge(a, b, c, begin, end);
    }

    public static void merge(int[] a, int[] b, int[] c, int begin, int end) {
        int mid = (begin + end) / 2;
        int i = begin;
        int j = mid + 1;
        int k = begin;
        while (i <= mid && j <= end) {
            if (a[c[i]] > a[c[j]]) {
                b[k] = c[j];
                j++;
            } else {
                b[k] = c[i];
                i++;
            }
            k++;
        }
        if (j <= end) {
            while (j <= end) {
                b[k] = c[j];
                k++;
                j++;
            }
        }
        if (i <= mid) {
            while (i <= mid) {
                b[k] = c[i];
                i++;
                k++;
            }
        }

        i = begin;
        while (i <= end) {
            c[i] = b[i];
            i++;
        }
    }

    final static class InputReader {
        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1)
                throw new IOException("No new bytes");
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-')
                    s = -1;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = readInt();

            return ar;
        }
    }
}


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

public class Main {

    public static void solve() {
        int n = IO.readInt();
        int k = IO.readInt();
        Map<Integer, Integer> s = new HashMap<Integer, Integer>();
        Map<Integer, Integer> p = new HashMap<Integer, Integer>();
        long result = 0;
        while (n-- > 0) {
            int a = IO.readInt();
            Integer sn;
            if (a % k == 0) {
                Integer pn = p.get(a / k);
                if (pn != null) {
                    result += pn;
                }

                sn = s.get(a / k);
                if (sn != null) {
                    pn = p.get(a);
                    if (pn == null) {
                        pn = 0;
                    }
                    p.put(a, pn + sn);
                }
            }
            sn = s.get(a);
            if (sn == null) {
                sn = 0;
            }
            s.put(a, sn + 1);
        }

        IO.println(result);
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            } catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            } else if (cmp == 0) {
                return mid;
            } else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static final boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a,int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math {

        static long c(int n, int k) {
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


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

public class Main {

    public static void solve() {
        int n = IO.readInt();
        int k = IO.readInt();
        Map<Integer, Integer> s = new HashMap<Integer, Integer>();
        Map<Integer, Integer> p = new HashMap<Integer, Integer>();
        int result = 0;
        while (n-- > 0) {
            int a = IO.readInt();
            Integer sn;
            if (a % k == 0) {
                Integer pn = p.get(a / k);
                if (pn != null) {
                    result += pn;
                }

                sn = s.get(a / k);
                if (sn != null) {
                    pn = p.get(a);
                    if (pn == null) {
                        pn = 0;
                    }
                    p.put(a, pn + sn);
                }
            }
            sn = s.get(a);
            if (sn == null) {
                sn = 0;
            }
            s.put(a, sn + 1);
        }

        IO.println(result);
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            } catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            } else if (cmp == 0) {
                return mid;
            } else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static final boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a,int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math {

        static long c(int n, int k) {
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


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

public class Main {

    public static void solve() {
        int n = IO.readInt();
        int k = IO.readInt();
        Map<Integer, Long> s = new HashMap<Integer, Long>();
        Map<Integer, Long> p = new HashMap<Integer, Long>();
        long result = 0;
        while (n-- > 0) {
            int a = IO.readInt();
            Long sn;
            if (a % k == 0) {
                Long pn = p.get(a / k);
                if (pn != null) {
                    result += pn;
                }

                sn = s.get(a / k);
                if (sn != null) {
                    pn = p.get(a);
                    if (pn == null) {
                        pn = 0l;
                    }
                    p.put(a, pn + sn);
                }
            }
            sn = s.get(a);
            if (sn == null) {
                sn = 0l;
            }
            s.put(a, sn + 1);
        }

        IO.println(result);
    }

    // Input/Output ================================
    public static class IO {

        private static Scanner scanner;
        private static PrintWriter writer;

        public static void setUp(InputStream in, OutputStream out) {
            scanner = new Scanner(new java.io.BufferedInputStream(in));
            writer = new PrintWriter(out);
        }

        public static boolean isEmpty() {
            return !scanner.hasNext();
        }

        public static boolean hasNextLine() {
            return scanner.hasNextLine();
        }

        public static String readLine() {
            String line;
            try {
                line = scanner.nextLine();
            } catch (Exception e) {
                line = null;
            }
            return line;
        }

        public static String readString() {
            return scanner.next();
        }

        public static int readInt() {
            return scanner.nextInt();
        }

        public static double readDouble() {
            return scanner.nextDouble();
        }

        public static float readFloat() {
            return scanner.nextFloat();
        }

        public static long readLong() {
            return scanner.nextLong();
        }

        public static char readChar() {
            return scanner.findInLine("[^\\s]").charAt(0);
        }

        public static void print(Object o) {
            writer.print(o);
            writer.flush();
        }

        public static void println(Object o) {
            writer.println(o);
            writer.flush();
        }
    }

    // Algorithms ================================

    private static class Algo {

        private static int binSearch(int[] array, int n, int lo, int hi) {
            if (lo > hi) {
                return lo;
            }

            int mid = lo + (hi - lo) / 2;
            int cmp = (int) java.lang.Math.signum(n - array[mid]);
            if (cmp < 0) {
                return binSearch(array, n, lo, mid - 1);
            } else if (cmp == 0) {
                return mid;
            } else {
                return binSearch(array, n, mid + 1, hi);
            }
        }

        private static void permutations(int n) {
            int[] p = new int[n];
            for (int index = 0; index < n; ++index) {
                p[index] = index + 1;
            }

            while (true) {
                IO.println(Arrays.toString(p));

                int k = n - 1;
                while (k > 0) {
                    if (p[k] < p[k - 1]) {
                        k--;
                    }
                    else {
                        break;
                    }
                }
                if (k == 0) {
                    break;
                }
                int j = n - 1;
                while (p[j] < p[k - 1]) {
                    j--;
                }

                int t = p[j];
                p[j] = p[k - 1];
                p[k - 1] = t;

                int i = 0;
                while (k + i < n - 1 - i) {
                    t = p[k + i];
                    p[k + i] = p[n - i - 1];
                    p[n - i - 1] = t;
                    i++;
                }
            }
        }

        private static final boolean isPrime(int number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            int i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        private static boolean isPalindrome(int number) {
            int n = number;
            int reverse = 0;
            while (n > 0) {
                reverse *= 10;
                reverse += (n % 10);
                n /= 10;
            }
            return reverse == number;
        }

        public static int gcd(int a,int b) {
            while (b != 0) {
                int tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }
    }

    private static class Math {

        static long c(int n, int k) {
            int d = 1000;
            int l = 1000000007;
            long[][] c = new long[d + 1][d + 1];
            for (int i = 1; i <= d; ++i) {
                for (int j = 0; j <= i; ++j) {
                    if (i == j || j == 0) {
                        c[i][j] = 1;
                    }
                    else {
                        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % l;
                    }
                }
            }
            return c[n][k];
        }
    }

    public static void main(String[] args) {
        IO.setUp(System.in, System.out);
        /*
        try {
            IO.setUp(new FileInputStream("encode.in"), new FileOutputStream("encode.out"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        */
        solve();
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        int n, k;
        long ans = 0;
        Map <Long, Long> l = new HashMap<Long, Long> ();
        Map <Long, Long> r = new HashMap<Long, Long> ();
        long [] arr = new long[200005];
        Scanner sc = new Scanner (System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            if (l.containsKey(arr[i])) {
                long x = l.get(arr[i]);
                x++;
                l.put(arr[i], x);
            }
            else {
                l.put(arr[i], 1L);
            }
        }

        for (int i = 0; i < n; i++) {
            long a = 0, b = 0, j = 0;
            if (arr[i]%k == 0) {
                if (r.containsKey(arr[i]/k)) {
                    a = r.get(arr[i]/k);
                }
                if (r.containsKey(arr[i])) {
                    r.put(arr[i], r.get(arr[i])+1);
                } else {
                    r.put(arr[i], 1L);
                }

                l.put(arr[i], l.get(arr[i])-1);
                if (l.containsKey(arr[i]*k)) {
                    b = l.get(arr[i]*k);
                }

                ans += a*b;
            } else {
                if (r.containsKey(arr[i])) {
                    r.put(arr[i], r.get(arr[i])+1);
                } else {
                    r.put(arr[i], 1L);
                }
                if(l.containsKey(arr[i])) {
                    l.put(arr[i], l.get(arr[i])-1);
                }
            }
        }
        System.out.println(ans);
    }
}