#include <bits/stdc++.h>
using namespace std;
long long s[200111], c[200111], b[200111], ada[200111];
set<pair<int, int> > ind;
int main() {
  memset(b, -1, sizeof(b));
  long long n, m;
  long long ac = 0, au = 0;
  scanf("%lld%lld", &n, &m);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", c + i);
    ind.insert({c[i], i});
  }
  for (long long i = 0; i < m; i++) scanf("%lld", s + i);
  for (long long k = 0; k <= 30; k++) {
    for (long long i = 0; i < m; i++) {
      if (s[i] == 0) continue;
      if (k != 0) s[i] = (s[i] + 1) / 2;
      auto it = ind.lower_bound({s[i], -1});
      if (it != ind.end() && it->first == s[i]) {
        b[it->second] = i;
        ada[i] = k;
        ac++;
        au += k;
        ind.erase(it);
        s[i] = 0;
      }
    }
  }
  printf("%lld %lld\n", ac, au);
  for (long long i = 0; i < m; i++) printf("%lld ", ada[i]);
  printf("\n");
  for (long long i = 0; i < n; i++) printf("%lld ", b[i] + 1);
  printf("\n");
  return 0;
}
