N = gets.to_i A = gets.split.map(&:to_i).sort.reverse k = 0 ans = 0 until A.empty? cnt = 2 ** k while cnt > 0 && a = A.shift ans += k * a cnt -= 1 end k += 1 end puts ans