description: You are given an array a consisting of n distinct elements and an integer k. Each element in the array is a non-negative integer not exceeding 2^k-1.
  
  Let's define the XOR distance for a number x as the value of 
  
  $$$f(x) = min_{i = 1}^{n} min_{j = i + 1}^{n} |(a_i ⊕ x) - (a_j ⊕ x)|,$$$
  
  where ⊕ denotes [the bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
  
  For every integer x from 0 to 2^k-1, you have to calculate f(x).
  
  Input
  
  The first line contains two integers n and k (1 ≤ k ≤ 19; 2 ≤ n ≤ 2^k).
  
  The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^k-1). All these integers are distinct.
  
  Output
  
  Print 2^k integers. The i-th of them should be equal to f(i-1).
  
  Examples
  
  Input
  
  
  3 3
  6 0 3
  
  
  Output
  
  
  3 1 1 2 2 1 1 3 
  
  
  Input
  
  
  3 4
  13 4 2
  
  
  Output
  
  
  2 2 6 6 3 1 2 2 2 2 1 3 6 6 2 2 
  
  Note
  
  Consider the first example:
  
    * for x = 0, if we apply bitwise XOR to the elements of the array with x, we get the array [6, 0, 3], and the minimum absolute difference of two elements is 3; 
    * for x = 1, if we apply bitwise XOR to the elements of the array with x, we get the array [7, 1, 2], and the minimum absolute difference of two elements is 1; 
    * for x = 2, if we apply bitwise XOR to the elements of the array with x, we get the array [4, 2, 1], and the minimum absolute difference of two elements is 1; 
    * for x = 3, if we apply bitwise XOR to the elements of the array with x, we get the array [5, 3, 0], and the minimum absolute difference of two elements is 2; 
    * for x = 4, if we apply bitwise XOR to the elements of the array with x, we get the array [2, 4, 7], and the minimum absolute difference of two elements is 2; 
    * for x = 5, if we apply bitwise XOR to the elements of the array with x, we get the array [3, 5, 6], and the minimum absolute difference of two elements is 1; 
    * for x = 6, if we apply bitwise XOR to the elements of the array with x, we get the array [0, 6, 5], and the minimum absolute difference of two elements is 1; 
    * for x = 7, if we apply bitwise XOR to the elements of the array with x, we get the array [1, 7, 4], and the minimum absolute difference of two elements is 3. 
solution: #include <bits/stdc++.h>
  using namespace std;
  const int mod = 1000000007;
  int mult(int a, int b) { return a * (long long)b % mod; }
  int bp(int a, int b) {
    int res = 1;
    while (b > 0) {
      if (b & 1) res = mult(res, a);
      a = mult(a, a);
      b >>= 1;
    }
    return res;
  }
  vector<int> ans;
  const int N = (1 << 19);
  vector<int> arr[N];
  struct Vertex {
    int ed[2];
  };
  vector<Vertex> bor;
  void create() {
    Vertex q;
    q.ed[0] = -1;
    q.ed[1] = -1;
    bor.push_back(q);
  }
  int add(int first, int second) {
    if (bor[first].ed[second] == -1) {
      create();
      bor[first].ed[second] = bor.size() - 1;
    }
    return bor[first].ed[second];
  }
  int get_min(int st, int rem, int bits) {
    int ans = st * (1 << (bits - 1));
    int cur = bor[0].ed[st];
    for (int i = bits - 2; i >= 0; --i) {
      int Q = (((1 << i) & rem) > 0);
      if (bor[cur].ed[Q] != -1) {
        ans += (1 << i) * Q;
        cur = bor[cur].ed[Q];
      } else {
        ans += (1 << i) * (1 - Q);
        cur = bor[cur].ed[(1 - Q)];
      }
    }
    return ans;
  }
  int get_max(int st, int rem, int bits) {
    int ans = st * (1 << (bits - 1));
    int cur = bor[0].ed[st];
    for (int i = bits - 2; i >= 0; --i) {
      int Q = 1 - (((1 << i) & rem) > 0);
      if (bor[cur].ed[Q] != -1) {
        ans += (1 << i) * Q;
        cur = bor[cur].ed[Q];
      } else {
        ans += (1 << i) * (1 - Q);
        cur = bor[cur].ed[(1 - Q)];
      }
    }
    return ans;
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &first : v) cin >> first;
    ans.assign((1 << k), 1e9);
    for (int bits = 0; bits < k; ++bits) {
      for (int i = 0; i < (1 << k); ++i) arr[i].clear();
      for (int i = 0; i < n; ++i) {
        int left_part = v[i] >> (k - bits);
        int right_part = v[i] ^ (left_part << (k - bits));
        arr[left_part].push_back(right_part);
      }
      vector<int> best_remainder(1 << (k - bits), 1e9);
      for (int i = 0; i < (1 << k); ++i) {
        if (arr[i].size() != 0) {
          bor.clear();
          create();
          for (auto first : arr[i]) {
            int cur = 0;
            for (int j = k - bits - 1; j >= 0; --j) {
              if ((first & (1 << j)) != 0) {
                cur = add(cur, 1);
              } else
                cur = add(cur, 0);
            }
          }
          if (bor[0].ed[0] == -1 || bor[0].ed[1] == -1) continue;
          for (int rem = 0; rem < (1 << (k - bits)); ++rem) {
            if (rem < (1 << (k - bits - 1))) {
              int A = get_min(1, rem, k - bits);
              int B = get_max(0, rem, k - bits);
              best_remainder[rem] =
                  min(best_remainder[rem], abs((A ^ rem) - (B ^ rem)));
            } else {
              int A = get_min(0, rem, k - bits);
              int B = get_max(1, rem, k - bits);
              best_remainder[rem] =
                  min(best_remainder[rem], abs((A ^ rem) - (B ^ rem)));
            }
          }
        }
      }
      for (int i = 0; i < (1 << k); ++i) {
        ans[i] = min(ans[i], best_remainder[i % (1 << (k - bits))]);
      }
    }
    for (auto first : ans) cout << first << " ";
  }
  