N = gets.to_i

cards = gets.split(' ').map(&:to_i)
coms = [[1,1]]
cardcoms = [cards]

def newcoms(coms)
	newcoms = Array.new
	coms.each do |com|
		(1..com.size-1).each do |i|
			newcoms.push(com[0..i-1]+[(com[i-1]+com[i])]+com[i..100])
		end
	end
	return newcoms.uniq
end
def newcardcoms(cardcoms)
	newcardcoms = Array.new
	cardcoms.each do |cards|
		(1..cards.size-2).each do |i|
          if i>1
			newcardcoms.push(cards[0..i-2]+[cards[i-1]+cards[i], cards[i]+cards[i+1]]+cards[i+2..100])
          else
            newcardcoms.push([cards[i-1]+cards[i], cards[i]+cards[i+1]]+cards[i+2..100])
          end
		end
	end
	return newcardcoms.uniq
end

m = [3,N/2].max

(m-2).times do
	coms = newcoms(coms)
end

(N-m).times do
	cardcoms = newcardcoms(cardcoms)
end

ans = 0
cardcoms.each do |cardcom|
	coms.each do |com|
      val = 0
      m.times do |i|
        val += com[i]*cardcom[i]
      end
      ans = val if ans == 0
		ans = [ans, val].min
	end
end

p ans