import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str0 = sc.nextLine();
int L = Integer.parseInt(str0);
String str1 = sc.nextLine();
String[] str2 = str1.split(" ");
int[] a = new int[L];
for(int i=0; i<L; i++){
a[i] = Integer.parseInt(str2[i]);
}
int res = smallestNum(a,L);
System.out.println(res);
}
private static int smallestNum(int[] a, int L) {
int sum = 0;
StringBuffer sb = new StringBuffer();
for(int i=0; i<L; i++){
sb.append(a[i]+" ");
}
int i=0;
int j=a.length-1;
while(i<j){
if(a[i] != a[j]){
int min = a[i]>a[j]?a[j]:a[i];
sb.append(min+" ");
if(a[i]<a[j]){
i++;
}else{
j--;
}
}else{
i++;
j--;
}
}
String str1 = sb.toString();
String[] str2 = str1.split(" ");
int[] b = new int[str2.length];
for(int k=0; k<str2.length; k++){
b[k] = Integer.parseInt(str2[k]);
sum += b[k];
}
return sum;
}
}