#!/bin/ruby n = gets.strip.to_i calories = gets.strip.split(' ').map(&:to_i).sort.reverse ans = 0 n.times do |i| ans += (2 ** i) * calories[i] end puts ans