#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  map<unsigned long long, vector<int>> pow;
  vector<int> a(m + 1), s(m + 1), u(m + 1), b(n + 1);
  for (int i = 1; i <= n; ++i) {
    unsigned long long p;
    scanf("%llu", &p);
    pow[p].push_back(i);
  }
  for (int i = 1; i <= m; ++i) scanf("%llu", &s[i]);
  int c = 0, us = 0;
  for (int i = 0; i < 32; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (!u[j] && pow.count(s[j]) && !pow[s[j]].empty()) {
        u[j] = 1;
        us += i;
        c++;
        int cp = pow[s[j]].back();
        pow[s[j]].pop_back();
        b[cp] = j;
        a[j] = i;
      } else
        s[j] = (s[j] + 1) / 2;
    }
  }
  printf("%d %d\n", c, us);
  for (int i = 1; i <= m; ++i) {
    printf("%d ", a[i]);
  }
  printf("\n");
  for (int i = 1; i <= n; ++i) {
    printf("%d ", b[i]);
  }
  printf("\n");
}
