The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. 

It was decided that elevator, when it is not used, will stay on the x-th floor, but x hasn't been chosen yet. When a person needs to get from floor a to floor b, elevator follows the simple algorithm: 

  * Moves from the x-th floor (initially it stays on the x-th floor) to the a-th and takes the passenger. 
  * Moves from the a-th floor to the b-th floor and lets out the passenger (if a equals b, elevator just opens and closes the doors, but still comes to the floor from the x-th floor). 
  * Moves from the b-th floor back to the x-th. 

The elevator never transposes more than one person and always goes back to the floor x before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the a-th floor to the b-th floor requires |a - b| units of electricity.

Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the x-th floor. Don't forget than elevator initially stays on the x-th floor. 

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of floors.

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 100) — the number of people on each floor.

Output

In a single line, print the answer to the problem — the minimum number of electricity units.

Examples

Input

3
0 2 1


Output

16

Input

2
1 1


Output

4

Note

In the first example, the answer can be achieved by choosing the second floor as the x-th floor. Each person from the second floor (there are two of them) would spend 4 units of electricity per day (2 to get down and 2 to get up), and one person from the third would spend 8 units of electricity per day (4 to get down and 4 to get up). 4 ⋅ 2 + 8 ⋅ 1 = 16.

In the second example, the answer can be achieved by choosing the first floor as the x-th floor.
#include <bits/stdc++.h>
using namespace std;
const int NN = 200008;
bool prime[NN];
bool isprime(int n) {
  if (n <= 1) return 0;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return prime[n] = true;
}
void feilprime() {
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= 300; i++) {
    if (isprime(i))
      for (int j = i + i; j < 300; j += i) prime[j] = 0;
  }
}
string DecToBinary(int num, string s) {
  if (num < 2)
    cout << num;
  else {
    DecToBinary(num / 2, s);
    s += num % 2;
  }
  return s;
}
bool isVowel(char c) {
  if (c == 'a' || c == 'y' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    return true;
  return false;
}
bool isPale(string s) {
  for (int i = 0, j = s.size() - 1; i <= j; i++, j--) {
    if (s[i] != s[j]) {
      return false;
    }
  }
  return true;
}
void sortBasedOnLength(string s[], int n) {
  for (int i = 1; i < n; i++) {
    string temp = s[i];
    int j = i - 1;
    while (j >= 0 && temp.length() < s[j].length()) {
      s[j + 1] = s[j];
      j--;
    }
    s[j + 1] = temp;
  }
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int getMid(int s, int e) { return s + (e - s) / 2; }
int getSumUtil(int *st, int ss, int se, int qs, int qe, int si) {
  if (qs <= ss && qe >= se) return st[si];
  if (se < qs || ss > qe) return 0;
  int mid = getMid(ss, se);
  return getSumUtil(st, ss, mid, qs, qe, 2 * si + 1) +
         getSumUtil(st, mid + 1, se, qs, qe, 2 * si + 2);
}
void updateValueUtil(int *st, int ss, int se, int i, int diff, int si) {
  if (i < ss || i > se) return;
  st[si] = st[si] + diff;
  if (se != ss) {
    int mid = getMid(ss, se);
    updateValueUtil(st, ss, mid, i, diff, 2 * si + 1);
    updateValueUtil(st, mid + 1, se, i, diff, 2 * si + 2);
  }
}
const int N = 100002 * 2;
int arr[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  int mn = 999999999;
  for (int i = 1; i <= n; i++) {
    int v = i;
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      if (j == 1) j = 0;
      sum += ((j * 2) + (2 * abs(j - i))) * arr[j - 1];
      if (j == 0) j = 1;
    }
    mn = min(sum, mn);
  }
  cout << mn << endl;
  return 0;
}
