#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int 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);
}
template <class T>
inline T bpow(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int ts, kk = 1;
int n, m;
int p[200005], s[200005], sz = 1;
vector<int> al[200005];
int id[200005];
map<int, int> mp;
map<int, int>::iterator it;
int on[200005];
int qr[200005];
int qq[200005];
int main() {
  int t, i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i < n + 1; i++) {
    scanf("%d", &p[i]);
    it = mp.find(p[i]);
    if (it != mp.end())
      k = it->second;
    else {
      id[sz] = 0;
      mp[p[i]] = sz++;
      k = sz - 1;
    }
    al[k].push_back(i);
  }
  for (i = 1; i < m + 1; i++) {
    scanf("%d", &s[i]);
  }
  int r1, r2;
  r1 = r2 = 0;
  for (i = 0; i < 32; i++) {
    for (j = 1; j <= m; j++) {
      if (on[j] || s[j] == 0) continue;
      t = s[j];
      s[j] = s[j] - s[j] / 2;
      it = mp.find(t);
      if (it != mp.end()) {
        k = it->second;
        if (id[k] < al[k].size()) {
          on[j] = 1;
          qq[al[k][id[k]++]] = j;
          qr[j] = i;
          s[j] = t;
          r1++;
          r2 += i;
        }
      }
    }
  }
  printf("%d %d\n", r1, r2);
  printf("%d", qr[1]);
  for (i = 2; i < m + 1; i++) {
    printf(" %d", qr[i]);
  }
  printf("\n%d", qq[1]);
  for (i = 2; i < n + 1; i++) {
    printf(" %d", qq[i]);
  }
  puts("");
  return 0;
}
