#include<stdio.h>
int data[99];
int vist[99];
int shu;
int max;
void dfs(int step,int sum)
{
int left=-1;
int right=-1;
if(step==shu-1)
{
for(int i=0;i<shu;i++)
if(vist[i]==0)
sum+=data[i];
if(sum>max)
max=sum;
return ;
}
for(int i=0;i<shu;i++)
{
if(vist[i]==0)
{
vist[i]=1;
int n=i;
while(n>=0&&vist[n]==1)
{
n--;
}
if(n>=0&&vist[n]==0)
{
left=data[n];
}
n=i;
while(n<shu&&vist[n]==1)
{
n++;
}
if(n<shu&&vist[n]==0)
{
right=data[n];
}
if(left==-1)
dfs(step+1,sum+right);
else if(right==-1)
dfs(step+1,sum+left);
else
dfs(step+1,sum+left*right);
vist[i]=0;
left=-1;
right=-1;
}
}
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d",&shu)!=EOF)
{
for(int i=0;i<shu;i++)
{
scanf("%d",&data[i]);
vist[i]=0;
}
max=-1;
dfs(0,0);
printf("%d
",max);
}
return 0;
}