{$R+,Q+,O-}
program elves_and_deers;

uses
    sysutils;

const
	maxn = 100000;

type
	tarr = array [1..maxn] of longint;

var
	m, n: longint;
	a, b: tarr;
	ia, ib: tarr;
	i: longint;
	di, e1i, e2i: longint;
	ans: longint;
	d, e1, e2: array [1..maxn] of longint;

procedure sort(var a, ia: tarr; l, r: longint);
var
	i, j: longint;
	x, t: longint;
begin	
	i := l;
	j := r;
	x := a[i + random(j - i + 1)];
	while i <= j do begin
		while a[i] < x do inc(i);
		while a[j] > x do dec(j);
		if i <= j then begin
			t := a[i]; a[i] := a[j]; a[j] := t;
			t := ia[i]; ia[i] := ia[j]; ia[j] := t;
			inc(i);
			dec(j);
		end;
	end;
	if l < j then sort(a, ia, l, j);
	if i < r then sort(a, ia, i, r);
end;

begin
	reset(input, 'elves.in');
	rewrite(output, 'elves.out');

	readln(m, n);
	assert((1 <= m) and (m <= maxn));
	assert((1 <= n) and (n <= maxn));

	for i := 1 to m do begin
		read(a[i]);
		assert((0 <= a[i]) and (a[i] <= 1000000000));
		ia[i] := i;
	end;
	for i := 1 to n do begin
		read(b[i]);
		assert((0 <= b[i]) and (b[i] <= 1000000000));
		ib[i] := i;
	end;

	sort(a, ia, 1, m);
	sort(b, ib, 1, n);

	di := 1;
	e1i := 1;
	e2i := n div 2 + 1;

	ans := 0;
	while (e1i <= n div 2) and (di <= m) and (e2i <= n) do begin
		while (di <= m) and (a[di] <= b[e1i]) do 
			inc(di);
		if (di > m) then 
			break;
		while (e2i <= n) and (b[e2i] <= a[di]) do 
			inc(e2i);
		if e2i > n then
			break;
		inc(ans);
		d[ans] := ia[di];
		e1[ans] := ib[e1i];
		e2[ans] := ib[e2i];
		inc(e1i);
		inc(di);
		inc(e2i);
	end;

	writeln(ans);
	for i := 1 to ans do begin
		writeln(d[i], ' ', e1[i], ' ', e2[i]);
	end;

	close(input);
	close(output);
end.