#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
void read(T& num) {
  char CH;
  bool F = false;
  for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
    ;
  for (num = 0; CH >= '0' && CH <= '9';
       num = num * 10 + CH - '0', CH = getchar())
    ;
  F && (num = -num);
}
const int N = 2e5 + 10;
struct node {
  int num, id;
  node() {}
  node(int nu, int i) : num(nu), id(i) {}
  bool operator<(const node& tmp) const {
    if (num != tmp.num) return num < tmp.num;
    return id < tmp.id;
  }
} p[N], s[N];
std::map<int, int> mp;
int a[N], b[N], c, u;
int main() {
  int n, m;
  read(n), read(m);
  for (int i = 1; i <= n; i++) {
    read(p[i].num);
    p[i].id = i;
    mp[p[i].num]++;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= m; i++) {
    read(s[i].num);
    s[i].id = i;
  }
  sort(s + 1, s + m + 1);
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= 30; j++) {
      if (mp.count(s[i].num)) {
        int t = lower_bound(p + 1, p + n + 1, node(s[i].num, 0)) - p +
                mp[s[i].num] - 1;
        if (p[t].num == s[i].num && !b[p[t].id]) {
          b[p[t].id] = s[i].id;
          mp[s[i].num]--;
          a[s[i].id] = j;
          u += j;
          c++;
          break;
        }
      }
      s[i].num = (s[i].num + 1) >> 1;
    }
  }
  printf("%d %d\n", c, u);
  for (int i = 1; i <= m; i++) printf("%d%c", a[i], i == m ? '\n' : ' ');
  for (int i = 1; i <= n; i++) printf("%d%c", b[i], i == n ? '\n' : ' ');
  return 0;
}
