#include using namespace std; int n; int k[1000]; int ans = 5000000; int calculateEven(int start) { int currentAnswer = 0, left = start - 1, right = start + 1; if (left < 0) left = n - 1; if (right >= n) right = 0; for (int i = 0; i < (n - 2) / 2; i++) { currentAnswer += ((i + 1) * (k[left] + k[right])); left--; right++; if (left == -1) left = n - 1; if (right == n) right = 0; } int ind = start + (n - 2) / 2 + 1; if (ind >= n) ind -= n; currentAnswer += (k[ind] * ((n - 2) / 2 + 1)); if (currentAnswer < ans) ans = currentAnswer; /// 1 2 3 4 5 6 7 8 } int calculateOdd(int start) { int currentAnswer = 0, left = start - 1, right = start + 1; if (left < 0) left = n - 1; if (right >= n) right = 0; for (int i = 0; i < (n - 1) / 2; i++) { currentAnswer += ((i + 1) * (k[left] + k[right])); left--; right++; if (left == -1) left = n - 1; if (right == n) right = 0; } if (currentAnswer < ans) ans = currentAnswer; } int main() { freopen("sortmach.in", "r", stdin); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &k[i]); fclose(stdin); if (n & 1) for (int i = 0; i < n; i++) calculateOdd(i); else for (int i = 0; i < n; i++) calculateEven(i); freopen("sortmach.out", "w" , stdout); printf("%d\n", ans); fclose(stdout); return 0; }