import java.util.*;
import java.util.stream.Collectors;

public class C {

    private static final long MAX = 1000000000;

    private static class Point implements Comparable<Point> {
        private final int x;
        private final long value;

        public Point(int x, long value) {
            this.x = x;
            this.value = value;
        }

        public int getX() {
            return x;
        }

        public long getValue() {
            return value;
        }

        @Override
        public int compareTo(Point o) {
            return x - o.x;
        }
    }

    private static class Solver {

        private final int k;
        private final long zeroCount;
        private final List<Integer> seq;

        private Solver(int k, List<Integer> seq) {
            this.k = k;
            this.zeroCount = seq.stream().filter(x -> x == 0).count();
            this.seq = seq.stream().filter(x -> x == 0).collect(Collectors.toList());
        }

        public long getCombinationsCount() {
            if (seq.size() < 3) {
                return 0;
            }
            Map<Integer, List<Integer>> itemPositions = seqToItemPositions();
            List<Integer> starters = getBaseCandidates(itemPositions.keySet());
            long result = zeroCount * (zeroCount - 1) * (zeroCount - 2) / 6;
            for (Integer starter : starters) {
                result += getCombinationsCountForStarter(starter, itemPositions);
            }
            return result;
        }

        private long getCombinationsCountForStarter(Integer starter, Map<Integer, List<Integer>> itemPositions) {
            if (k == 1) {
                long n = itemPositions.get(starter).size();
                if (n < 3) {
                    return 0;
                }
                return n * (n - 1) * (n - 2) / 6;
            }
            List<Point> secondPoints = new ArrayList<>();
            long secondCounter = 0;
            List<Integer> secondPositions = itemPositions.get(starter * k * k);
            for (int i = secondPositions.size() - 1; i >= 0; i--) {
                secondPoints.add(new Point(secondPositions.get(i), ++secondCounter));
            }
            Collections.reverse(secondPoints);

            List<Point> firstPoints = new ArrayList<>();
            long firstCounter = 0;
            List<Integer> firstPositions = itemPositions.get(starter * k);
            for (int i = firstPositions.size() - 1; i >= 0; i--) {
                int nextSecondIndex = firstIndexGreater(secondPoints, firstPositions.get(i));
                if (nextSecondIndex < secondPoints.size()) {
                    firstCounter += secondPoints.get(nextSecondIndex).getValue();
                }
                firstPoints.add(new Point(firstPositions.get(i), firstCounter));
            }
            Collections.reverse(firstPoints);

            List<Point> zeroPoints = new ArrayList<>();
            long zeroCounter = 0;
            List<Integer> zeroPositions = itemPositions.get(starter);
            for (int i = zeroPositions.size() - 1; i >= 0; i--) {
                int nextFirstIndex = firstIndexGreater(firstPoints, zeroPositions.get(i));
                if (nextFirstIndex < firstPoints.size()) {
                    zeroCounter += firstPoints.get(nextFirstIndex).getValue();
                }
                zeroPoints.add(new Point(zeroPositions.get(i), zeroCounter));
            }
            Collections.reverse(zeroPoints);
            return zeroPoints.get(0).getValue();
        }

        int firstIndexGreater(List<Point> list, int value) {
            int searchResult = Collections.binarySearch(list, new Point(value, 0));
            return -(searchResult + 1);
        }

        private Map<Integer, List<Integer>> seqToItemPositions() {
            Map<Integer, List<Integer>> result = new HashMap<>();
            for (int i = 0; i < seq.size(); i++) {
                int val = seq.get(i);
                if (!result.containsKey(val)) {
                    result.put(val, new ArrayList<>());
                }
                result.get(val).add(i);
            }
            result.values().forEach(Collections::sort);
            return result;
        }

        private List<Integer> getBaseCandidates(Set<Integer> items) {
            List<Integer> result = new ArrayList<>();
            for (Integer candidate : items) {
                long first = ((long) candidate) * k;
                long second = first * k;
                if (first > MAX || second > MAX) {
                    continue;
                }
                if (!items.contains(candidate * k) || !items.contains(candidate * k * k)) {
                    continue;
                }
                result.add(candidate);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        List<Integer> seq = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            seq.add(s.nextInt());
        }
        System.out.println(new Solver(k, seq).getCombinationsCount());
    }
}


import java.util.*;

public class C {

    private static final long MAX = 200000;

    private static class Solver {

        private final int k;
        private final List<Integer> seq;

        private Solver(int k, List<Integer> seq) {
            this.k = k;
            this.seq = seq;
        }

        public int getCombinationsCount() {
            Map<Integer, List<Integer>> itemPositions = seqToItemPositions();
            List<Integer> starters = getBaseCandidates(itemPositions);
            int result = 0;
            for (Integer starter : starters) {
                result += getCombinationsCountForStarter(starter, itemPositions);
            }
            return result;
        }

        private int getCombinationsCountForStarter(Integer starter, Map<Integer, List<Integer>> itemPositions) {
            List<Integer> zeroPositions = itemPositions.get(starter);
            List<Integer> firstPositions = itemPositions.get(starter * k);
            List<Integer> secondPositions = itemPositions.get(starter * k * k);
            int result = 0;
            for (int zeroIndex = 0; zeroIndex < zeroPositions.size(); zeroIndex++) {
                int zeroPosition = zeroPositions.get(zeroIndex);
                int firstStart = k != 1 ? firstIndexGreater(firstPositions, zeroPosition) : zeroIndex + 1;
                for (int firstIndex = firstStart; firstIndex < firstPositions.size(); firstIndex++) {
                    int firstPosition = firstPositions.get(firstIndex);
                    int secondStart = k != 1 ? firstIndexGreater(secondPositions, firstPosition) : firstIndex + 1;
                    int secondCounts = secondPositions.size() - secondStart;
                    if (secondCounts > 0) {
                        result += secondCounts;
                    }
                }
            }
            return result;
        }

