#include <stdio.h>
#include <string.h>

#define SUM(A, B) ((A + B >= N) ? (A + B - N) : (A + B))

#define MAX 23

int N, A[MAX], U[MAX], Sum, Max = 20000;

void dfs( int die )
{
  int i, sum = 0, d, a, b;

  if (Sum + (N - die) >= Max)
    return;
  if (die == N)
  { 
    Max = Sum;
    return; 
  }
  if (die)
    for (i = 0; i < N; i++)
      if (!U[i])
        sum += A[i];
  Sum += sum;
  for (i = 0; i < N; i++)
    if (!U[i] && (U[i ? i - 1 : N - 1] || (!U[SUM(i, 1)] && !U[SUM(i, 2)])))
    {
      d = 1 + !U[a = SUM(i, 1)] + !U[b = SUM(i, 2)];
      U[i]++, U[a]++, U[b]++;
      dfs(die + d);  
      U[i]--, U[a]--, U[b]--;
    }
  Sum -= sum;
}

int main( void )
{
  int i;

  scanf("%d", &N);
  for (i = 0; i < N; i++)
    scanf("%d", &A[i]);
  memset(U, 0, sizeof(U));
  dfs(0);
  printf("%d", Max);
  return 0;
}