#include <bits/stdc++.h>
using namespace std;
int ans[200011], ans1[200011], a[200011], b[200011], mark[200011];
int main() {
  int n, m, i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < m; i++) scanf("%d", &b[i]);
  set<pair<int, int> > second[2];
  int c = 0;
  set<pair<int, int> >::iterator it;
  for (i = 0; i < m; i++) second[0].insert(make_pair(b[i], i));
  int coun = 0, coun1 = 0;
  for (i = 0; i <= 32; i++) {
    if (second[c].size() == 0) break;
    for (j = 0; j < n; j++) {
      if (mark[j] == 1) continue;
      it = second[c].lower_bound(make_pair(a[j], -1));
      if (it != second[c].end() && it->first == a[j]) {
        ans[it->second] = i;
        mark[j] = 1;
        ans1[j] = it->second + 1;
        coun += i;
        coun1++;
        second[c].erase(it);
      }
    }
    second[!c].clear();
    for (it = second[c].begin(); it != second[c].end(); it++) {
      int k = it->first;
      k = k / 2 + k % 2;
      if (k > 0 && k != it->first) second[!c].insert(make_pair(k, it->second));
    }
    c = !c;
  }
  assert(coun1 <= n && coun1 >= 1);
  printf("%d %d\n", coun1, coun);
  int co = 0;
  for (i = 0; i < m; i++) printf("%d ", ans[i]), co += ans[i];
  printf("\n");
  for (i = 0; i < n; i++) printf("%d ", ans1[i]);
  printf("\n");
  assert(co == coun);
  return 0;
}
