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

public class elves_pm {

    private static StreamTokenizer t;

    private static int nextInt() throws IOException {
        t.nextToken();
        return (int) t.nval;
    }


    public static void main(String[] args) throws IOException {
        t = new StreamTokenizer(new BufferedReader(new FileReader("elves.in")));
        PrintWriter writer = new PrintWriter(new File("elves.out"));

        int n = nextInt();
        int m = nextInt();

        Pair[] a = new Pair[n];
        Pair[] b = new Pair[m];

        for (int i = 0; i < a.length; i++) {
            int v = nextInt();
            a[i] = new Pair(i + 1, v);
        }
        for (int i = 0; i < b.length; i++) {
            int v = nextInt();
            b[i] = new Pair(i + 1, v);
        }

        Arrays.sort(a);
        Arrays.sort(b);

        List<String> ans = new ArrayList<String>(n / 2);

        int i = 0;
        int j = (m / 2);
        int k = 0;
        while ((j < m) && (k < n)) {
            while (k < n && a[k].v <= b[i].v) k++;
            if (k == n) break;
            while (j < m && a[k].v >= b[j].v) j++;
            if (j == m) break;
            ans.add("" + a[k].i + " " + b[i].i + " " + b[j].i);
            i++;
            j++;
            k++;
        }
        writer.println(ans.size());
        for (String s : ans) {
            writer.println(s);
        }
        writer.close();
    }

    static class Pair implements Comparable<Pair> {
        int v;
        int i;

        public Pair(int i, int v) {
            this.v = v;
            this.i = i;
        }

        public int compareTo(Pair that) {
            return this.v - that.v;
        }
    }
}
