#include <bits/stdc++.h>
#include "optimization.h"

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int maxN = 1e5;

int n, m, a[maxN], b[maxN], oa[maxN], ob[maxN];
int ra[maxN], rb1[maxN], rb2[maxN];

bool aless( int i, int j ) { return a[i] < a[j]; }
bool bless( int i, int j ) { return b[i] < b[j]; }

bool solve( int k ) {
  forn(i, k)
    rb1[i] = ob[i], rb2[i] = ob[n - k + i];
  
  int p = 0;
  forn(i, m) {
    ra[p] = oa[i];
    if (b[rb1[p]] < a[ra[p]] && a[ra[p]] < b[rb2[p]] && ++p == k)
      return 1;
  }
  return 0;
}

int main() {
  m = readInt();
  n = readInt();
  forn(i, m)
    a[i] = readInt(), oa[i] = i;
  forn(i, n)
    b[i] = readInt(), ob[i] = i;
  sort(oa, oa + m, aless);
  sort(ob, ob + n, bless);

  int l = 0, r = min(m, n / 2), x;
  while (l < r)
    if (!solve(x = (l + r + 1) / 2))
      r = x - 1;
    else
      l = x;
  
  solve(l);

  writeInt(l, '\n');
  forn(i, l) {
    writeInt(ra[i] + 1, ' ');
    writeInt(rb1[i] + 1, ' ');
    writeInt(rb2[i] + 1, ' ');
  }
}
