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.
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import java.util.StringTokenizer;

/**
 * @author Sri Mouli
 * Copyright © 2018 Sri Mouli. All rights reserved.
 */

public class A1084 {

    public static long MOD = 1000000007;
    public static long[][][] dp;
    public static String INPUT = "3 " +
            "0 2 1";

    @SuppressWarnings("unused")
    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        // PrintWriter out = new PrintWriter(new FileOutputStream(new
        // File("output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        FastReader in = new FastReader(oj);
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int min = Integer.MAX_VALUE;
        /*
        for(int i=1;i<n;i++) {
            int ans = 0;
            for(int j=0;j<n;j++) {
                ans+= 4*a[j]*j;
            }
            if(ans<min) {
                //System.out.println(i);
                min = ans;
            }
        }
        */
        int ans = 0;
        for(int j=0;j<n;j++) {
            ans+= 4*a[j]*j;
        }
        System.out.println(ans);
    }

    public static int upper_bound(int A[], int key) {
        int first = 0;
        int last = A.length;
        int mid;

        while (first < last) {
            mid = first + (last - first) / 2;

            if (A[mid] <= key)
                first = mid + 1;
            else
                last = mid;
        }
        return first;
    }

    // For finding greater than equal to
    public static int lower_bound(int A[], int key) {
        int first = 0;
        int last = A.length;
        int mid;
        while (first < last) {
            mid = first + ((last - first) >> 1);
            if (A[mid] < key)
                first = mid + 1;
            else
                last = mid;
        }

        return first;
    }

    @SuppressWarnings("rawtypes")
    public static void printPermutations(Comparable[] c) {
        System.out.println(Arrays.toString(c));
        while ((c = nextPermutation(c)) != null) {
            System.out.println(Arrays.toString(c));
        }
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    // modifies c to next permutation or returns null if such permutation does not
    // exist
    public static Comparable[] nextPermutation(final Comparable[] c) {
        // 1. finds the largest k, that c[k] < c[k+1]
        int first = getFirst(c);
        if (first == -1)
            return null; // no greater permutation
        // 2. find last index toSwap, that c[k] < c[toSwap]
        int toSwap = c.length - 1;
        while (c[first].compareTo(c[toSwap]) >= 0)
            --toSwap;
        // 3. swap elements with indexes first and last
        swap(c, first++, toSwap);
        // 4. reverse sequence from k+1 to n (inclusive)
        toSwap = c.length - 1;
        while (first < toSwap)
            swap(c, first++, toSwap--);
        return c;
    }

    // finds the largest k, that c[k] < c[k+1]
    // if no such k exists (there is not greater permutation), return -1
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static int getFirst(final Comparable[] c) {
        for (int i = c.length - 2; i >= 0; --i)
            if (c[i].compareTo(c[i + 1]) < 0)
                return i;
        return -1;
    }

    // swaps two elements (with indexes i and j) in array
    @SuppressWarnings("rawtypes")
    public static void swap(final Comparable[] c, final int i, final int j) {
        final Comparable tmp = c[i];
        c[i] = c[j];
        c[j] = tmp;
    }

    public static long cal(int index, int last, int n, int left) {
        if (index == n) {
            return left == 0 ? 1 : 0;
        }
        if (left < 0) {
            return 0;
        }
        if (dp[last][index][left] != -1) {
            return dp[last][index][left];
        }
        long result = 0;
        for (int i = 0; i < 4; i++) {
            result += cal(index + 1, i, n, left - count(last, i));
            result %= MOD;

        }
        return dp[last][index][left] = result;
    }

    public static int count(int last, int cur) {
        if (last == cur) {
            return 0;
        }
        if (last == 0) {
            return 1;
        }
        if (last == 1) {
            if (cur == 2) {
                return 2;
            }
            return 0;
        }
        if (last == 2) {
            if (cur == 1) {
                return 2;
            }
            return 0;
        }
        return 1;
    }

    public static boolean div(int need, String v) {
        int cur = 0;
        for (int i = 0; i < v.length(); i++) {
            cur += v.charAt(i) - '0';
            if (cur == need) {
                cur = 0;
            } else if (cur > need) {
                return false;
            }
        }
        return true;
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            return this.y == other.y;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    private static class Pair {
        long x;
        long y;

        @SuppressWarnings("unused")
        public Pair(long first, long second) {
            this.x = first;
            this.y = second;
        }

        @Override
        public String toString() {
            return "(" + x + "," + y + ")";
        }
    }

    @SuppressWarnings("rawtypes")
    public static Comparator csort = (Comparator<Pair>) (a, b) -> {
        if (a.x < b.x)
            return -1;
        else if (a.x > b.x)
            return 1;
        else
            return Long.compare(a.y, b.y);
    };

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;
        InputStream is;
        byte[] inbuf = new byte[1024];
        int lenbuf = 0, ptrbuf = 0;

        FastReader(boolean onlineJudge) {
            is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        FastReader(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return next().charAt(0);
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

    }

}
