{$O-,Q+,R+}
uses SysUtils, Math;
var a, b, c, d, v, w, vr, wr:array [1..100000] of integer;
    f:array [1..100000] of boolean;


procedure qsort (l, r:integer);
var i, j, x, y:integer;
begin
  if l>=r then exit;
  i:=l; j:=r; x:=a[(l+r) shr 1];
  repeat
    while a[i]<x do inc (i);
    while x<a[j] do dec (j);
    if i<=j then begin
      y:=a[i]; a[i]:=a[j]; a[j]:=y;
      y:=v[i]; v[i]:=v[j]; v[j]:=y;
      inc (i); dec (j);
    end;
  until i>j;
  qsort (l, j);
  qsort (i, r);
end;


procedure qsort2 (l, r:integer);
var i, j, x, y:integer;
begin
  if l>=r then exit;
  i:=l; j:=r; x:=b[(l+r) shr 1];
  repeat
    while b[i]<x do inc (i);
    while x<b[j] do dec (j);
    if i<=j then begin
      y:=b[i]; b[i]:=b[j]; b[j]:=y;
      y:=w[i]; w[i]:=w[j]; w[j]:=y;
      inc (i); dec (j);
    end;
  until i>j;
  qsort2 (l, j);
  qsort2 (i, r);
end;

var i, j, l, cc, dc, m, n, p, k:integer;

begin
  reset (input, 'elves.in'); rewrite (output, 'elves.out');
  read (m, n);
  for i:=1 to m do read (a[i]);
  for i:=1 to m do v[i]:=i;
  for i:=1 to n do read (b[i]);
  for i:=1 to n do w[i]:=i;
  qsort (1, m);
  qsort2 (1, n);
  i:=1; j:=1;
  repeat
    if b[j]<a[i] then begin c[j]:=i; inc (j) end;
    inc (i);
  until (i>m) or (j>n);
  cc:=j-1;
  //1 some elves
  i:=m; j:=n;
  repeat
    if b[j]>a[i] then begin d[n+1-j]:=i; dec (j) end;
    dec (i);
  until (i<1) or (j<1);
  dc:=n-j;



  l:=min (cc, dc);
  if l>n shr 1 then l:=n shr 1;
  assert (l<=m);

  for i:=1 to m do vr[v[i]]:=i;
  for i:=1 to n do wr[w[i]]:=i;


  k:=l;

  for i:=1 to l do begin
    assert (b[i]<a[c[i]]);
    if (b[n-l+i]<=a[c[i]]) then begin
      f[n-l+i]:=true;
      dec (k);
    end;
  end;

  writeln (k);
  p:=n-l+1;
  for i:=1 to k do begin
    while f[p] do inc (p);
    writeln (v[c[i]], ' ', w[i], ' ', w[p]);
    inc (p);
  end;

  flush (output);

  p:=n-l+1;
  for i:=1 to k do begin
    while f[p] do inc (p);
    assert (b[i]<a[c[i]]);
    assert (b[p]>a[c[i]]);
    inc (p);
  end;


end.