#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { (void)std::initializer_list<int>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple)
  { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { os << "("; (void)std::initializer_list<int>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < class Value >
bool bat(Value x, std::size_t pos) { return (x >> pos) & Value{1}; }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  int N = 1 << n;
  std::vector<lint> a(N); std::cin>>a;
  debug(n,N,a);

  std::vector<std::pair<lint,lint>> large_two(N);
  rep(bs,0,N) {
    large_two.at(bs) = {a.at(bs), 0};
  }
  auto mul = [&] (auto&& p, auto&& q) {
    lint x,y,z,w; std::tie(x,y) = p, std::tie(z,w) = q;
    return std::make_pair(std::max(x,z), std::max({std::min(x,z), y, w}));
  };
  rep(i,0,n) rep(bs,0,N) {
    if (!bat(bs,i)) continue;
    large_two.at(bs) = mul(large_two.at(bs), large_two.at(bs ^ 1<<i));
  }

  std::vector<lint> dp(N);
  rep(bs,0,N) {
    lint x,y; std::tie(x,y) = large_two.at(bs);
    dp.at(bs) = x + y;
  }

  #if DEBUG
    rep(bs,0,N) {
      debug(bs,large_two.at(bs), dp.at(bs));
    }
  #endif

  rep(bs,1,N) {
    cmx(dp.at(bs), dp.at(bs-1));
  }
  rep(bs,1,N) {
    std::cout << dp.at(bs) << std::endl;
  }
  return 0;
}

/*
K 以下という条件を、bit 表現で K に含まれるに書き換えて、あとで cmx すればよいです。
これは、i, j がいずれも K に含まれることと同じなので、これらは第一位、第二位です。
高速ゼータ変換で、第一位と第二位のペアを DP です。
*/

Measured memory_bytes: 11264