#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
map<int, int> cnt;
const int bot = 10000000;
std::vector<int> cntmal(bot, 0);
int getcnt(int i) {
  if (i < bot)
    return cntmal[i];
  else
    return cnt[i];
}
void modcnt(int i, int add) {
  if (i < bot)
    cntmal[i] += add;
  else
    cnt[i] += add;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  std::vector<int> p(n);
  std::vector<int> s(m);
  std::vector<std::pair<int, int> > comp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    modcnt(p[i], 1);
    comp.push_back(make_pair(p[i], i));
  }
  set<std::pair<int, int> > dec;
  std::vector<std::pair<int, int> > ans;
  int u = 0;
  std::vector<int> md(m, 0);
  for (int i = 0; i < m; i++) {
    scanf("%d", &s[i]);
    int d = 0;
    while (s[i] > 0 && getcnt(s[i]) == 0) {
      d++;
      if (s[i] == 1)
        s[i] = 0;
      else
        s[i] = (s[i] + 1) / 2;
    }
    if (s[i] > 0) dec.insert(make_pair(d, i));
  }
  while (!dec.empty()) {
    auto it = dec.begin();
    int i = it->second;
    int d = it->first;
    if (getcnt(s[i]) > 0) {
      modcnt(s[i], -1);
      md[i] = d;
      u += d;
      ans.push_back(make_pair(s[i], i));
      dec.erase(it);
    } else {
      d++;
      if (s[i] == 1)
        s[i] = 0;
      else
        s[i] = (s[i] + 1) / 2;
      while (s[i] > 0 && getcnt(s[i]) == 0) {
        d++;
        if (s[i] == 1)
          s[i] = 0;
        else
          s[i] = (s[i] + 1) / 2;
      }
      dec.erase(it);
      if (s[i] > 0) {
        dec.insert(make_pair(d, i));
      }
    }
  }
  std::vector<int> con(n, 0);
  sort((comp).begin(), (comp).end());
  sort((ans).begin(), (ans).end());
  int pa = 0;
  int pc = 0;
  while (pa < ans.size()) {
    if (comp[pc].first < ans[pa].first)
      pc++;
    else {
      con[comp[pc].second] = ans[pa].second + 1;
      pa++;
      pc++;
    }
  }
  printf("%d %d\n", ans.size(), u);
  for (int i = 0; i < m; i++) {
    printf("%d", md[i]);
    if (i < m - 1)
      printf(" ");
    else
      printf("\n");
  }
  for (int i = 0; i < n; i++) {
    printf("%d", con[i]);
    if (i < n - 1)
      printf(" ");
    else
      printf("\n");
  }
}
