import java.util.*;
public class Main {
private static int max=0;
public static void getMax(int[] workList,int now,int sum,int day){
if(now<workList.length){
if(day==0){
getMax(workList, now+1, sum, 0);
getMax(workList, now+1, sum+workList[now],day+1);
}else if(day==1){
getMax(workList,now+1,sum,0);
getMax(workList, now+1, sum+workList[now], day+1);
}else if(day==2){
getMax(workList, now+1, sum, 0);
}
}else{
if(sum>max){
max=sum;
}
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int[] seq = new int[n];
for(int i=0;i<n;i++){
seq[i] = sc.nextInt();
}
Main m = new Main();
m.getMax(seq, 0, 0, 0);
System.out.println(max);
}
}
}
public class Main {
private static int max=0;
public static void getMax(int[] workList,int now,int sum,int day){
if(now<workList.length){
if(day==0){
getMax(workList, now+1, sum, 0);
getMax(workList, now+1, sum+workList[now],day+1);
}else if(day==1){
getMax(workList,now+1,sum,0);
getMax(workList, now+1, sum+workList[now], day+1);
}else if(day==2){
getMax(workList, now+1, sum, 0);
}
}else{
if(sum>max){
max=sum;
}
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int[] seq = new int[n];
for(int i=0;i<n;i++){
seq[i] = sc.nextInt();
}
Main m = new Main();
m.getMax(seq, 0, 0, 0);
System.out.println(max);
}
}
}