#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> c, s;
bool fg[200009];
int adp, ad[200009], so[200009], cp, co[200009];
int main() {
  int n, m, i, j, x, y, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    c.push_back(make_pair(x, i));
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &x);
    s.push_back(make_pair(x, i));
  }
  sort(c.begin(), c.end());
  sort(s.begin(), s.end());
  k = 0;
  while (k < 32) {
    i = 0;
    j = 0;
    while (i < n && j < m) {
      if (c[i].first == s[j].first && fg[j] == 0 && co[i] == 0) {
        fg[j] = 1;
        co[i] = 1;
        so[c[i].second] = s[j].second + 1;
        ad[s[j].second] = k;
        i++;
        j++;
        cp++;
        adp += k;
      } else if (fg[j] == 1) {
        j++;
      } else if (co[i] == 1) {
        i++;
      } else if (c[i].first > s[j].first) {
        j++;
      } else {
        i++;
      }
    }
    j = 0;
    while (j < m) {
      s[j].first = (s[j].first + 1) / 2;
      j++;
    }
    k++;
  }
  cout << cp << " " << adp << endl;
  ;
  for (j = 0; j < m; j++) {
    cout << ad[j] << " ";
    ;
  }
  cout << endl;
  for (i = 0; i < n; i++) {
    cout << so[i] << " ";
    ;
  }
}
