#include<iostream>
#include<cstdio>
using namespace std;
__int64 a[51];
__int64 sum;
int main()
{
int n;
while(cin>>n)
{
if(n == 0)
break;
int i;
sum = 0;
for(i = 1;i <= n;i++)
scanf("%I64d",&a[i]);
while(n > 0)
{
for(i = 1; i < n;i++)//从最后开时一次往i-1加a[i]
a[i] = a[i] + a[n];
sum = sum + a[n];
n--;
}
printf("%I64d\n",sum);
}
return 0;
}