// Author: Christoph Schwirzer
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
LL a[256];
LL dp[256][256];
const LL OO = 1000000000000000000LL;
int main()
{
//	freopen("elias.in", "r", stdin);
	int n;
	while (cin >> n, n)
	{
		for (int i=0; i<n; i++)
			cin >> a[i+1];
		for (int i=0; i<=n; i++)
			for (int j=0; j<=n; j++)
				dp[i][j] = OO;
		dp[0][0] = 0;
		LL res = LLONG_MAX;
		for (int i=1; i<=n; i++)
		{
			for (int j=1; j<=n; j++)
			{
				LL sum = 0;
				for (int k=j; k>=1; k--)
				{
					sum += a[k] * (i + j);
					dp[i][j] = min(dp[i][j], dp[i-1][k-1] + sum);
				}
			}
			res = min(res, dp[i][n]);
		}
		cout << res << endl;
	}
	return 0;
}
