import java.util.Scanner;/*
使用递归模拟每次取披萨,使用递归注意找到关键点,就是每次某个人取披萨都是从两个选一个,
即每次递归传入1、是否是A 2、当前可选的左边坐标 3、当前可选的右边坐标,
结束标志就是左边和右边坐标相等
*/publicclassMain{publicstatic int N;publicstatic int[] ints;publicstatic int max;publicstatic int sumTemp;publicstaticvoidmain(String[] args){
Scanner sc =newScanner(System.in);N= sc.nextInt();
ints =newint[N];for(int i =0; i <N; i++){
ints[i]= sc.nextInt();}for(int i =0; i <N; i++){
int left =getLeft(i);
int right =getRight(i);
sumTemp += ints[i];handle(false, left, right);}
System.out.println(max);}publicstaticvoidhandle(boolean isA, int left, int right){if(left == right){if(isA){
sumTemp += ints[left];}
max = Math.max(max, sumTemp);
sumTemp =0;}else{if(ints[left]> ints[right]){if(isA){
sumTemp += ints[left];}handle(!isA,getLeft(left), right);}elseif(ints[left]< ints[right]){if(isA){
sumTemp += ints[right];}handle(!isA, left,getRight(right));}}}privatestatic int getRight(int i){// 获取右边return i <N-1? i +1:0;}privatestatic int getLeft(int i){// 获取左边return i >0? i -1:N-1;}}