Language: C++

use io::*;
use std::cmp::max;

fn maxp(a: (i64, i64), b: (i64, i64)) -> (i64, i64) {
    if a.0 > b.0 {
        (a.0, max(a.1, b.0))
    } else {
        (b.0, max(a.0, b.1))
    }
}

fn solve(pos: usize, p: usize, tbl: &mut Vec<Vec<(i64, i64)>>, a: &Vec<i64>) -> (i64, i64) {
    if pos >= tbl.len() {
        return (a[p],-1);
    }

    if tbl[pos][p].0 >= 0 {
        return tbl[pos][p];
    }

    let ret = solve(pos+1,p, tbl, a);
    let ret = if p&(1<<pos) != 0 {
        maxp(ret, solve(pos+1, p&!(1<<pos),tbl,a))
    } else {ret};

    tbl[pos][p] = ret;
    ret
}

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let a: Vec<i64> = sc.next_vec(1 << n);

    let mut tbl: Vec<Vec<(i64, i64)>> = vec![vec![(-1, -1); 1<<n]; n];

    let mut ans = 0;

    for k in 1..1 << n {
        // println!("* k: {}", cnv(k));
        let t = solve(0, k, &mut tbl, &a);
        ans = max(ans, t.0 + t.1);
        println!("{}", ans);
    }
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Compiler output:
a.cc:41:14: error: too many decimal points in number
   41 |     for k in 1..1 << n {
      |              ^~~~
a.cc:55:24: warning: missing terminating ' character
   55 |     pub struct Scanner<'a> {
      |                        ^
a.cc:55:24: error: missing terminating ' character
   55 |     pub struct Scanner<'a> {
      |                        ^~~~~
a.cc:56:41: warning: missing terminating ' character
   56 |         iter: std::str::SplitWhitespace<'a>,
      |                                         ^
a.cc:56:41: error: missing terminating ' character
   56 |         iter: std::str::SplitWhitespace<'a>,
      |                                         ^~~~
a.cc:59:10: warning: multi-character literal with 11 characters exceeds 'int' size of 4 bytes
   59 |     impl<'a> Scanner<'a> {
      |          ^~~~~~~~~~~~~~
a.cc:60:24: warning: multi-character literal with 18 characters exceeds 'int' size of 4 bytes
   60 |         pub fn new(s: &'a str) -> Scanner<'a> {
      |                        ^~~~~~~~~~~~~~~~~~~~~
a.cc:81:14: error: too many decimal points in number
   81 |             (0..n).map(|_| self.next()).collect()
      |              ^~~~
a.cc:1:1: error: 'use' does not name a type
    1 | use io::*;
      | ^~~
a.cc:2:1: error: 'use' does not name a type
    2 | use std::cmp::max;
      | ^~~
a.cc:4:1: error: 'fn' does not name a type
    4 | fn maxp(a: (i64, i64), b: (i64, i64)) -> (i64, i64) {
      | ^~
a.cc:12:1: error: 'fn' does not name a type
   12 | fn solve(pos: usize, p: usize, tbl: &mut Vec<Vec<(i64, i64)>>, a: &Vec<i64>) -> (i64, i64) {
      | ^~
a.cc:30:1: error: 'fn' does not name a type
   30 | fn main() {
      | ^~
a.cc:51:1: error: 'pub' does not name a type
   51 | pub mod io {
      | ^~~
a.cc:59:5: error: 'impl' does not name a type
   59 |     impl<'a> Scanner<'a> {
      |     ^~~~
a.cc:85:5: error: 'pub' does not name a type
   85 |     pub fn read_string() -> String {
      |     ^~~
a.cc:93:5: error: 'pub' does not name a type
   93 |     pub fn read_line() -> String {
      |     ^~~
a.cc:98:1: error: expected declaration before '}' token
   98 | }
      | ^