module mod_or_plus_max
  implicit none
  integer :: n, a(-1:262143), u
  integer :: f(0:262143), s(0:262143)
contains
  recursive subroutine bit_group(x)
    implicit none
    integer, intent(in) :: x
    integer :: i, y
    if ((f(x).ge.0).and.(s(x).ge.0)) return
    if (and(x,x-1).eq.0) then
      f(x) = 0
      s(x) = x
      if (a(0).lt.a(x)) then
        f(x) = x
        s(x) = 0
      end if
      return
    end if
    do i = 0, n
      if (btest(x,i)) call bit_group(ibclr(x,i))
    end do
    f(x) = x
    do i = 0, n
      if (.not.btest(x,i)) cycle
      y = ibclr(x,i)
      if (a(f(x)).lt.a(f(y))) then
        f(x) = f(y)
      end if
    end do
    if (f(x).ne.x) s(x) = x
    do i = 0, n
      if (.not.btest(x,i)) cycle
      y = ibclr(x,i)
      if ((a(s(x)).lt.a(f(y))).and.(f(y).ne.f(x))) then
        s(x) = f(y)
      end if
      if ((a(s(x)).lt.a(s(y))).and.(s(y).ne.f(x))) then
        s(x) = s(y)
      end if
    end do
    return
  end subroutine bit_group
end module mod_or_plus_max
program or_plus_max
  use mod_or_plus_max
  implicit none
  integer :: k, m, t
  a = -1
  f = -1
  s = -1
  read(*,*) n
  u = 2**n-1
  read(*,*) a(0:u)
  call bit_group(u)
  t = 0
  do k = 1, u
    m = a(f(k))+a(s(k))
    if (m.lt.t) m = t
    write(*,'(i0)') m
    t = m
  end do
  stop
end program or_plus_max