#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 2e5 + 5;
int p[N], s[N];
int vec[N][33];
int del[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < m; i++) cin >> s[i];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 32; j++) {
      vec[i][j] = s[i];
      s[i] = (s[i] + 1) / 2;
    }
  }
  multiset<int> second;
  multiset<pair<int, int> > Q;
  for (int i = 0; i < n; i++) second.insert(p[i]);
  int c = 0, u = 0;
  for (int i = 0; i < m; i++) Q.insert(make_pair(s[i], i));
  map<int, vector<int> > who;
  for (int i = 0; i < n; i++) who[p[i]].push_back(i);
  vector<int> match(n, -1);
  vector<int> used(m, 0);
  memset(del, 0, sizeof(del));
  for (int i = 0; i < 32; i++) {
    for (int j = 0; j < m; j++) {
      if (del[j]) continue;
      if (second.count(vec[j][i])) {
        c++;
        u += i;
        second.erase(second.find(vec[j][i]));
        match[who[vec[j][i]].back()] = j;
        del[j] = 1;
        who[vec[j][i]].pop_back();
        used[j] = i;
      }
    }
  }
  printf("%d %d\n", c, u);
  for (int i = 0; i < m; i++) {
    if (i) printf(" ");
    printf("%d", used[i]);
  }
  printf("\n");
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", match[i] + 1);
  }
  return 0;
}
