n = gets.to_i A = gets.split.map(&:to_i).sort A.pop ans = 0 f = 1 until A.empty? ans += A.pop(2**f).sum * f f += 1 end puts ans