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 
end

N = gets.to_i
A = $<.read.split($/).map(&:to_i)

include Memoizable

def f(turn, i, j)
	if turn
		if i == j
			0
		elsif A[i] > A[j]
			f(false, (i - 1) % N, j)
		else
			f(false, i, (j + 1) % N)
		end
	else
		if i == j
			A[i]
		else
			[
			A[i] + f(true, (i - 1) % N, j),
			A[j] + f(true, i, (j + 1) % N)
			].max
		end
	end
end

memoize(:f)

p (0..N-1).map{|i|
	A[i] + f(true, (i - 1) % N, (i + 1) % N)
}.max