#ifndef solution_h
#define solution_h 1
#include "library/Common.h"
#include "library/Debug.h"
namespace solution
{
const int sz = 2e5 + 105;
const int mod = 1e9 + 7;
const ll INF = 1e12;
int t, n;
ll ar[sz];
ll dp[sz][5][5][5];
int vis[sz][5][5][5];
int vs = 0;
ll rec(int x, int a, int b, int c)
{
if (x == n)
{
return 0;
}
ll &ret = dp[x][a][b][c];
if (vis[x][a][b][c] == vs)
{
return ret;
}
ret = INF;
vis[x][a][b][c] = vs;
for (int i = 0; i < 5; i++)
{
if (i == b || i == c)
{
continue;
}
ret = min(ret, rec(x + 1, b, c, i) + ar[x] * i);
}
return ret;
}
// 1 0 2 1 0
void solve_case()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld", &ar[i]);
}
memset(dp, -1, sizeof(dp));
ll ans = INF;
vs++;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i == j)
{
continue;
}
for (int k = 0; k < 5; k++)
{
if (i == k || j == k)
{
continue;
}
ans = min(ans, rec(3, i, j, k) + ar[0] * i + ar[1] * j + ar[2] * k);
}
}
}
printf("%lld\n", ans);
}
void solve()
{
vs = 0;
scanf("%d", &t);
while (t--)
{
solve_case();
}
}
} // namespace solution
#endif // solution_h