#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a, b;
vector<int> aa, bb, ua, ub;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  b.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i].first;
    b[i].second = i;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ua.assign(n, 0);
  ub.assign(m, 0);
  aa.assign(m, 0);
  bb.assign(n, 0);
  for (int rep = 0; rep < 31; ++rep) {
    int i = 0;
    int j = 0;
    while (i < n && j < m) {
      if (ua[i])
        ++i;
      else if (ub[j])
        ++j;
      else {
        if (a[i].first == b[j].first) {
          bb[a[i].second] = b[j].second + 1;
          aa[b[j].second] = rep;
          ua[i] = 1;
          ub[j] = 1;
        } else if (a[i].first < b[j].first)
          ++i;
        else
          ++j;
      }
    }
    for (int i = 0; i < m; ++i) {
      if (ub[i] == 0) b[i].first = (b[i].first + 1) / 2;
    }
  }
  cout << accumulate(ua.begin(), ua.end(), 0) << " "
       << accumulate(aa.begin(), aa.end(), 0) << endl;
  for (int i = 0; i < m; ++i) cout << aa[i] << " ";
  cout << endl;
  for (int i = 0; i < n; ++i) cout << bb[i] << " ";
  cout << endl;
  return 0;
}
