#!/bin/ruby n = gets.strip.to_i calories = gets.strip calories = calories.split(' ').map(&:to_i) # your code goes here calories = calories.sort { |a, b| b <=> a } miles = 0 calories.each_with_index do |c, i| miles += c * 2 ** i end puts miles