#include <bits/stdc++.h>
using namespace std;
struct TPair {
  int x, y;
  TPair(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
};
bool compx(TPair a, TPair b) { return a.x < b.x; }
const int MAXN = 2e5 + 2;
int n, m, c, u, s[MAXN], a[MAXN], b[MAXN];
vector<int> mp[MAXN];
bool used[MAXN];
TPair p[MAXN];
int Get(int x) {
  TPair *it = lower_bound(p + 1, p + 1 + n, TPair(x, 0), compx);
  if (it != p + 1 + n && it->x == x) return it - p;
  return 0;
}
void Solve() {
  for (int j = 0; j <= 30; ++j)
    for (int i = 1; i <= m; ++i) {
      if (used[i]) continue;
      int pos = Get(s[i]);
      if (!mp[pos].empty()) {
        a[i] = j;
        b[p[mp[pos].back()].y] = i;
        mp[pos].pop_back();
        ++c;
        u += j;
        used[i] = true;
      }
      if (s[i] == 1)
        used[i] = true;
      else
        s[i] = (s[i] + (s[i] & 1)) >> 1;
    }
  printf("%d %d\n", c, u);
  for (int i = 1; i <= m; ++i) printf("%d ", a[i]);
  printf("\n");
  for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i].x), p[i].y = i;
  for (int i = 1; i <= m; ++i) scanf("%d", &s[i]);
  sort(p + 1, p + 1 + n, compx);
  for (int i = 1; i <= n; ++i) mp[Get(p[i].x)].push_back(i);
  Solve();
  return 0;
}
