#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 2e9;
const int mod = 1e9 + 7;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> p(n), pto(n), used(m), cnt(m);
  set<pair<int, int>> s;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < m; ++i) {
    int x;
    scanf("%d", &x);
    s.insert({x, i});
  }
  int cur = -1, dd = 1;
  while (1) {
    if (cur > 30) break;
    ++cur;
    set<pair<int, int>> kek;
    for (auto x : s) {
      x.first = (x.first / dd) + (x.first % dd);
      kek.insert(x);
    }
    s.swap(kek);
    dd = 2;
    for (int i = 0; i < n; ++i) {
      if (pto[i]) continue;
      auto it = s.lower_bound({p[i], -inf});
      if (it == s.end() || it->first != p[i]) continue;
      pto[i] = it->second + 1;
      cnt[it->second] = cur;
      s.erase(it);
    }
  }
  int c = 0, u = 0;
  for (int x : pto) c += x > 0;
  for (int x : cnt) u += x;
  printf("%d %d\n", c, u);
  for (int x : cnt) printf("%d ", x);
  printf("\n");
  for (int x : pto) printf("%d ", x);
}
