#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<vector<vector<pair<int16_t, int16_t>>>> cs(min(n, 16) + 1);
  cs[2].push_back({{1, 0}, {0, 1}});
  for (int m = 3; m <= min(n, 16); ++m) {
    for (int ml = 2; ml < m; ++ml) {
      int mr = m - ml + 1;
      for (const auto& cl : cs[ml]) {
        for (const auto& cr : cs[mr]) {
          vector<pair<int16_t, int16_t>> c(m);
          c[0] = {1, 0};
          for (int i = 1; i < ml - 1; ++i) {
            c[i] = cl[i];
            c[i].first += c[i].second;
          }
          c[ml - 1] = {1, 1};
          for (int i = 1; i < mr - 1; ++i) {
            c[ml + i - 1] = cr[i];
            c[ml + i - 1].second += c[ml + i - 1].first;
          }
          c.back() = {0, 1};
          cs[m].push_back(c);
        }
      }
    }
  }
  long long res = 1e18;
  if (n <= 16) {
    for (const auto& c : cs[n]) {
      long long cur = 0;
      for (int i = 0; i < n; ++i) {
        cur += (c[i].first + c[i].second) * a[i];
      }
      res = min(res, cur);
    }
  } else if (n == 17) {
    for (int nl = 2; nl < n; ++nl) {
      int nr = n - nl + 1;
      for (const auto& cl : cs[nl]) {
        for (const auto& cr : cs[nr]) {
          long long cur = 0;
          cur += a[0];
          for (int i = 1; i < nl - 1; ++i) {
            cur += (cl[i].first + 2 * cl[i].second) * a[i];
          }
          cur += 2 * a[nl - 1];
          for (int i = 1; i < nr - 1; ++i) {
            cur += (2 * cr[i].first + cr[i].second) * a[nl + i - 1];
          }
          cur += a.back();
          res = min(res, cur);
        }
      }
    }
  } else {
    for (int nl = 3; nl < n - 1; ++nl) {
      int nr = n - nl + 1;
      for (const auto& cl : cs[nl]) {
        for (const auto& cr : cs[nr]) {
          long long cur = 0;
          cur += a[0];
          for (int i = 1; i < nl - 1; ++i) {
            cur += (cl[i].first + 2 * cl[i].second) * a[i];
          }
          cur += 2 * a[nl - 1];
          for (int i = 1; i < nr - 1; ++i) {
            cur += (2 * cr[i].first + cr[i].second) * a[nl + i - 1];
          }
          cur += a.back();
          res = min(res, cur);
        }
      }
    }
    for (int nl = 2; nl < n - 1; ++nl) {
      int nr = n - nl;
      for (const auto& cl : cs[nl]) {
        for (const auto& cr : cs[nr]) {
          vector<pair<int16_t, int16_t>> c(n - 1);
          c[0] = {1, 0};
          for (int i = 1; i < nl - 1; ++i) {
            c[i] = cl[i];
            c[i].first += c[i].second;
          }
          c[nl - 1] = {1, 1};
          for (int i = 1; i < nr - 1; ++i) {
            c[nl + i - 1] = cr[i];
            c[nl + i - 1].second += c[nl + i - 1].first;
          }
          c.back() = {0, 1};
          {
            long long cur = a[0];
            for (int i = 0; i < n - 1; ++i) {
              cur += (2 * c[i].first + c[i].second) * a[i + 1];
            }
            res = min(res, cur);
          }
          {
            long long cur = a.back();
            for (int i = 0; i < n - 1; ++i) {
              cur += (c[i].first + 2 * c[i].second) * a[i];
            }
            res = min(res, cur);
          }
        }
      }
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 377628