        int firstIndexGreater(List<Integer> list, int value) {
            int searchResult = Collections.binarySearch(list, value);
            return searchResult >= 0 ? searchResult +1 : -(searchResult + 1);
        }

        private Map<Integer, List<Integer>> seqToItemPositions() {
            Map<Integer, List<Integer>> result = new HashMap<>();
            for (int i = 0; i < seq.size(); i++) {
                int val = seq.get(i);
                if (!result.containsKey(val)) {
                    result.put(val, new ArrayList<>());
                }
                result.get(val).add(i);
            }
            result.values().forEach(Collections::sort);
            return result;
        }

        private List<Integer> getBaseCandidates(Map<Integer, List<Integer>> itemPositions) {
            List<Integer> result = new ArrayList<>();
            for (Integer candidate : itemPositions.keySet()) {
                long first = ((long) candidate) * k;
                long second = first * k;
                if (first > MAX || second > MAX) {
                    continue;
                }
                if (!itemPositions.containsKey(candidate * k) || !itemPositions.containsKey(candidate * k * k)) {
                    continue;
                }
                result.add(candidate);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        List<Integer> seq = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            seq.add(s.nextInt());
        }
        System.out.println(new Solver(k, seq).getCombinationsCount());
    }
}


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

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> r = new HashMap<>();
		HashMap<Integer, Integer> l = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			Integer tmp = r.get(a[i]);
			if (tmp == null)
				tmp = 0;
			r.put(a[i], tmp + 1);
		}
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			Integer tmp = r.get(a[i]);
			if (tmp > 1)
				r.put(a[i], tmp - 1);
			else
				r.remove(a[i]);
			if (a[i] % k == 0)
			{
				tmp = r.get(a[i] * k);
				Integer tmp2 = l.get(a[i] / k);
				if (tmp == null)
					tmp = 0;
				if (tmp2 == null)
					tmp2 = 0;
				ans += tmp * tmp2;
			}
			tmp = l.get(a[i]);
			if (tmp == null)
				tmp = 0;
			l.put(a[i], tmp + 1);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


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

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> r = new HashMap<>();
		HashMap<Integer, Integer> l = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			Integer tmp = r.get(a[i]);
			if (tmp == null)
				tmp = 0;
			r.put(a[i], tmp + 1);
		}
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			Integer tmp = r.get(a[i]);
			if (tmp > 1)
				r.put(a[i], tmp - 1);
			else
				r.remove(a[i]);
			if (a[i] % k == 0) {
				tmp = r.get(a[i] * k);
				Integer tmp2 = l.get(a[i] / k);
				if (tmp == null)
					tmp = 0;
				if (tmp2 == null)
					tmp2 = 0;
				ans += 1l * tmp * tmp2;
			}
			tmp = l.get(a[i]);
			if (tmp == null)
				tmp = 0;
			l.put(a[i], tmp + 1);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


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

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> r = new HashMap<>();
		HashMap<Integer, Integer> l = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			Integer tmp = r.get(a[i]);
			if (tmp == null)
				tmp = 0;
			r.put(a[i], tmp + 1);
		}
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			Integer tmp = r.get(a[i]);
			if (tmp > 1)
				r.put(a[i], tmp - 1);
			else
				r.remove(a[i]);
			if (a[i] % k == 0 && 1l*a[i]*k >= -1e9 && 1l*a[i]*k <= 1e9) {
				tmp = r.get(a[i] * k);
				Integer tmp2 = l.get(a[i] / k);
				if (tmp == null)
					tmp = 0;
				if (tmp2 == null)
					tmp2 = 0;
				ans += 1l * tmp * tmp2;
			}
			tmp = l.get(a[i]);
			if (tmp == null)
				tmp = 0;
			l.put(a[i], tmp + 1);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


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

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> r = new HashMap<>();
		HashMap<Integer, Integer> l = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			Integer tmp = r.get(a[i]);
			if (tmp == null)
				tmp = 0;
			r.put(a[i], tmp + 1);
		}
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			Integer tmp = r.get(a[i]);
			if (tmp > 1)
				r.put(a[i], tmp - 1);
			else
				r.remove(a[i]);
			if (a[i] % k == 0) {
				tmp = r.get(1l* a[i] * k);
				Integer tmp2 = l.get(a[i] / k);
				if (tmp == null)
					tmp = 0;
				if (tmp2 == null)
					tmp2 = 0;
				ans += 1l * tmp * tmp2;
			}
			tmp = l.get(a[i]);
			if (tmp == null)
				tmp = 0;
			l.put(a[i], tmp + 1);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


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

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> r = new HashMap<>();
		HashMap<Integer, Integer> l = new HashMap<>();
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			Integer tmp = r.get(a[i]);
			if (tmp == null)
				tmp = 0;
			r.put(a[i], tmp + 1);
		}
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			Integer tmp = r.get(a[i]);
			if (tmp > 1)
				r.put(a[i], tmp - 1);
			else
				r.remove(a[i]);
			if (a[i] % k == 0 && 1l*a[i]*k <= 1e9) {
				tmp = r.get(a[i] * k);
				Integer tmp2 = l.get(a[i] / k);
				if (tmp == null)
					tmp = 0;
				if (tmp2 == null)
					tmp2 = 0;
				ans += 1l * tmp * tmp2;
			}
			tmp = l.get(a[i]);
			if (tmp == null)
				tmp = 0;
			l.put(a[i], tmp + 1);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),k = parseInt(tk.nextToken());
        Map<Long,Long> f1 = new HashMap<>();
        Map<Long,Long> f2 = new HashMap<>();

        int [] a = new int[n];
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++) {
            a[i] = parseInt(tk.nextToken());
            if(!f2.containsKey(a[i]))
                f2.put((long)a[i], 0l);
            f2.put((long)a[i], f2.get(a[i])+1);
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                f2.put((long)a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(f1.containsKey(a[i]/k) && f2.containsKey(a[i]*k))
                    ans += (long)f1.get(a[i]/k)*(long)f2.get(a[i]*k);

                if(!f1.containsKey(a[i])) f1.put((long)a[i], 1l);
                else f1.put((long)a[i], f1.get(a[i])+1);
            } else {
                f2.put((long)a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(!f1.containsKey(a[i])) f1.put((long)a[i], 1l);
                else f1.put((long)a[i], f1.get(a[i])+1);
            }
        }

        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),k = parseInt(tk.nextToken());
        Map<Long,Long> f1 = new HashMap<>();
        Map<Long,Long> f2 = new HashMap<>();

        long [] a = new long[n];
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++) {
            a[i] = parseInt(tk.nextToken());
            if(!f2.containsKey(a[i]))
                f2.put((long)a[i], 0l);
            f2.put((long)a[i], f2.get(a[i])+1);
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                f2.put((long)a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(f1.containsKey(a[i]/k) && f2.containsKey(a[i]*k))
                    ans += (long)f1.get(a[i]/k)*(long)f2.get(a[i]*k);

                if(!f1.containsKey(a[i])) f1.put((long)a[i], 1l);
                else f1.put((long)a[i], f1.get(a[i])+1);
            } else {
                f2.put((long)a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(!f1.containsKey(a[i])) f1.put((long)a[i], 1l);
                else f1.put((long)a[i], f1.get(a[i])+1);
            }
        }

        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),k = parseInt(tk.nextToken());
        Map<Integer,Long> f1 = new HashMap<>();
        Map<Integer,Long> f2 = new HashMap<>();

        int [] a = new int[n];
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++) {
            a[i] = parseInt(tk.nextToken());
            if(!f2.containsKey(a[i]))
                f2.put(a[i], 0l);
            f2.put(a[i], f2.get(a[i])+1);
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(f1.containsKey(a[i]/k) && f2.containsKey(a[i]*k))
                    ans += (long)f1.get(a[i]/k)*(long)f2.get(a[i]*k);

                if(!f1.containsKey(a[i])) f1.put(a[i], 1l);
                else f1.put(a[i], f1.get(a[i])+1);
            } else {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(!f1.containsKey(a[i])) f1.put(a[i], 1l);
                else f1.put(a[i], f1.get(a[i])+1);
            }
        }

        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),k = parseInt(tk.nextToken());
        Map<Integer,Integer> f1 = new HashMap<>();
        Map<Integer,Integer> f2 = new HashMap<>();

        int [] a = new int[n];
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++) {
            a[i] = parseInt(tk.nextToken());
            if(!f2.containsKey(a[i]))
                f2.put(a[i], 0);
            f2.put(a[i], f2.get(a[i])+1);
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(f1.containsKey(a[i]/k) && f2.containsKey(a[i]*k))
                    ans += (long)f1.get(a[i]/k)*(long)f2.get(a[i]*k);

                if(!f1.containsKey(a[i])) f1.put(a[i], 1);
                else f1.put(a[i], f1.get(a[i])+1);
            } else {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

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

        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),k = parseInt(tk.nextToken());
        Map<Integer,Integer> f1 = new HashMap<>();
        Map<Integer,Integer> f2 = new HashMap<>();

        int [] a = new int[n];
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++) {
            a[i] = parseInt(tk.nextToken());
            if(!f2.containsKey(a[i]))
                f2.put(a[i], 0);
            f2.put(a[i], f2.get(a[i])+1);
        }

        long ans = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

                if(f1.containsKey(a[i]/k) && f2.containsKey(a[i]*k))
                    ans += f1.get(a[i]/k)*f2.get(a[i]*k);

                if(!f1.containsKey(a[i])) f1.put(a[i], 1);
                else f1.put(a[i], f1.get(a[i])+1);
            } else {
                f2.put(a[i], f2.get(a[i])-1);
                if(f2.get(a[i])==0) f2.remove(a[i]);

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

        System.out.println(ans);
    }
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		String s;
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n + 10];
			long[][] dp = new long[n + 10][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			for(int i = 0 ; i < n ; i ++)
				if((lim == 0) || (b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		return -1;
	}
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n + 10];
			long[][] dp = new long[n + 10][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			lim = 1;
			for(int i = 1 ; i < n ; i ++)
				if((b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		return n;
	}
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		String s;
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n + 10];
			long[][] dp = new long[n + 10][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			for(int i = 0 ; i < n ; i ++)
				if((lim == 0) || (b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		while(true){
			int m = 0;
		}
//		return -1;
	}
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n + 10];
			long[][] dp = new long[n + 10][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			lim = 1;
			for(int i = 1 ; i < n ; i ++)
				if((b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		return 0;
	}
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		String s;
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n];
			long[][] dp = new long[n + 1][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			for(int i = 0 ; i < n ; i ++)
				if((lim == 0) || (b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		return -1;
	}
}


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

public class Main {

	public static void main(String[] args) {
		int n,k;
		Scanner cin = new Scanner(System.in);
		String s;
		while(cin.hasNext()){
			n = cin.nextInt();
			k = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] last = new int[n];
			int[][] dp = new int[n + 1][4];
			for(int i = 0 ; i < n ; i ++)
				b[i] = a[i] = cin.nextInt();
			int lim = 0;
			Arrays.sort(b);
			for(int i = 0 ; i < n ; i ++)
				if((lim == 0) || (b[i] != b[lim - 1])) b[lim ++] = b[i];
			int l,l2;
			dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
			for(int i = 0  ; i < n ; i ++){
				l = find(a[i],lim,b);
				dp[i + 1][1] = dp[ last[l] ][1] + 1;
				dp[i + 1][2] = dp[ last[l] ][2];
				dp[i + 1][3] = dp[ last[l] ][3];
				if(a[i] % k == 0){
					l2 = find(a[i] / k,lim,b);
					dp[i + 1][2] += dp[ last[l2] ][1];
					dp[i + 1][3] += dp[ last[l2] ][2];
				}
				last[l] = i + 1;
			}
			long res = 0;
			for(int i = 0 ; i < lim ; i ++)
				res += dp[ last[i] ][3];
			System.out.println(res);
		}
		cin.close();
	}
	static int find(int x,int n,int[] b){
		int l = 0,r = n - 1;
		while(l <= r){
			int mid = (r + l) >> 1;
			if(b[mid] < x) l = mid + 1;
			else if(b[mid] > x) r = mid - 1;
			else return mid;
		}
		return -1;
	}
}


import java.util.*;
import java.io.*;
public class Solution{

	public static void main(String args[]){

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

		int n=in.nextInt(),
			k=in.nextInt();

		long a[]=new long[n];
		for(int i=0; i<n; i++)
			a[i]=in.nextLong();

		HashMap<Long,Long[]> map=new HashMap<>();

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

			long item=a[i];

			if(!map.containsKey(item))
				map.put(item,new Long[]{0L,0L,0L,0L});
			map.get(item)[1]+=1;

			if(k!=1 && item!=0 && item%k==0){
				long prev=item/k;

				if(map.containsKey(prev)){
					map.get(item)[2]+=map.get(prev)[1];
					map.get(item)[3]+=map.get(prev)[2];
				}
			}
		}

		long count=0;
		for(Map.Entry<Long,Long[]> pair:map.entrySet()){
			if(k==1){
				long value1=pair.getValue()[1];
				count+=(value1*(value1-1)*(value1-2))/(1*2*3);
			}
			else{
				//System.out.println(pair.getKey()+" "+pair.getValue()[3]);
				count+=pair.getValue()[3];
			}
		}
		if(map.containsKey(0L)){
			long value1=map.get(0L)[1];
			count+=(value1*(value1-1)*(value1-2))/(1*2*3);
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;
public class Solution{

	public static void main(String args[]){

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

		int n=in.nextInt(),
			k=in.nextInt();

		long a[]=new long[n];
		for(int i=0; i<n; i++)
			a[i]=in.nextLong();

		HashMap<Long,Long[]> map=new HashMap<>();

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

			long item=a[i];

			if(!map.containsKey(item))
				map.put(item,new Long[]{0L,0L,0L,0L});
			map.get(item)[1]+=1;

			if(k!=1 && item!=0 && item%k==0){
				long prev=item/k;

				if(map.containsKey(prev)){
					map.get(item)[2]+=map.get(prev)[1];
					map.get(item)[3]+=map.get(prev)[2];
				}
			}
		}

		long count=0;
		for(Map.Entry<Long,Long[]> pair:map.entrySet()){
			if(k==1 && pair.getKey()!=0){
				long value1=pair.getValue()[1];
				count+=(value1*(value1-1)*(value1-2))/(1*2*3);
			}
			else{
				//System.out.println(pair.getKey()+" "+pair.getValue()[3]);
				count+=pair.getValue()[3];
			}
		}
		if(map.containsKey(0L)){
			long value1=map.get(0L)[1];
			count+=(value1*(value1-1)*(value1-2))/(1*2*3);
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;
public class Solution{

	public static void main(String args[]){

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

		int n=in.nextInt(),
			k=in.nextInt();

		int a[]=new int[n];
		for(int i=0; i<n; i++)
			a[i]=in.nextInt();

		HashMap<Integer,Integer[]> map=new HashMap<>();

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

			int item=a[i];

			if(!map.containsKey(item))
				map.put(item,new Integer[]{0,0,0,0});
			map.get(item)[1]+=1;

			if(k!=1 && a[i]%k==0){
				int prev=a[i]/k;

				if(map.containsKey(prev)){
					map.get(item)[2]+=map.get(prev)[1];
					map.get(item)[3]+=map.get(prev)[2];
				}
			}
		}

		long count=0;
		for(Map.Entry<Integer,Integer[]> pair:map.entrySet()){
			if(k==1){
				long value1=pair.getValue()[1];
				count+=(value1*(value1-1)*(value1-2))/(1*2*3);
			}
			else
				count+=pair.getValue()[3];
		}

		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;
public class Solution{

	public static void main(String args[]){

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

		int n=in.nextInt(),
			k=in.nextInt();

		long a[]=new long[n];
		for(int i=0; i<n; i++)
			a[i]=in.nextLong();

		HashMap<Long,Long[]> map=new HashMap<>();

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

			long item=a[i];

			if(!map.containsKey(item))
				map.put(item,new Long[]{0L,0L,0L,0L});
			map.get(item)[1]+=1;

			if(k!=1 && item%k==0){
				long prev=item/k;

				if(map.containsKey(prev)){
					map.get(item)[2]+=map.get(prev)[1];
					map.get(item)[3]+=map.get(prev)[2];
				}
			}
		}

		long count=0;
		for(Map.Entry<Long,Long[]> pair:map.entrySet()){
			if(k==1){
				long value1=pair.getValue()[1];
				count+=(value1*(value1-1)*(value1-2))/(1*2*3);
			}
			else{
				//System.out.println(pair.getKey()+" "+pair.getValue()[3]);
				count+=pair.getValue()[3];
			}
		}

		System.out.println(count);
	}
}


import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        long k = in.nextInt();
        long k2 = k*k;
        long[] a = new long[n];
        HashMap<Long, Long> r = new HashMap<>();
        HashMap<Long, Long> l = new HashMap<>();
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            if(r.containsKey(a[i])) {
                r.put(a[i], r.get(a[i])+1);
            } else {r.put(a[i], 1l);}
            l.put(a[i], 0l);
        }
        long rs = 0;
        for(int i=0; i<n; i++) {
            long lv = 0, rv = 0;
            if(a[i]%k==0 && l.containsKey(a[i]/k)) {
                lv = l.get(a[i]/k);
            }
            r.put(a[i], r.get(a[i])-1);
            if(r.containsKey(a[i]*k)) {
                rv = r.get(a[i]*k);
            }
            rs += lv * rv;
            l.put(a[i], l.get(a[i])+1);
        }
        out.println(rs);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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


import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        long k = in.nextInt();
        long k2 = k*k;
        long[] a = new long[n];
        HashMap<Long, Long> r = new HashMap<>();
        HashMap<Long, Long> l = new HashMap<>();
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            if(r.containsKey(a[i])) {
                r.put(a[i], r.get(a[i])+1);
            } else {r.put(a[i], 1l);}
            l.put(a[i], 0l);
        }
        long rs = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                if(l.containsKey(a[i]/k) && r.containsKey(a[i]*k)) {
                    rs += l.get(a[i]/k) * (r.get(a[i]*k) - (a[i]==a[i]*k?1:0));
                }
            }
            l.put(a[i], l.get(a[i])+1);
            r.put(a[i], r.get(a[i])-1);
        }
        out.println(rs);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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


import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        long k = in.nextInt();
        long k2 = k*k;
        long[] a = new long[n];
        HashMap<Long, Long> r = new HashMap<>();
        HashMap<Long, Long> l = new HashMap<>();
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            if(r.containsKey(a[i])) {
                r.put(a[i], r.get(a[i])+1);
            } else {r.put(a[i], 1l);}
            l.put(a[i], 0l);
        }
        long rs = 0;
        for(int i=0; i<n; i++) {
            if(a[i]%k==0) {
                if(l.containsKey(a[i]/k) && r.containsKey(a[i]*k)) {
                    rs += l.get(a[i]/k) * (r.get(a[i]*k) - (k==1?1:0));
                }
            }
            l.put(a[i], l.get(a[i])+1);
            r.put(a[i], r.get(a[i])-1);
        }
        out.println(rs);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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


import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static final int INF = (int) 1e9;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        HashMap<Integer, Integer> all = new HashMap<>();
        for (int x : a)
            all.put(x, all.getOrDefault(x, 0) + 1);
        long ans = 0;
        HashMap<Integer, Integer> have = new HashMap<>();
        for (int two : a) {
            have.put(two, have.getOrDefault(two, 0) + 1);
            if (two % k != 0) continue;
            int one = two / k;
            if (1l * two * k > INF) continue;
            int three = two * k;
            int before = have.getOrDefault(one, 0) - (one == two ? 1 : 0);
            int after = all.getOrDefault(three, 0) - have.getOrDefault(three, 0);
            ans += 1l * before * after;

        }
        out.println(ans);
        out.close();
        out.flush();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

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

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

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}


import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static final int INF = (int) 1e9;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        HashMap<Integer, Integer> all = new HashMap<>();
        for (int x : a)
            all.put(x, all.getOrDefault(x, 0) + 1);
        long ans = 0;
        HashMap<Integer, Integer> have = new HashMap<>();
        for (int two : a) {
            have.put(two, have.getOrDefault(two, 0) + 1);
            if (Math.abs(two) % k != 0) continue;
            int one = two / k;
            if (Math.abs(1l * two * k) > INF) continue;
            int three = two * k;
            int before = have.getOrDefault(one, 0) - (one == two ? 1 : 0);
            int after = all.getOrDefault(three, 0) - have.getOrDefault(three, 0);
            ans += 1l * before * after;
        }
        out.println(ans);
        out.close();
        out.flush();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

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

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

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}


import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static final int INF = (int) 1e9;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        HashMap<Integer, Integer> all = new HashMap<>();
        for (int x : a)
            all.put(x, all.getOrDefault(x, 0) + 1);
        long ans = 0;
        HashMap<Integer, Integer> have = new HashMap<>();
        for (int two : a) {
            have.put(two, have.getOrDefault(two, 0) + 1);
            if (two % k != 0) continue;
            int one = two / k;
            if (Math.abs(1l * two * k) > INF) continue;
            int three = two * k;
            int before = have.getOrDefault(one, 0) - (one == two ? 1 : 0);
            int after = all.getOrDefault(three, 0) - have.getOrDefault(three, 0);
            ans += 1l * before * after;
        }
        out.println(ans);
        out.close();
        out.flush();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

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

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

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class ProblemC {
    BufferedReader rd;

    ProblemC() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        long k = longarr()[1];
        long[] a = longarr();
        int n = a.length;
        Map<Long, Set<Integer>> m = new HashMap<>();
        for(int i=0;i<n;i++) {
            Set<Integer> u = m.get(a[i]);
            if(u == null) {
                u = new HashSet<>();
                m.put(a[i], u);
            }
            u.add(i);
        }
        Set<Long> processed = new HashSet<>();
        long res = 0;
        long k2 = k*k;
        BigInteger k2b = BigInteger.valueOf(k2);
        for(long i: a) {
            if(processed.add(i)) {
                if(k == 1 || i == 0) {
                    int s = m.get(i).size();
                    if(s > 2) {
                        res += (s-2)*(s-1)*s / 6;
                    }
                } else {
                    long p2 = i*k;
                    long p3 = i*k2;
                    if(BigInteger.valueOf(i).multiply(k2b).equals(BigInteger.valueOf(p3))) {
                        res += count(m.get(i), m.get(p2), m.get(p3));
                    }
                }
            }
        }
        out(res);
    }

    private long count(Set<Integer> p1, Set<Integer> p2, Set<Integer> p3) {
        long res = 0;
        if(p1 != null && p2 != null && p3 != null) {
            Set<Integer> all = new TreeSet<>();
            all.addAll(p1);
            all.addAll(p2);
            all.addAll(p3);
            long r1 = 0;
            long r3 = p3.size();
            for(Integer x: all) {
                r1 += p1.contains(x)?1:0;
                r3 -= p3.contains(x)?1:0;
                if(p2.contains(x)) {
                    res += r1 * r3;
                }
            }
        }
        return res;
    }

    private long[] longarr() throws IOException {
        return longarr(rd.readLine());
    }

    private long[] longarr(String s) {
        String[] q = split(s);
        int n = q.length;
        long[] a = new long[n];
        for(int i=0;i<n;i++) {
            a[i] = Long.parseLong(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemC {
    BufferedReader rd;

    ProblemC() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        long k = longarr()[1];
        long[] a = longarr();
        int n = a.length;
        Map<Long, Set<Integer>> m = new HashMap<>();
        for(int i=0;i<n;i++) {
            Set<Integer> u = m.get(a[i]);
            if(u == null) {
                u = new HashSet<>();
                m.put(a[i], u);
            }
            u.add(i);
        }
        Set<Long> processed = new HashSet<>();
        long res = 0;
        for(long i: a) {
            if(processed.add(i)) {
                if(k == 1 || i == 0) {
                    int s = m.get(i).size();
                    if(s > 2) {
                        res += (s-2)*(s-1)*s / 6;
                    }
                } else {
                    long p2 = i*k;
                    long p3 = i*k*k;
                    res += count(m.get(i), m.get(p2), m.get(p3));
                }
            }
        }
        out(res);
    }

    private long count(Set<Integer> p1, Set<Integer> p2, Set<Integer> p3) {
        long res = 0;
        if(p1 != null && p2 != null && p3 != null) {
            Set<Integer> all = new TreeSet<>();
            all.addAll(p1);
            all.addAll(p2);
            all.addAll(p3);
            long[] r1 = new long[all.size()];
            long[] r3 = new long[all.size()];
            int i = 0;
            r3[0] = p3.size();
            for(Integer x: all) {
                long t1 = p1.contains(x)?1:0;
                r1[i] = i > 0?r1[i-1]+t1:t1;
                long t3 = p3.contains(x)?1:0;
                r3[i] = i>0?r3[i-1]-t3:r3[i]-t3;
                i++;
            }
            int j = 0;
            for(Integer x: all) {
                if(p2.contains(x)) {
                    res += r1[j] * r3[j];
                }
                j++;
            }
        }
        return res;
    }

    private long[] longarr() throws IOException {
        return longarr(rd.readLine());
    }

    private long[] longarr(String s) {
        String[] q = split(s);
        int n = q.length;
        long[] a = new long[n];
        for(int i=0;i<n;i++) {
            a[i] = Long.parseLong(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class ProblemC {
    BufferedReader rd;

    ProblemC() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        long k = longarr()[1];
        long[] a = longarr();
        int n = a.length;
        Map<Long, Set<Integer>> m = new HashMap<>();
        for(int i=0;i<n;i++) {
            Set<Integer> u = m.get(a[i]);
            if(u == null) {
                u = new HashSet<>();
                m.put(a[i], u);
            }
            u.add(i);
        }
        Set<Long> processed = new HashSet<>();
        long res = 0;
        long k2 = k*k;
        BigInteger k2b = BigInteger.valueOf(k2);
        for(long i: a) {
            if(processed.add(i)) {
                if(k == 1 || i == 0) {
                    long s = m.get(i).size();
                    if(s > 2) {
                        res += (s-2)*(s-1)*s / 6;
                    }
                } else {
                    long p2 = i*k;
                    long p3 = i*k2;
                    if(BigInteger.valueOf(i).multiply(k2b).equals(BigInteger.valueOf(p3))) {
                        res += count(m.get(i), m.get(p2), m.get(p3));
                    }
                }
            }
        }
        out(res);
    }

    private long count(Set<Integer> p1, Set<Integer> p2, Set<Integer> p3) {
        long res = 0;
        if(p1 != null && p2 != null && p3 != null) {
            Set<Integer> all = new TreeSet<>();
            all.addAll(p1);
            all.addAll(p2);
            all.addAll(p3);
            long r1 = 0;
            long r3 = p3.size();
            for(Integer x: all) {
                r1 += p1.contains(x)?1:0;
                r3 -= p3.contains(x)?1:0;
                if(p2.contains(x)) {
                    res += r1 * r3;
                }
            }
        }
        return res;
    }

    private long[] longarr() throws IOException {
        return longarr(rd.readLine());
    }

    private long[] longarr(String s) {
        String[] q = split(s);
        int n = q.length;
        long[] a = new long[n];
        for(int i=0;i<n;i++) {
            a[i] = Long.parseLong(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemC {
    BufferedReader rd;

    ProblemC() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        long k = longarr()[1];
        long[] a = longarr();
        int n = a.length;
        Map<Long, Set<Integer>> m = new HashMap<>();
        for(int i=0;i<n;i++) {
            Set<Integer> u = m.get(a[i]);
            if(u == null) {
                u = new HashSet<>();
                m.put(a[i], u);
            }
            u.add(i);
        }
        Set<Long> processed = new HashSet<>();
        long res = 0;
        for(long i: a) {
            if(processed.add(i)) {
                if(k == 1) {
                    int s = m.get(i).size();
                    if(s > 2) {
                        res += (s-2)*(s-1)*s / 6;
                    }
                } else {
                    long p2 = i*k;
                    long p3 = i*k*k;
                    res += count(m.get(i), m.get(p2), m.get(p3));
                }
            }
        }
        out(res);
    }

    private long count(Set<Integer> p1, Set<Integer> p2, Set<Integer> p3) {
        long res = 0;
        if(p1 != null && p2 != null && p3 != null) {
            Set<Integer> all = new TreeSet<>();
            all.addAll(p1);
            all.addAll(p2);
            all.addAll(p3);
            long[] r1 = new long[all.size()];
            long[] r3 = new long[all.size()];
            int i = 0;
            r3[0] = p3.size();
            for(Integer x: all) {
                long t1 = p1.contains(x)?1:0;
                r1[i] = i > 0?r1[i-1]+t1:t1;
                long t3 = p3.contains(x)?1:0;
                r3[i] = i>0?r3[i-1]-t3:r3[i]-t3;
                i++;
            }
            int j = 0;
            for(Integer x: all) {
                if(p2.contains(x)) {
                    res += r1[j] * r3[j];
                }
                j++;
            }
        }
        return res;
    }

    private long[] longarr() throws IOException {
        return longarr(rd.readLine());
    }

    private long[] longarr(String s) {
        String[] q = split(s);
        int n = q.length;
        long[] a = new long[n];
        for(int i=0;i<n;i++) {
            a[i] = Long.parseLong(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC();
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static long[] a;
    static long[] a2;
    static long[] a3;
    static boolean[][] isPr;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();

        a = new long[n + 1];
        a2 = new long[n + 1];
        a3 = new long[n + 1];

        isPr = new boolean[n + 1][n + 1];

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

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < i; ++j) {
                if (isPr[i][j] = (a[i] / a[j] == k && a[i] % a[j] == 0) )
                    a2[i]++;
            }

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < i; ++j)
                if (isPr[i][j])
                    a3[i]+= a2[j];

        int sum = 0;
        for (int i = 0; i < n ;++i)
                sum+= a3[i];

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static int[] a;
    static int[] a2;
    static int[] a3;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();

        a = new int[n + 1];
        a2 = new int[n + 1];
        a3 = new int[n + 1];

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

        for (int i = 0; i < n ;++i)
            for (int j = 0; j < i; ++j)
                if (a[i] / a[j] == k && a[i] % a[j] == 0)
                    a2[i]++;

        for (int i = 0; i < n ;++i)
            for (int j = 0; j < i; ++j)
                if (a[i] / a[j] == k && a[i] % a[j] == 0)
                    a3[i]+= a2[j];

        int sum = 0;
        for (int i = 0; i < n ;++i)
                sum+= a3[i];

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static long[] a;
    static HashMap<Long, Long> a1;
    static HashMap<Long, Long> a2;
    static HashMap<Long, Long> a3;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();
        int N = 200050;

        a = new long[n + 1];
        a1 = new HashMap<Long, Long>();
        a2 = new HashMap<Long, Long>();
        a3 = new HashMap<Long, Long>();

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

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

            if ( a[i] % k == 0 ) {

                if (a2.get(a[i]) == null)
                    a2.put(a[i], 0L);

                if (a3.get(a[i]) == null)
                    a3.put(a[i], 0L);

                if (a2.get(a[i] / k) == null)
                    a2.put(a[i] / k, 0L);

                if (a1.get(a[i] / k) == null)
                    a1.put(a[i] / k, 0L);

                a3.put(a[i], a3.get(a[i]) + a2.get(a[i] / k)); //a3[ (int) a[i] ] += a2[(int) (a[i] / k) ];
                a2.put(a[i], a2.get(a[i]) + a1.get(a[i] / k));//a2[ (int) a[i] ] += a1[(int) (a[i] / k) ];
            }
            if (a1.get(a[i]) == null)
                a1.put(a[i], 0L);
            a1.put(a[i], a1.get(a[i]) + 1);//a1[ (int) a[i]]++;
        }

        long sum = 0;
        for (Long i : a3.values())
                sum+= i;

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static long[] a;
    static long[] a1;
    static long[] a2;
    static long[] a3;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();
        int N = 200050;

        a = new long[n + 1];
        a1 = new long[N + 1];
        a2 = new long[N + 1];
        a3 = new long[N + 1];

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

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

            if ( a[i] % k == 0 ) {
                a3[(int) a[i]] += a2[(int) (a[i] / k) ];
                a2[(int) a[i]] += a1[(int) (a[i] / k) ];
            }
            a1[ (int) a[i]]++;
        }

        long sum = 0;
        for (int i = 0; i < N ;++i)
                sum+= a3[i];

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static long[] a;
    static long[] a2;
    static long[] a3;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();

        a = new long[n + 1];
        a2 = new long[n + 1];
        a3 = new long[n + 1];

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

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < i; ++j) {
                if (a[i] / a[j] == k && a[i] % a[j] == 0) {
                    a3[i] += a2[j];
                    a2[i]++;
                }
            }

        /*
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < i; ++j)
                if (a[i] / a[j] == k && a[i] % a[j] == 0)
                    a3[i]+= a2[j];
                    */

        int sum = 0;
        for (int i = 0; i < n ;++i)
                sum+= a3[i];

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

/**
 * Created by Пользователь on 09.08.2015.
 */
public class Codeforces567C {

    static long[] a;
    static long[] a1;
    static long[] a2;
    static long[] a3;

    public static void main(String[] args) throws IOException {
        InputReader ir = new InputReader(System.in);

        int n = ir.nextInt();
        int k = ir.nextInt();
        int N = 200050;

        a = new long[n + 1];
        a1 = new long[N + 1];
        a2 = new long[N + 1];
        a3 = new long[N + 1];

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

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

            if ( a[i] % k == 0 ) {
                a3[(int) a[i]] += a2[(int) (a[i] / k) ];
                a2[(int) a[i]] += a1[(int) (a[i] / k) ];
            }
            a1[ (int) a[i]]++;
        }

        int sum = 0;
        for (int i = 0; i < N ;++i)
                sum+= a3[i];

        System.out.println(sum);

    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


import java.util.*;
import java.io.*;

public class Main
{
    public static void main(String args[])
    {
        // String s=fs.next();
        //char c[]=s.toCharArray();
        //int len=s.length();
         InputStream in=System.in;
         FastScanner fs=new FastScanner(in);
         PrintWriter out=new PrintWriter(System.out);

         int n=fs.nextInt();
           int m=fs.nextInt();
         int arr[]=new int[n];
         for(int i=0;i<n;i++)
         {
         arr[i]=fs.nextInt();
         }

        // int n=fs.nextInt();
         int arr1[]=new int[m];
         for(int i=0;i<m;i++)
         {
         arr1[i]=fs.nextInt();
         }

         long tem[][]=new long[n][m];
         for(int i=0;i<n;i++)
          for(int j=0;j<m;j++)
            tem[i][j]=((long)arr[i])*((long)arr1[j]);
         long ans=tem[0][0];
         long ans1=tem[0][0];
         int i1=-1;
         int j1=-1;
         for(int i=0;i<n;i++)
           for(int j=0;j<m;j++)
           {  if(ans<=tem[i][j])
               { ans=tem[i][j];
                i1=i;
                j1=j;
               }

           }
           for(int i=0;i<n;i++)
           for(int j=0;j<m;j++)
           {  if(tem[i][j]<=ans&&ans1<tem[i][j])
           {
            if(i==i1&&j==j1)
              continue;
            ans1=tem[i][j];
          }
           }
           //out.println(ans);

          out.println(ans1);
        out.close();

    }
   static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            try {
                br = new BufferedReader(new InputStreamReader(f));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        char [] charArray()
          {
            return  next().toCharArray();
          }

    }

}


import java.util.*;
import java.io.*;

public class Main
{
    public static void main(String args[])
    {
        // String s=fs.next();
        //char c[]=s.toCharArray();
        //int len=s.length();
         InputStream in=System.in;
         FastScanner fs=new FastScanner(in);
         PrintWriter out=new PrintWriter(System.out);

         int n=fs.nextInt();
           int m=fs.nextInt();
         int arr[]=new int[n];
         for(int i=0;i<n;i++)
         {
         arr[i]=fs.nextInt();
         }

        // int n=fs.nextInt();
         int arr1[]=new int[m];
         for(int i=0;i<m;i++)
         {
         arr1[i]=fs.nextInt();
         }

         long tem[][]=new long[n][m];
         for(int i=0;i<n;i++)
          for(int j=0;j<m;j++)
            tem[i][j]=(((long)arr[i])*((long)arr1[j]));
         long ans=tem[0][0];
         long ans1=Long.MIN_VALUE;
         int i1=-1;
         int j1=-1;
         for(int i=0;i<n;i++)
           for(int j=0;j<m;j++)
           {  if(ans<=tem[i][j])
               { ans=tem[i][j];
                i1=i;
                j1=j;
               } }
           for(int i=0;i<n;i++)
           for(int j=0;j<m;j++)
           {if(ans1<=tem[i][j])
           {
            if(i==i1&&j==j1)
              continue;
            ans1=tem[i][j];
          }
           }
         //  out.println(ans);

          out.println(ans1);
        out.close();

    }
   static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            try {
                br = new BufferedReader(new InputStreamReader(f));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        char [] charArray()
          {
            return  next().toCharArray();
          }

    }

}