module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 

	#def memoize(name)
	#	original = "__original_#{name}__"
	#	klass = ([Class, Module].include?(self.class) ? self : self.class)
	#	klass.class_eval <<-"EOS"
	#		alias_method('#{original}', '#{name}')
	#		private('#{original}')
	#		@@cache_for_#{name} = {}
	#		def #{name}(*args)
	#			@@cache_for_#{name}[args] ||= send('#{original}', *args)
	#		end
	#	EOS
	#end 
end
include Memoizable

$n = gets.to_i
$a = [0] + (1..$n-1).map{ gets.to_i }

def f(lesser, greater, i)
	return 0 if lesser + $n - i == greater
	return Float::INFINITY if lesser + $n - i < greater
	
	min = Float::INFINITY
	(i+1..$n-1).each{|j|
		m = $a[j] + f(*[lesser+j-i, greater].sort, j)
		min = m if m < min
	}
	min
end

memoize :f

p f(0, 0, 0)