#[allow(dead_code)] #[allow(unused_imports)] fn read() -> T { use std::io::*; let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } fn main(){ let n:usize = read(); let mut a:Vec = (0..n).map(|_| read()).collect(); a.sort(); a.reverse(); let mut con = 0; let mut ans = 0; let mut sum = 0; let mut cnt = 0; let mut floor = -1; let mut i = 0; while i < n { if con == 0 { con = 1; }else { con *= 2; } floor += 1; let mut cnt = 0; let mut sum = 0; while i < n && cnt < con { sum += a[i]; cnt += 1; i += 1; } ans += floor * sum; } println!("{}",ans); }