function main(){
	var n = scan();
	var a = Array(n);
	rep(n, function(i){
		a[i] = scan();
	});
	a = a.concat(a);

	var dp = Array(n + 1);
	rep(n + 1, function(i){
		dp[i] = Array(n);
		rep(n, function(j){
			if(i == 0){
				dp[i][j] = 0;
			}
			else if(i == 1){
				dp[i][j] = a[j];
			}
			else{
				if(a[j + 1] < a[j + i - 1]){
					dp[i][j] = dp[i - 2][(j + 1) % n] + a[j];
				}
				else{
					dp[i][j] = dp[i - 2][(j + 2) % n] + a[j];
				}
				if(a[j] < a[j + i - 2]){
					dp[i][j] = Math.max(dp[i - 2][j] + a[i + j - 1], dp[i][j]);
				}
				else{
					dp[i][j] = Math.max(dp[i - 2][(j + 1) % n] + a[i + j - 1], dp[i][j]);
				}
			}
		});
	});
	print(Math.max.apply(null, dp[n]));
}

function rep(n, func){
	for(var i = 0; i < n; ++i){
		func(i);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';
var input_index = 0;

function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}

function print(val){
	console.log(val);
}

process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});