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;
  namespace Base {
  const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
  const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
  template <typename T>
  void read(T &x) {
    x = 0;
    int fh = 1;
    double num = 1.0;
    char ch = getchar();
    while (!isdigit(ch)) {
      if (ch == '-') fh = -1;
      ch = getchar();
    }
    while (isdigit(ch)) {
      x = x * 10 + ch - '0';
      ch = getchar();
    }
    if (ch == '.') {
      ch = getchar();
      while (isdigit(ch)) {
        num /= 10;
        x = x + num * (ch - '0');
        ch = getchar();
      }
    }
    x = x * fh;
  }
  template <typename T>
  void chmax(T &x, T y) {
    x = x < y ? y : x;
  }
  template <typename T>
  void chmin(T &x, T y) {
    x = x > y ? y : x;
  }
  }  // namespace Base
  using namespace Base;
  const int K = 20, N = (1 << K) + 10;
  int n, rt, k, place, cnt;
  struct Trie {
    int lmax, rmax, l, r, width;
    int ans;
  } T[N];
  int num[N], a[N], ans[N];
  void upd(int pos) {
    if (T[pos].l == 0)
      T[pos].lmax = T[pos].width / 2 + T[T[pos].r].lmax;
    else
      T[pos].lmax = T[T[pos].l].lmax;
    if (T[pos].r == 0)
      T[pos].rmax = T[T[pos].l].rmax;
    else
      T[pos].rmax = T[pos].width / 2 + T[T[pos].r].rmax;
    T[pos].ans = inf;
    if (T[pos].l != 0) chmin(T[pos].ans, T[T[pos].l].ans);
    if (T[pos].r != 0) chmin(T[pos].ans, T[T[pos].r].ans);
    if (T[pos].l != 0 && T[pos].r != 0)
      chmin(T[pos].ans, T[T[pos].r].lmax - T[T[pos].l].rmax + T[pos].width / 2);
  }
  void insert(int &pos, int dep, int x) {
    if (pos == 0) pos = ++place, T[pos].width = (1 << dep);
    if (dep == 0) {
      T[pos].lmax = T[pos].rmax = 0;
      T[pos].ans = inf;
      return;
    }
    if ((x & (1 << (dep - 1))) == 0)
      insert(T[pos].l, dep - 1, x);
    else
      insert(T[pos].r, dep - 1, x);
    upd(pos);
  }
  void rebuild(int &pos, int dep, int x) {
    if (pos == 0) return;
    if ((1 << dep) == x * 2) {
      swap(T[pos].l, T[pos].r);
      upd(pos);
      return;
    }
    rebuild(T[pos].l, dep - 1, x);
    rebuild(T[pos].r, dep - 1, x);
    upd(pos);
  }
  int main() {
    read(n);
    read(k);
    for (int i = 1; i <= n; i++) {
      read(num[i]);
      insert(rt, k, num[i]);
    }
    a[0] = 0;
    cnt = 1;
    for (int i = k - 1; i >= 0; i--) {
      for (int j = 0; j < cnt; j++) a[2 * cnt - j - 1] = a[j] + (1 << i);
      cnt = cnt * 2;
    }
    for (int i = 0; i < cnt; i++) {
      ans[a[i]] = T[rt].ans;
      if (i != cnt - 1) {
        int x = a[i] ^ a[i + 1];
        rebuild(rt, k, x);
      }
    }
    for (int i = 0; i < cnt; i++)
      printf("%d%c", ans[i], (i == cnt - 1) ? '\n' : ' ');
    return 0;
  }
  