#include<iostream>
using namespace std;
int main()
{
int total,book[101],temp[101];
cin>>total;
int i,j;
for(i=0; i<total; i++)
cin>>book[i];
int score=0,c=total;
while(c>1)
{
for(i=0; i<c; i++)
{
temp[i]=book[i];
}
int index=0,min=10000000;
int t=book[0];
for(i=0; i<c; i++)
{
if(i<c-1)
book[i]+=book[i+1];
else
book[i]+=t;
}
for(i=0; i<c; i++)
{
if(min>book[i])
{
min=book[i];
index=i;
}
}
score+=min;
// cout<<score<<endl;
for(i=0,j=0; i<c; i++,j++)
{
if(i==index)
{
if(index!=c-1)
{
book[i]=min;
j++;
}else
{
book[0]=min;
}
}
else
{
book[i]=temp[j];
}
// cout<<book[i]<<" ";
}
c--;
// cout<<endl;
}
cout<<score<<endl;
return 0;
}