#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T M) {
  long long ret = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) ret = (ret * b) % M;
    b = (b * b) % M;
  }
  return (T)ret;
}
template <class T>
inline T lcm(T a, T b) {
  return (a * b) / __gcd(a, b);
}
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
const double PI = acos(-1.0), EPS = 1e-7;
const long long INF = (long long)1e18 + 7;
const int N = 2e5 + 5, M = 1e9 + 7;
int n, m, p[N], pc[N], sc[N];
pair<int, int> s[N];
map<int, int> mp;
int ks, ad[N], soc[N], last[N];
vector<int> vec[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &p[i]);
    if (mp.find(p[i]) == mp.end()) mp[p[i]] = ++ks;
    int id = mp[p[i]];
    pc[id]++;
    vec[id].push_back(i);
  }
  for (int i = 1; i < m + 1; i++) {
    scanf("%d", &s[i].first);
    s[i].second = i;
  }
  sort(s + 1, s + m + 1);
  int c = 0, u = 0, t;
  for (int i = 1; i < m + 1; i++) {
    t = s[i].first;
    int a = 0, f = 0;
    for (;;) {
      if (mp.find(t) != mp.end()) {
        int id = mp[t];
        if (pc[id]) {
          pc[id]--;
          f = 1;
          c++;
          u += a;
          ad[s[i].second] = a;
          soc[vec[id][last[id]]] = s[i].second;
          last[id]++;
        }
      }
      if (f || t == 1) break;
      t = (t + 1) / 2;
      a++;
    }
  }
  printf("%d %d\n", c, u);
  for (int i = 1; i < m + 1; i++) printf("%d ", ad[i]);
  printf("\n");
  for (int i = 1; i < n + 1; i++) printf("%d ", soc[i]);
  printf("\n");
  return 0;
}
