#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> c[200005];
pair<long long, long long> s[200005];
long long n, m, adapter[200005], used[200005], lo[200005], ge1 = 0, ge2 = 0, i,
                                                           j;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> c[i].first;
    c[i].second = i;
  }
  for (i = 1; i <= m; i++) {
    cin >> s[i].first;
    s[i].second = i;
  }
  sort(c + 1, c + 1 + n);
  sort(s + 1, s + 1 + m);
  for (int z = 0; z < 33; z++) {
    for (i = 1, j = 1; i <= n; i++) {
      if (lo[c[i].second]) continue;
      while (j <= m && (s[j].first < c[i].first)) {
        j++;
      }
      while (j <= m && used[s[j].second]) {
        j++;
      }
      if (j <= m && !used[s[j].second] && s[j].first == c[i].first) {
        lo[c[i].second] = s[j].second;
        used[s[j].second] = 1;
        adapter[s[j].second] = z;
        ge1++;
        ge2 += z;
      }
    }
    for (i = 1; i <= m; i++) {
      s[i].first = (s[i].first + 1) / 2;
    }
  }
  cout << ge1 << " " << ge2 << endl;
  for (i = 1; i <= m; i++) {
    cout << adapter[i] << " ";
  }
  cout << endl;
  for (i = 1; i <= n; i++) {
    cout << lo[i] << " ";
  }
  cout << endl;
}
