import sys
input = sys.stdin.readline
n = int(input())
s = [0]+list(map(int, input().split()))
ret = 9876543210
for xth in range(1, len(s)):
    summ = 0
    for i in range(1, len(s)):
        summ += 2*(abs(xth-i)+(i-1)+(xth-1))*s[i]
    ret=min(ret, summ)
print(ret)

n = int(input())
min = 0
res = input().split()
for i in range(n):
    min += i*int(res[i])
print(4*min)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 12 19:01:12 2018

@author: mach
"""

i = int(input())
l = list(map(int, input().strip().split()))
sums = 0
for k in range(1,i):
    sums += 4*k*l[k]
print(sums)

n=int(input())
x = list(map(int, input().split(" ")))
sum=0
for i in range(n):
   sum+=i*4*x[i]
print(sum)

#for i in range(int(input())):
n=int(input())
arr=[int(x) for x in input().split()]
final=-1
for i in range(n):
	temp=2
	cost=0
	for j in range(i+1):
	#	print(arr[j],j+1)
		cost+=arr[j]*(j)+abs(j-i)*arr[j]+abs(i)*arr[j]
		cost+=arr[j]*(j)+abs(j-i)*arr[j]+abs(i)*arr[j]

	#print(cost,i)
	for j in range(i+1,n):
		cost+=arr[j]*(j)+abs(j-i)*arr[j]+abs(i)*arr[j]
		cost+=arr[j]*(j)+abs(j-i)*arr[j]+abs(i)*arr[j]

	if cost<final or final==-1:
		final=cost
	#print(cost,i)
print(final)

n = int(input())
a = input().split()
a = [int(item) for item in a]
def lf(x,et):
    s = 2*(abs(et-x) + abs(x -1) + abs(et-1))
    return(s)
f = []
for i in range(n):
    s2 = 0
    for j in range(n):
        s2 += lf(i+1,j+1)*a[j]
    f.append(s2)
print(min(f))

n = map(int, input())
m = list(map(int, input().split()))
index = m.index(max(m))
k = 0
for i in range(len(m)):
    k += i*4*m[i]
print(k)

from sys import stdin
n = int(stdin.readline())
a =  map(int,stdin.readline().split())
def get(x):
    ans = 0
    for i in xrange(1,n+1):
        cur = abs(x-i) + i-1  + x -1
        ans += 2*cur*a[i-1]
    return ans
res = 10**18
for i  in xrange(1,n+1):
    res = min(res,get(i))
print res

n = int(input())
people = []
people_ = input()
people_ = people_.split(" ")
for p in people_:
    people.append(int(p))

sum =0
for each_floor in range(n):
    sum += people[each_floor]*4*each_floor

print(sum)

def ElctryctyUnts(no_of_people):
    min_units = 1000000000
    for i in range(len(no_of_people)):
        units = 0
        for j in range(len(no_of_people)):
            units += 2*no_of_people[j]*((abs(i-j))+(abs(j-0))+i)
        #print units
        if units < min_units:
            min_units = units

    return min_units

def main():
    n = int(raw_input())
    no_of_people = list(map(int,raw_input().split()))

    print ElctryctyUnts(no_of_people)

main()

n=int(input())
arr=[]
tmp=input().split()
for i in tmp:
	arr.append(int(i))
min=1000000000
for i in range(n):
	s=0
	for j in range(n):
		s+=((abs(i-j)+i+j)*2*arr[j])
	if(min>s):
		min=s
print(min)

inp=input()
inp2=map(int,raw_input().split())
best=100000000
for i in range(105):
    ans=0
    for j,x in enumerate(inp2):
        ans+=2*2*max(j,i)*x
    # best=min(best,ans)
    if best>ans:
        best=ans
        # print i,best
print best

"""
this is a standard python template for codeforces task, repo: github.com/solbiatialessandro/pyComPro/codeforces
"""
stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), raw_input().split(sep)))
joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)
def solve(A):
    res = 1e9
    for x in xrange(1, 101):
        _res = 0
        for i, num in enumerate(A):
            index = i + 1
            value = 2*(x-1 + index-1 + abs(x - index))
            _res += num * value
        res = min(res, _res)
        #print x, _res
    return res

if __name__ == "__main__":
    """the solve(*args) structure is needed for testing purporses"""
    n = stdin()
    A = stdin()
    print solve(A)

'''input
3
0 2 1
'''
import math
from fractions import gcd

ma=10**18
ind=-1
n=input()
arr=map(int,raw_input().split())
for j in range(n):
	su=0
	for i in range(n):
		a=abs(j-i)+i+j;
		a=2*a
		su+=(arr[i]*a)
	ma=min(ma,su)
print ma

import sys

def FairNut(peoples):
	mini=10**10
	for x in xrange(len(peoples)):
		unit_pp=0
		for i in xrange(len(peoples)):
			unit_pp+=(abs(i-x)+i+x)*peoples[i]
		mini=min(unit_pp,mini)
	return(mini)

n=int(raw_input())
l=map(int,raw_input().split())
print(FairNut(l)*2)

n=input()
l=map(int,raw_input().split(" "))
mn=1000000000000000
for i in range(n):
    x=i
    ans=0
    for i in range(n):
        ans+=2*l[i]*(i+x+abs(i-x))
        #print l[i]*(i+1+x+abs(i+1-x))
    mn=min(ans,mn)
print mn

def f(n,l):
    mi = 1000000000000000
    for k in range(1,101):
        su = 0
        for idx in range(n):
            i = idx + 1
            su += 2* l[idx] * (abs(k-i)+abs(i-1)+abs(k-1))
        mi = min(su, mi)
    return mi

if __name__ == '__main__':
    n = int(input())
    l = map(int, raw_input().rstrip().split())
    print f(n,l)

import sys
import operator

def main():
    n = int(sys.stdin.readline())
    arr = list(map(int, sys.stdin.readline().split()))
    arr = list(enumerate(arr))
    arr.sort(key=operator.itemgetter(1), reverse=True)
    # print(arr)
    check = arr[0][1]
    index = -1
    while index < n-1 and arr[index][1] == check:
        index += 1
    count = 0
    # print(index)
    # print(arr[index][0])
    for i in range(n):
        # if arr[i][0] <= arr[index][0]:
            #count += arr[i][1]*(2*(abs(arr[index][0]-arr[i][0]))+2*(arr[i][0]))
        # else:
        count += 2*(arr[i][1]*2*(arr[i][0]))
    print(count)

if __name__ == '__main__':
    main()

n = int(input())
array = list(map(int, input().split()))
ans = []
e = 0
for x in range(1, n + 1):
	e = 0
	for i in range(1, n + 1):
		difference = (x - 1) + (i - 1) + abs(i - x)
		e += 2 * difference * array[i - 1]
		##print(e)
	ans.append(e)
print(min(ans))

raw_input()
print sum(list(map(lambda (i, x): 4*i*x, list(enumerate(map(int, raw_input().split(' ')))))))

__author__ = 'tanunia'

from sys import stdin

n = int(stdin.readline())
a = [int(x) for x in stdin.readline().strip().split()]

x = 0
best_sum = 100005000
for i in xrange(n):
    cur_sum = 0
    for j in xrange(n):
        cur_sum += 2*a[j] * (abs(j) + abs(j - i) + abs(i))
    if cur_sum < best_sum:
        best_sum = cur_sum
        x = i

print best_sum

from sys import stdin, stdout

n = int(stdin.readline())
ary = list(map(int, stdin.readline().split()))
ans = 10**9
for x in range(1, n + 1):
    cur = 0
    for f in range(1, n + 1):
        cur = cur + 2 * ary[f - 1] * (abs(x - f) + abs(f - 1) + abs(x - 1))
    ans = min(ans, cur)
stdout.write("{}".format(ans))

n = int(input())
array = [int(x) for x in input().split()]
count = 0

for i in range(n):
    count = count + (4 * i * array[i])
print(count)

n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

sum = 0
for i in range(n):
    sum += 4 * arr[i] * i
print(sum)

def _mp():
	return map(int,raw_input().split())
n=input()
a=_mp()
x=1
mi=1000000000
for x in range(1,n+1):
	curr=0
	for i in range(1,n+1):
		curr+=a[i-1]*(2*abs(i-1)+abs(x-i)+abs(x-1)+abs(1-x)+abs(i-x))

	mi=min(mi,curr)

print mi

n = int(input())
a = [int(w) for w in input().split()]

print(4*sum(a[i]*i for i in range(n)))

n = int(input())
a = list(map(int,input().split()))
b = []
for x in range(1,n+1):
    count = 0
    for i in range(1,n+1):
        count += 2 *  a[i-1] * (abs(i-x)+x-2+i)
    b.append(count)
print(min(b))

#526_A

import sys
import math

floors = int(sys.stdin.readline().rstrip())

lne = [int(i) for i in sys.stdin.readline().rstrip().split(" ")]

mn = 10 ** 9

for i in range(0, floors):
    elec = 0
    for j in range(0, len(lne)):
        elec += (abs(i - j) + j + i) * 2 * lne[j]
    if elec < mn:
        mn = elec
print(mn)

n = int(input())

a = [int(x) for x in input().split()]

ind = a.index(max(a))+1
s = 0
for i in range(n):
  s += a[i]*i*4
print(s)

# -*- coding: utf-8 -*-
# @Date    : 2019-01-23 09:28:02
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

from sys import stdin

max_val=int(10e12)
min_val=int(-10e12)

def read_int()     : return int(stdin.readline())
def read_ints()    : return [int(x) for x in stdin.readline().split()]
def read_str()     : return input()
def read_strs()    : return [x for x in stdin.readline().split()]

nb_floors = int(input())
peoples   = read_ints()
print( 4 * (sum([i*v for i, v in enumerate(peoples)])))

n=(int(input()))
ar=[int(x) for x in input().split()]
ans=0
for k in range(n):
    ans+=4*ar[k]*k
print(ans)

n=int(input())
a=list(map(int,input().split()))
r=[]
for j in range(1,n+1):
    ans=0
    for i in range(1,n+1):
        ans+=(2*a[i-1]*(abs(j-i)+abs(i-1)+abs(1-j)))
    r.append(ans)

print(min(r))

n = int(input())
flours = list(map(int, input().split()))
best = 10000000
for x in range (n):
    sum = 0
    for i in range (n):
        if i <= x:
            sum += (x * 4) * flours[i]

        else:
            sum += (i * 4) * flours[i]
    if best > sum:
        best = sum

print(best)

k=int(input())
li=list(map(int,input().split()))
a=0
for i in range(k):
    a+=4*li[i]*i
print(a)

n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n):
    c+=i*l[i]*4
print(c)

import math
n = int(input())
a = list(map(int, input().strip().split()))

minim = 10000000000000
curr = 0

for opt_etage in range(len(a)):

    curr = 0
    for population in range(len(a)):

        if(population!=0):

            curr +=  a[population]*(abs(opt_etage-population) + abs(opt_etage) + abs(population)) * 2

    if(minim>curr):
        minim=curr

print(minim)

n=int(input())
a=list(map(int,input().split()))
ans=10**10
for i in range(n):
    el=0
    for j in range(n):
        if j>i:
            el+=a[j]*j*4
        else:
            el+=a[j]*i*4
    #print(el)
    if (ans > el):
        ans=el
print(ans)

n = int(input())
arr = list(map(int, input().split()))

ans = 0

for idx in range(n):
    ans += arr[idx] * idx * 4

print(ans)

n = int(input())
ans=0
a=list(map(int,input().split()))
for i,j in enumerate(a):
    ans+=i*j
print(ans*4)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
energy = []
for x in range(n):
    energy.append(0)
    for i, resident in enumerate(residents):
        energy[x] += (abs(x - i) + i + x) * 2 * resident
print(min(energy))

n = int(input())

a = list(map(int, input().split()))
a = [0] + a
# print(a)
maxi = -1
index = -1
for i in range(n):
    if a[i] > maxi:
        maxi = a[i]
        index = i

ans = 10**10
# print(index)
for x in range(1,n+1):
    cost = 0
    for i in range(1,n+1):
        if a[i] == 0:
            continue
        cost += a[i] * (abs(x - i) + i - 1 + x - 1)

    ans = min(ans, cost)
print(2*ans)

''' Thruth can only be found at one place - THE CODE '''

''' Copyright 2018, SATYAM KUMAR'''
from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27)  # new thread will get stack of such size

printHeap = str()
memory_constrained = False
P = 10**9+7
import sys
sys.setrecursionlimit(10000000)

class Operation:
    def __init__(self, name, function, function_on_equal, neutral_value=0):
        self.name = name
        self.f = function
        self.f_on_equal = function_on_equal
def add_multiple(x, count):
    return x * count
def min_multiple(x, count):
    return x
def max_multiple(x, count):
    return x
sum_operation = Operation("sum", sum, add_multiple, 0)
min_operation = Operation("min", min, min_multiple, 1e9)
max_operation = Operation("max", max, max_multiple, -1e9)
class SegmentTree:
    def __init__(self,
                 array,
                 operations=[sum_operation, min_operation, max_operation]):
        self.array = array
        if type(operations) != list:
            raise TypeError("operations must be a list")
        self.operations = {}
        for op in operations:
            self.operations[op.name] = op
        self.root = SegmentTreeNode(0, len(array) - 1, self)
    def query(self, start, end, operation_name):
        if self.operations.get(operation_name) == None:
            raise Exception("This operation is not available")
        return self.root._query(start, end, self.operations[operation_name])
    def summary(self):
        return self.root.values
    def update(self, position, value):
        self.root._update(position, value)
    def update_range(self, start, end, value):
        self.root._update_range(start, end, value)
    def __repr__(self):
        return self.root.__repr__()
class SegmentTreeNode:
    def __init__(self, start, end, segment_tree):
        self.range = (start, end)
        self.parent_tree = segment_tree
        self.range_value = None
        self.values = {}
        self.left = None
        self.right = None
        if start == end:
            self._sync()
            return
        self.left = SegmentTreeNode(start, start + (end - start) // 2,
                                    segment_tree)
        self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end,
                                     segment_tree)
        self._sync()
    def _query(self, start, end, operation):
        if end < self.range[0] or start > self.range[1]:
            return None
        if start <= self.range[0] and self.range[1] <= end:
            return self.values[operation.name]
        self._push()
        left_res = self.left._query(start, end,
                                    operation) if self.left else None
        right_res = self.right._query(start, end,
                                      operation) if self.right else None
        if left_res is None:
            return right_res
        if right_res is None:
            return left_res
        return operation.f([left_res, right_res])
    def _update(self, position, value):
        if position < self.range[0] or position > self.range[1]:
            return
        if position == self.range[0] and self.range[1] == position:
            self.parent_tree.array[position] = value
            self._sync()
            return
        self._push()
        self.left._update(position, value)
        self.right._update(position, value)
        self._sync()
    def _update_range(self, start, end, value):
        if end < self.range[0] or start > self.range[1]:
            return
        if start <= self.range[0] and self.range[1] <= end:
            self.range_value = value
            self._sync()
            return
        self._push()
        self.left._update_range(start, end, value)
        self.right._update_range(start, end, value)
        self._sync()
    def _sync(self):
        if self.range[0] == self.range[1]:
            for op in self.parent_tree.operations.values():
                current_value = self.parent_tree.array[self.range[0]]
                if self.range_value is not None:
                    current_value = self.range_value
                self.values[op.name] = op.f([current_value])
        else:
            for op in self.parent_tree.operations.values():
                result = op.f(
                    [self.left.values[op.name], self.right.values[op.name]])
                if self.range_value is not None:
                    bound_length = self.range[1] - self.range[0] + 1
                    result = op.f_on_equal(self.range_value, bound_length)
                self.values[op.name] = result
    def _push(self):
        if self.range_value is None:
            return
        if self.left:
            self.left.range_value = self.range_value
            self.right.range_value = self.range_value
            self.left._sync()
            self.right._sync()
            self.range_value = None
    def __repr__(self):
        ans = "({}, {}): {}\n".format(self.range[0], self.range[1],
                                      self.values)
        if self.left:
            ans += self.left.__repr__()
        if self.right:
            ans += self.right.__repr__()
        return ans

def display(string_to_print):
    stdout.write(str(string_to_print) + "\n")

def primeFactors(n): #n**0.5 complex
    factors = dict()
    for i in range(2,math.ceil(math.sqrt(n))+1):
        while n % i== 0:
            if i in factors:
                factors[i]+=1
            else: factors[i]=1
            n = n // i
    if n>2:
        factors[n]=1
    return (factors)

def isprime(n):
    """Returns True if n is prime."""
    if n < 4:
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True

def test_print(*args):
    if testingMode:
        print(args)

def display_list(list1, sep=" "):
    stdout.write(sep.join(map(str, list1)) + "\n")

def get_int():
    return int(stdin.readline().strip())

def get_tuple():
    return map(int, stdin.readline().split())

def get_list():
    return list(map(int, stdin.readline().split()))

memory = dict()
def clear_cache():
    global memory
    memory = dict()
def cached_fn(fn, *args):
    global memory
    if args in memory:
        return memory[args]
    else:
        result = fn(*args)
        memory[args] = result
        return result

# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
optimiseForReccursion = False #Can not be used clubbed with TestCases
def comp(li):
    return len(li)

def main():
    n=get_int()
    li = get_list()
    res = 0
    for i,ele in enumerate(li):
        res+=i*4*ele
    print(res)

# --------------------------------------------------------------------- END

if TestCases:
    for _ in range(get_int()):
        cProfile.run('main()') if testingMode else main()
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()

from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

if __name__=="__main__":
    n=intIn()
    a=listIn()
    minn=float('inf')

    for x in range(1,n+1):
        m=0
        j=1
        for i in range(1,n+1):
            s_floor=0
            s_floor=abs(i-j)+abs(i-x)+abs(j-x)
            s_floor*=2*a[i-1]
            #print(s_floor,i)
            m+=s_floor
        minn=min(m,minn)

    print(minn)

#_________________ Mukul Mohan Varshney _______________#

#Template
import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict
from itertools import permutations, combinations

#define function
def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())
def Lstr(): return list(sys.stdin.readline().strip())
def Str(): return sys.stdin.readline().strip()
def Mstr(): return map(str,sys.stdin.readline().strip().split())
def List(): return list(map(int,sys.stdin.readline().split()))
def Hash(): return dict()
def Mod(): return 1000000007
def Ncr(n,r,p): return ((fact[n])*((ifact[r]*ifact[n-r])%p))%p
def Most_frequent(list): return max(set(list), key = list.count)
def Mat2x2(n): return [List() for _ in range(n)]

def Prime_factors(n):
     i = 2
     factors = set()
     while i * i <= n:
          if n % i:
               i += 1
          else:
               n //= i
               factors.add(i)
     if n > 1:
          factors.add(n)
     print(factors)
     if len(factors)==2:
          return True
     else:
          return False

def Divisors(n) :
     l = []
     for i in range(1, int(math.sqrt(n) + 1)) :
          if (n % i == 0) :
               if (n // i == i) :
                    l.append(i)
               else :
                    l.append(i)
                    l.append(n//i)
     return l

def Sieve(n):
     prime=[True for i in range(n+1)]
     lst=[]
     p=2
     while p*p<=n:
          if prime[p]:
               for i in range(p*p,n+1,p):
                    prime[i]=False
          p=p+1
     for i in range(2,n+1):
          if prime[i]:
               lst.append(i)
     return lst

def minimum_integer_not_in_list(a):
     b=max(a)
     if(b<1):
          return 1

     A=set(a)
     B=set(range(1,b+1))
     D=B-A
     if len(D)==0:
          return b+1
     else:
          return min(D)

# Driver Code
def solution():
     n=Int()
     a=List()
     s=0
     for i in range(n):
          s+=4*i*a[i]
     print(s)

#Call the solve function
if __name__ == "__main__":
     solution()

n = int(input())
arr = list(map(int, input().split()))
base = 0
bigNumber = 0
electricity = 0
temp=0
for i in range(0, len(arr)):
    electricity += i*arr[i]*2*2
for i in range(1, len(arr)):
    base = i
    temp = 0
    for j in range(0, len(arr)):
        if base >= j:
            temp += ((base-j) + j + base)*2*arr[j]
        elif base < j:
            temp += ((j - base) + j + base) * 2 * arr[j]
    if temp < electricity:
        electricity = temp
print(electricity)

n = int(input())
l = list(map(int, input().split()))
x = 0

ans = 0
for i in range(n):
	ans += l[i]  * (i + abs(i - x) + x) * 2

print(ans)

Input=lambda:map(int,input().split())

n = int(input())

ans = 0
Min = float('inf')
List = list(Input())
x = List.index(max(List)) + 1

for i in range(1,n+1):
        if List[i-1] != 0:
                ans+= (i-1) * 4 * List[i-1]
print(ans)

n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
minE = 1000000000
for x in range(1,n+1):
	e = 0
	for f in range(1,n+1):
		e += (abs(x-f) + f-1 + x-1)*a[f-1]*2
	if e < minE:
		minE = e
print(minE)

n=int(input())
a=list(map(int,input().split()))
c=[]
for i in range(1,n+1):
	x=i
	ci=0
	for j in range(1,n+1):
		if j>x:
			ci+=4*(j-1)*a[j-1]
		if j<=x and not(j==1 and x==1):
			ci+=4*(x-1)*a[j-1]
		if j==1 and x==1:
			ci+=0

	c.append(ci)

print(min(c))

n=int(input())
a = list(map(int, input().split()))
tl=[]

def f(x,fl):
    return 2*(x+fl + abs(fl-x))
tl=[]
for x in range(n):
    t=0
    for fl in range(n):
        t += f(x,fl)*a[fl]
    tl.append(t)
print(min(tl))

n = int(input())

l = [0] + list(map(int,input().split()))
ans = 100000000000
for i in range(1,n+1):
    s=0
    for j in range(1,n+1):
        s += (abs(j-i)+ abs(i-1)+ abs(j-1))*l[j]
    ans = min(s,ans)
print(2*ans)

n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
	t=i+1
	sumi=0
	for j in range(1,n+1):
		sumi+=a[j-1]*(abs(t-j)+abs(j-1)+abs(t-1))
		sumi+=a[j-1]*(abs(t-1)+abs(1-j)+abs(j-t))
	b.append(sumi)
print(min(b))

import sys
n=int(input())
arr=[int(x) for x in input().split()]
ans=sys.maxsize
for x in range(1,n+1):
	t=0
	for j in range(1,n+1):
		t+=arr[j-1]*2*(abs(x-j)+abs(j-1)+abs(1-x))
	ans=min(ans,t)
print(ans)

def calc(a,x,n):
    sum = 0
    for i in range(1,n+1):
        sum+= 2*a[i-1]*(abs(i-1)+abs(x-1)+abs(i-x))
    return sum

n = int(input())
a = []
a = input()
a = list(map(int,a.split()))
temp = []
for i in range(1,n+1):
    temp.append(calc(a,i,n))
print(min(temp))

from sys import stdin

n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]

all_units = []

for x in range(1, n + 1):
    #print("Starting in floor number", x)
    units = 0

    for floor, p in enumerate(arr, start=1):
        #print("Going to floor", floor, "and no. of people =", p)
        units += (abs(1 - floor) + abs(floor - 1)) * 2 * p
        #print("Units of electricity consumed in total:", units)

    all_units.append(units)

    #print()

print(min(all_units))

input()

print(4 * sum(i*a for i,a in enumerate(map(int, input().split()))))

# alpha = "abcdefghijklmnopqrstuvwxyz"
t = 1#int(input())
for test in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 100000000

    for i in range(1,n+1):
        tmp = 0
        for j in range(1, n+1):
            tmp = tmp+(2*abs(j-i)+j-1+i-1+i-1+j-1)*a[j-1]

        if tmp<ans:
            ans = tmp

    print(ans)

# Author : raj1307 - Raj Singh
# Date   : 11.12.19

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[0]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    n=ii()
    l=li()

    p=inf

    for j in range(n):
        pos=j
        ans=0
        for i in range(n):
            ans+=l[i]*(2*abs(pos-i)+2*i+2*pos)
        p=min(p,ans)
        #print(l[i]*(2*(pos-i)+2*i+2*pos),2*(pos-i)+2*i+2*pos,pos)
    print(p)

    """
    s=list(si())

    cnt=0
    l=[]
    for i in range(len(s)):

        if s[i]=='b':
            l.append(cnt)
            cnt=0
        else:
            if s[i]=='a':
                cnt+=1

    l.append(cnt)

    ss=sum(l)

    ans=ss

    for i in range(len(l)):

        ans=(ans+((ss-l[i])*l[i])%mod)%mod
        ss-=l[i]

    print(ans)
    """

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()

n=int(input())
s=[]
f=list(map(int,input().split( )))
for x in range(1,n+1):
    p=0
    for a in range(1,n+1):
        p+=f[a-1]*(a+x-2+abs(a-x))*2
    s.append(p)
print(min(s))

import sys

n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(1, n + 1):
    ans += arr[i - 1] * 2 * (2 * i - 2)
print(ans)

from statistics import median
n = int(input())
a = [0] + list(map(int,input().split()))
ans = float('Inf')
for i in range(1,n+1):
    temp = 0
    for j in range(1,n+1):
        temp += ((i-1)*4*a[j]) if j <= i else (j-1)*4*a[j]
    ans = min(temp,ans)
print(ans)

n = int(input())
l = list(map(int,input().split()))
bill = float("inf")
for i in range(n):
	t = 0
	for j in range(n):
		t = t + l[j]*max(i,j)*4
	bill = min(t,bill)
print(bill)

n=int(input())
a=list(map(int,input().split(" ")))

from math import *
minn=100000000000000

for ck in range(0,n):

	tot=0
	for i in range(0,n):
		tota=0
		tota+=abs(i-ck)
		tota+=abs(i-0)
		tota+=abs(0-ck)
		tota+=abs(ck-0)
		tota+=abs(i-0)
		tota+=abs(i-ck)
		tota*=a[i]
		tot+=tota
	minn=min(minn,tot)
print(minn)

n = int(input())
a = list(map(int,input().split()))
ans = 100000000
for x in range(0,n):
    ret = 0
    for i in range(0,n):
        ret += a[i] * (abs(x-i) + i + x + x + i + abs(x-i))
    if ret < ans :
        ans = ret
print(ans)

import sys

def solve(io):
	N = io.read_int()
	A = io.read_int_array(N)

	best = 1234567890
	for x in range(0, N):
		score = calculate(x, A)
		best = min(best, score)
	io.println(best)

def calculate(x, A):
	cnt = 0
	for f in range(0, len(A)):
		cnt += 2 * A[f] * (abs(x - f) + f + x)
	return cnt

# +---------------------+
# | TEMPLATE CODE BELOW |
# |    DO NOT MODIFY    |
# +---------------------+

class IO:
	in_stream = None
	out_stream = None
	raw = ""
	buf = []
	pos = 0

	def __init__(self, input_stream, output_stream):
		self.in_stream = input_stream
		self.out_stream = output_stream

	def read_to_buffer(self):
		self.raw = self.in_stream.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def read_string(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def read_int(self):
		return int(self.read_string())

	def read_float(self):
		return float(self.read_string())

	def read_string_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_string())
		return arr

	def read_int_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_int())
		return arr

	def read_float_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_float())
		return arr

	def read_line(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		if self.pos > 0:
			raise ValueError("Cannot call read_line in the middle of a line.")
		self.pos = len(self.buf)
		return self.raw

	def print(self, s):
		self.out_stream.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def println_array(self, arr, sep = ' '):
		self.println(sep.join(str(x) for x in arr))

	def flush_output(self):
		self.out_stream.flush()

pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flush_output()

n = int(input())
arr = list(map(int,input().split()))
ans = -1

for x in range(0,len(arr)):
    now = 0
    for j in range(len(arr)):
        one = abs(x-j)+abs(j-0) + abs(0-x)
        total = 2*one*arr[j]
        now += total

    if ans ==-1:
        ans = now
    ans = min(ans,now)

print(ans)

import math

def min_energy(n, arr):
    min_energy = math.inf
    for x in range(n):
        cur_energy = 0
        for i in range(n):
            if i < x:
                cur_energy += arr[i] * (abs(x-i) + i + 3*x)
            elif i == x:
                cur_energy += arr[i] * 4 * x
            else:
                cur_energy += arr[i] * (2 * abs(x-i) + 2*i + 2 * x)
        min_energy = min(min_energy, cur_energy)
    return min_energy

if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().strip().split()))
    print(min_energy(n, arr))

n = int(input())
A = list(map(int, input().split()))

m = 10**9
for x in range(n):
    tmp = sum([ 2*A[i]*( abs(i-x) + x + i) for i in range(n)])
    m = min(m, tmp)
print(m)

n = int(raw_input())
number = list(map(int,raw_input().split()))
mini = 10000000000000000
ans = 1
k = 0
for i in xrange(1,n+1):
    for j in xrange(0,n):
            k += number[j]*(abs(j+1-i) + abs(j+1 - 1) + abs(1 - i))
    if mini > k:
        mini = k
        ans = i
print mini*2

n=input()
a=map(int,raw_input().split())
v=10**20
for x in range(n):
    t=0
    for i in range(n):
        t+=(abs(x-i)+i+x)*2*a[i]
    v=min(v,t)
print v

import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
inf=10**18
#sys.setrecursionlimit(10 ** 6 + 7)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().split())
from heapq import heappush, heappop, heapify
from collections import deque
from bisect import *

n=input()
arr=[0]+take()
ans=-1
check=inf
for i in range(1,n+1):
    now=0
    for j in range(1,n+1):
        u=arr[j]*(abs(i-j)+j-1+i-1+i-1+j-1+abs(i-j))
        #print i,j,u
        now+=u

    if now<check:
        check=now
        ans=i
print check

def inint():
    return int(raw_input())

def inints():
    return [int(x) for x in raw_input().split(' ')]

def ingrid(n):
    return [raw_input() for i in xrange(n)]

n = inint()
a = inints()

anss = []
for x in xrange(n):
    ans = 0
    for i, c in enumerate(a):
        ans += 2 * c * (abs(i - x) + abs(x - 0) + abs(i - 0))
    anss.append(ans)

print min(anss)

n, a = int(input()), list(map(int, input().split()))

print(min(sum(2 * a[i] * (abs(x - i) + i + x) for i in range(n)) for x in range(n)))

n = int(input())
l = list(map(int,input().split()))
mini = 10**18
for i in range(1,n+1):
    ans = 0
    cnt = 1
    for j in l:
        ans+=j*(abs(cnt-i) + abs(cnt-1) + abs(i-1) + abs(i-1) + abs(cnt-1) + abs(cnt-i))
        cnt+=1
    mini = min(mini,ans)

print(mini)

#!/usr/bin/python3
n = int(input())
a = list(map(int, input().split()))

def check(i):
    res = 0
    for k in range(n):
        res += 2 * a[k] * (i + k + abs(k - i))
    return res

m_v = n * (n + 1) + n * max(a) * 2 * n
for i in range(n):
    c_v = check(i)
    m_v = min(m_v, c_v)

print (m_v)

n=int(input())
l=list(map(int,input().split()))
minval=10**9
for i in range(n):
    ans=0
    for j in range(n):
        ans+=2*(abs(i-j)+abs(j+i))*(abs(l[j]))
    minval=min(ans,minval)
print(minval)

"""https://codeforces.com/contest/1084/problem/A"""
n = int(input())
a = list(map(int,input().split()))
x = 1
trips = 0
for i in range(1,n+1):
    trips += 2*a[i-1]*abs( abs(x-i) + abs(i-1) + abs(x-1) )
print(trips)

n = int(input())
array = list(map(int, input().split()))
x = array.index(max(array)) + 1
e = 0
for i in range(1, n + 1):
	e += array[i - 1] * 2 * (x + i - 2 + abs(i - x))
print(e)

def inint():
    return int(input())
def inlist():
    return list(map(int,input().split()))

def main():
    n=inint()
    a=inlist()
    sm=sum(a)#;sm1=0
    #for i in range(n):sm1+=i*a[i]
    #x=sm1//sm
    x=0
    for i in range(n):
        if a[i]>a[x]:x=i
    sol=0
    for i in range(n):
        sol+=a[i]*(abs(i-x)+i+x+abs(x-0)+abs(i-0)+abs(x-i))
        #print(abs(i-x)+i+x,abs(x-0)+abs(i-0)+abs(x-i),i,a[i])
    print(sol)

if __name__ == "__main__":
    #import profile
    #profile.run("main()")
    main()

#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))

x = a.index(max(a))

u = []
for f, k in enumerate(a):
  u.append(4 * k * (abs(x - f) + x))
print(sum(u))

n = int(input())
a = [i for i in list(map(int, input().split()))]
max = 0
sum = 0
for i in range(n):
	sum = 0
	for j in range(n):
		if j == i:
			sum += a[i] * (i) * 2
		else:
			sum += a[j] * (abs(j - i) * 2) + (i) * 2
	if sum > max:
		max = sum

print(max)

#codeforces _1084A
gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
pos = 1
ans = 1000000
v = 0
for j in range(1,n+1):
	ll = [(abs(pos-k)+abs(k-1)+abs(pos-1)+abs(pos-1)+abs(k-1)+abs(pos-k))*l[k-1] for k in range(1,n+1)]
	v = sum(ll)
	ans = min(ans,v)
	pos += 1
print(ans)

n = int(input())
arr = list(map(int, input().split()))
base = 0
bigNumber = 0
electricity = 0
temp=0
for i in range(0, len(arr)):
    electricity += (i+i+1)*arr[i]*2
for i in range(1, len(arr)):
    base = i
    temp = 0
    for j in range(0, len(arr)):
        if base >= j:
            temp += ((base-j)+(j+1))*2*arr[j]
        elif base < j:
            temp += ((j - base) + (j+ 1)) * 2 * arr[j]
    if temp < electricity:
        electricity = temp
print(electricity)

n = int(input())
a = [i for i in list(map(int, input().split()))]
max = 0
sum = 0
for i in range(1, n):
	sum = 0
	for j in range(1, n):
		if j == i:
			sum += a[i] * (i + 1) * 2
		else:
			sum += a[j] * (abs(j + 1 - i) * 2) + (i + 1) * 2
	if sum > max:
		max = sum

print(max)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents)) + 1
energy = 0

for resident in residents:
    energy += (abs(x - (residents.index(resident) + 1)) + (residents.index(resident) + 1)) * 2 * resident
print(energy)

import math
n = int(input())
a = list(map(int, input().strip().split()))

m = 10000000000000
su = 0

for j in range(1,len(a)):
    su = 0
    for i in range(1,len(a)+1):
        su += a[i-1]*(abs(j-i)+abs(i-1)+abs(j-1) + abs(j-1) + abs(i-1)+ abs(j-i))
    if(su < m):
        m = su

print(m)

n=int(input())
arr=[]
tmp=input().split()
for i in tmp:
	arr.append(int(i))
min=10000
for i in range(n):
	s=0
	for j in range(n):
		s+=((abs(i-j)+abs(j)+abs(i))*arr[j])
	if(min>s):
		min=s
print(2*min)

from sys import stdin
n = int(stdin.readline())
a =  map(int,stdin.readline().split())
def get(x):
    ans = 0
    for i in xrange(n):
        cur = abs(x-i) + i + abs(x-i)
        ans += 2*cur*a[i]
    return ans
res = 10**18
for i  in xrange(n):
    res = min(res,get(i))
print res

n=int(input())
l=[int(i) for i in input().strip().split()]
def solve(x):
    ans=0
    for i in range(n):
        ans=ans+(max(x,i))*l[i]*2*2
    return(ans)
fans=10*9
for i in range(n):
    tans=solve(i)
    if tans<fans:
        fans=tans
print(fans)

n = map(int, input())
m = list(map(int, input().split()))
index = m.index(max(m))
k = 0
for i in range(len(m)):
    if i != index:
        k += (abs(i-index)+i+index)*m[i]*2
    elif index != 0:
        k += index * 2 * 2 * m[i]
    else:
        k += 0
print(k)

def main():
    n = int(input())
    l = list(map(int, input().split()))
    x = n - l[::-1].index(max(l)) - 1

    c = 0

    for i in range(n):
        if i == x:
            c += l[i]*2*(x+1)
        else:
            c += l[i]*i*4

    print(c)

if __name__ == "__main__":
    main()

n = int(input())
lst = [int(x) for x in input().split()]
x = lst.index(max(lst))
s=0
for i in range(n):
        s+=(abs(x-i)+i+x)*lst[i]*2
        #print(s)
print(s)

n = int(input())
l = list(map(int,input().split()))

ans = 101

for i in range(n):
    s = 0
    for j in range(n):

        a = (abs(i-j) + j + i)*2*l[j]

        s += a

    ans = min(s,ans)

print(ans)

def flor(n,a):
    for i in range(n):
        if a[i] == 0:
            return a[0] *0
        elif len(a) == 2:
            return a[0]*0 + a[1] * 4
        else:
            return a[0]*0 + a[1] * 4 + a[2] * 8

n = int(input())
p = list(map(int, input().strip().split()))

x = p.index(max(p)) + 1
ans = 0

for i in range(1, len(p)):
    f = i + 1

    ans += p[i] * (abs(f-x)+abs(f-1)+abs(x-1)) * 2

print(ans)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents))
y = n//2
xe = 0
ye = 0
for i, resident in enumerate(residents):
    xe += (abs(x - i) + i + x) * 2 * resident
    ye += (abs(y - i) + i + y) * 2 * resident
print(min(xe,ye))

n = int(input())
array = list(map(int, input().split()))
x = array.index(max(array)) + 1
e = 0
for i in range(1, n + 1):
	e += array[i - 1] * 2 * (x + i - 2 + abs(i - x))
print(e)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents))
energy = 0
s = 0

for resident in residents:
    s = (abs(x - residents.index(resident)) + residents.index(resident) + x)
    if s == 0:
        s = 1
    energy += s * 2 * resident
print(energy)

def inint():
    return int(raw_input())

def inints():
    return [int(x) for x in raw_input().split(' ')]

def ingrid(n):
    return [raw_input() for i in xrange(n)]

n = inint()
a = inints()

if n == 1:
    print 0
else:
    arr = []
    for i, c in enumerate(a):
        if i == 0:
            continue
        arr += [c] * i

    x = arr[len(arr) / 2]

    ans = 0
    for i, c in enumerate(a):
        if i == 0:
            continue
        ans += (abs(i - x) + abs(0 - x) + abs(i - 0)) * c * 2

    print ans

#codeforces _1084A_live
gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
pos = 1
ans = 1000000000000
v = 0
for j in range(1,n+1):
	ll = [(abs(pos-k)+abs(k-1)+abs(pos-1)+abs(pos-1)+abs(k-1)+abs(pos-k))*l[k-1] for k in range(1,n+1)]
	print(ll)
	v = sum(ll)
	ans = min(ans,v)
	pos += 1
print(ans)

n=int(input())
l=list(map(int,input().split()))
x=l.index(max(l))
#print(x)
s=0
s+=4*l[0]*x
for i in range(1,n):
	#print(i,2*l[i]*(abs(i-x)+i+x))
	s+=2*l[i]*(abs(i-x)+i+x)

print(s)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents))
energy = 0
for i, resident in enumerate(residents):
    energy += (abs(x - i) + i + x) * 2 * resident
print(energy)

n=int(input())
arr=[]
tmp=input().split()
for i in tmp:
	arr.append(int(i))
min=10000
for i in range(n):
	s=0
	for j in range(n):
		s+=((abs(i-j)+i+j)*2*arr[j])
	if(min>s):
		min=s
print(min)

q = int(input())
w = list(map(int, input().split()))
r = []
for i in range(q):
    e = 0
    for j in range(q):
        e += (abs((i + 1) - (j + 1)) + j + 1) * w[j]
    r.append(e)
print(min(r))

n = int(input())
a = [int(i) for i in input().split()]
x = n // 2
sum = 0
for i in range(1, n):
    sum += a[i] * (abs(x - i) + i + x)
print(sum * 2)

n=int(input())
if n%2==0:
    mid=n//2;
else:
    mid=(n//2)+1;
cost=0
a=[]
a = [int(i) for i in input().split()]
for i in range(1,n):
    cost+=2*a[i]*(abs(mid-i-1)+abs(i)+abs(mid-1))
print(cost)

from sys import stdin
n = int(stdin.readline())
a =  map(int,stdin.readline().split())
def get(x):
    ans = 0
    for i in a:
        cur = abs(x-i) + i + abs(x-i)
        ans += 2*cur
    return ans
res = 10**18
for i  in xrange(n):
    res = min(res,get(i))
print res

n=int(input())
li=input().split()
c=0
j=0
for i in range(n):
    li[i]=int(li[i])
    if i==0:
        continue
    if li[i]>c:
        c=li[i]
        j=i+1
x=j
u=0
for i in range(n):
    if i==0:
        continue
    u1=(x-(i+1))*li[i]
    u2=(i)*li[i]
    if u1<0:
        u1*=-1
    u3=(x-1)*li[i]
    u=u+u1+u2+u3
print(u*2)

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents))
energy = 0

for resident in residents:
    energy += (abs(x - residents.index(resident)) + residents.index(resident) + x) * 2 * resident
print(energy)

import math
n = int(input())
a = list(map(int, input().strip().split()))

minim = 10000000000000
su = 0

for j in range(1,len(a)):
    su = 0
    for i in range(2,len(a)+1):
        su += a[i-1]*(abs(j-i-1)+abs(i-2)+abs(j-1))*2
    if(minim>su):
        minim = su

print(minim)

a=int(input())
s=list(map(int,input().split()))
m=0
for n in range(a):
    m+=4*(n+1)*s[n]
print(m)

a=int(input())
s=list(map(int,input().split()))
x=s.index(max(s))
m=0
for n in range(a):
    m+=(abs(x-n)+n+x+x+n+abs(x-n))*s[n]
print(m)

n=int(input())
li=input().split()
c=0
j=0
for i in range(n):
    li[i]=int(li[i])
    if i==0:
        continue
    if li[i]>=c:
        c=li[i]
        j=i+1
x=j
u=0
for i in range(n):
    if i==0:
        continue
    u1=(x-(i+1))*li[i]
    u2=(i)*li[i]
    if u1<0:
        u1*=-1
    u3=(x-1)*li[i]
    u=u+u1+u2+u3
print(u*2)

n = int(input())
A = list(map(int, input().split()))

m = 99999
for x in range(n):
    tmp = sum([ 2*A[i]*( abs(i-x) + x + i) for i in range(n)])
    m = min(m, tmp)
print(m)

a = int(input())
k = 0
l = list(map(int,input().split()))
for i in range(len(l)):
    if i > 0:
        k += (2**(i+1))*l[i]
print(k)

n = int(input())
A = list(map(int, input().split()))
num_ = A.index(max(A)) + 1
answer = 0
for k in range(n):
    y = 0
    y += abs(num_ - (k + 1)) * A[k]
    y += k * A[k]
    y += (num_ - 1) * A[k]
    y *= 2
    answer += y
print(answer)

n = int(input())
p = list(map(int, input().strip().split()))

x = p.index(max(p)) + 1
ans = 0

for i in range(1, len(p)):
    f = i + 1

    if f != x:
        ans += p[i] * (abs(f-x)+abs(f-1)+abs(x-1)) * 2
    else:
        ans += p[i] * f * 2

print(ans)

n = int(input())
p = list(map(int, input().strip().split()))

x = p.index(max(p)) + 1
ans = 0

for i in range(1, len(p)):
    if i+1 <= x:
        ans += 2 ** x * p[i]
    else:
        ans += 2 ** (i + 1) * p[i]

print(ans)

def inint():
    return int(input())
def inlist():
    return list(map(int,input().split()))

def main():
    n=inint()
    a=inlist()
    sm=sum(a);sm1=0
    for i in range(n):sm1+=i*a[i]
    x=sm1//sm
    x1=0
    for i in range(n):
        if a[i]>a[x1]:x1=i
    sol=0;sol2=0
    for i in range(n):
        sol+=a[i]*(abs(i-x)+i+x+abs(x-0)+abs(i-0)+abs(x-i))
        sol2+=a[i]*(abs(i-x1)+i+x1+abs(x1-0)+abs(i-0)+abs(x1-i))
        #print(abs(i-x)+i+x,abs(x-0)+abs(i-0)+abs(x-i),i,a[i])
    print(min(sol,sol2))

if __name__ == "__main__":
    #import profile
    #profile.run("main()")
    main()

n=int(input())
l=input().split()
l=list(map(int,l))

def sum1(g):
    if g==1:
        return 1
    else:
        return (g)*(g+1)/2
def fun():
    if len(l)==1:
        print(0)
        return
    else:
        z=0
        for i in range(1,len(l)):
            z=z+i*l[i]
        k=sum1(len(l)-1)
        x=int(z/k)
        ab=0

        f=(sum(l)-l[0])*x
        for i in range(1,len(l)):
            ab=ab+abs(i-x)

        print(2*z+2*ab+2*f)
fun()

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents))
energy = 0
for i, resident in enumerate(residents):
    energy += (abs(x - i) + i + x) * 2 * resident
print(energy)

n=int(input())
l=list(map(int,input().split()))
x=l.index(max(l))
#print(x)
s=0
s+=2*l[0]*x
for i in range(1,n):
	#print(i,2*l[i]*(abs(i-x)+i+x))
	s+=2*l[i]*(abs(i-x)+i+x)

print(s)

import sys
from math import ceil
if __name__ == "__main__":

    # single variables
    n = [int(val) for val in input().split()][0]

    # vectors
    a = [int(val) for val in input().split()]
    np = sum(a)

    c = [(ind+1)*val for ind, val in enumerate(a)]

    centroid = sum(c) / np
    X = [int(centroid), ceil(centroid)]
    best = float('inf')

    for x in X:
        summ = 0
        for ind, val in enumerate(a):
            summ += (abs(x - (ind+1)) + abs((ind+1) - 1) + abs(x - 1))*val

        best = min(best, summ)

    print(best*2)

n = int(input())
a = [i for i in list(map(int, input().split()))]
max = 0
sum = 0
for i in range(n):
	sum = 0
	for j in range(n):
		if j == i:
			sum += a[i] * (i) * 2
		else:
			sum += a[j] * (abs(j - i) * 2) + (i) * 2
	if sum > max:
		max = sum

print(max)

inp=input()
inp2=map(int,raw_input().split())
best=100000000
for i in range(105):
    ans=0
    for j,x in enumerate(inp2):
        ans+=2*2*max(j,i)*x
    # best=min(best,ans)
    if best>ans:
        best=ans
        print i,best
print best

def flor(n,a):
    for i in range(n):
        if a[i] == 0:
            return a[0] *0
        elif len(a) == 2:
            return a[0]*0 + a[1] * 4
        else:
            return a[0]*0 + a[1] * 4 + a[2] * 8

#!/usr/bin/env python3

""" 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.
"""

n = int(input())
a = list(map(int, input().split()))

x = a.index(max(a))

u = []
for k, f in enumerate(a):
  u.append(4 * k * (abs(x - f) + x))
print(sum(u))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 10 22:12:00 2018

@author: mach
"""

n = int(input())

h = list(map(int, input().strip().split()))
s = max(h)
d = h.index(s)
sums = 0
for i in range(n):
    if i <= d:

        sums+=4*d*h[i]
    else:
        sums += i *h[i]*4
print(sums)

def solve(n, arr):
    ans = 1000000

    for i in range(n):
        temp = 0
        for j in range(n):
            temp += (abs(j - i) + (j - 0) + i) * 2
            temp *= arr[j]
        ans = min(ans, temp)
    print(ans)

def main():
    n = int(input())
    arr = list(map(int, input().split()))

    solve(n, arr)

if __name__ == "__main__":
    main()

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = (n-1)//2
energy = 0
for i, resident in enumerate(residents):
    energy += (abs(x - i) + i + x) * 2 * resident
print(energy)

import sys
n=int(input())
arr=[int(x) for x in input().split()]
ans=sys.maxsize
for x in range(1,n+1):
	t=0
	for j in range(1,n+1):
		t+=2*(abs(x-j)+abs(j-1)+abs(1-x))
		t=t*arr[j-1]
	ans=min(ans,t)
print(ans)

n = int(input())
a = list(map(int, input().split(' ')))
mn = n * 2 * 200
for x in range(1, n + 1):
    sm = 0
    for i in range(1, n + 1):
        sm += a[i - 1] * (abs(x - i) + abs(i - 1) + abs(1 - x)) * 2
    mn = min(sm, mn)
print(mn)

import math
n = int(input())
a = list(map(int, input().strip().split()))

minim = 10000000000000
su = 0

for j in range(1,len(a)):
    su = 0
    for i in range(2,len(a)+1):
        su += a[i-1]*(abs(j-i)+abs(i-1)+abs(j-1))*2
    if(minim>su):
        minim = su

print(minim)

n = int(input())
a = [0] + [int(a) for a in list(input().strip().split())]
mn=9999999999999999
for f in range(2,n+1):
    sm=0
    for i in range(2,n+1):
        sm += (abs(f-i) + f-1 + i-1) * a[i]
        #print(f,i,sm)
    mn=min(mn,sm)

print(mn * 2)

import sys
import operator

def main():
    n = int(sys.stdin.readline())
    arr = list(map(int, sys.stdin.readline().split()))
    arr = list(enumerate(arr))
    arr.sort(key=operator.itemgetter(1), reverse=True)
    # print(arr)
    check = arr[0][1]
    index = -1
    while index < n-1 and arr[index][1] == check:
        index += 1
    count = 0
    # print(index)
    # print(arr[index][0])
    for i in range(n):
        count += arr[i][1]*(2*(abs(arr[index][0]-arr[i][0]))+2*(arr[i][0]))
    print(count)

if __name__ == '__main__':
    main()

t=int(input())
b=list(map(int,input().split()))
x=(b.index(max(b)))
a=[i for i in range(t)]
c=list(zip(a,b))

d=0
g=0
for i in c:
    if i[1]>0:
        d=((abs(i[0]-x)*2)+abs(i[0]-a[0])+(abs(a[0]-x)*2)+abs(a[0]-i[0]))*i[1]
        g+=d
    else:
        continue
print(g)

from sys import stdin
n = int(stdin.readline())
a =  map(int,stdin.readline().split())
def get(x):
    ans = 0
    for i in a:
        cur = abs(x-i) + i + abs(x-i)
        ans += 2*cur
    return ans
res = 10**18
for i  in xrange(n):
    res = min(res,get(i))
print res

n = int(input())
numOfPeople = list(map(int, input().split(' ')))
counter = 0

while n > 1:
	counter = counter + numOfPeople[n-1]*((2*n)- 2)
	n = n - 1

print(counter)

inp=input()
inp2=map(int,raw_input().split())
best=1000000
for i in range(100):
    ans=0
    for j,x in enumerate(inp2):
        ans+=2*2*j*x
    best=min(best,ans)
print best

n = int(input())
nums = input().split()
residents = [int(item) for item in nums]
x = residents.index(max(residents)) + 1
energy = 0

for resident in residents:
    energy += (abs(x - residents.index(resident)) + residents.index(resident) + x + residents.index(resident)) * resident
print(energy)

def main():
    n = int(input())
    l = list(map(int, input().split()))
    x = n - l[::-1].index(max(l)) - 1

    c = 0

    for i in range(n):
        if i == x:
            c += l[i]*2*(x+1)
        else:
            c += l[i]*i*2

    print(c)

if __name__ == "__main__":
    main()

n=int(input())
l=[int(i) for i in input().strip().split()]
def solve(x):
    ans=0
    for i in range(n):
        ans=ans+(max(x,i))*l[i]*2*2
    return(ans)
fans=10**9
for i in range(n):
    tans=solve(i)
    print(i,tans)
    fans=min(fans,tans)
print(fans)

n = int(input())
l = list(map(int,input().split()))
bill = float("inf")
for i in range(n):
	t = 0
	for j in range(n):
		t = t +(j)*l[j]*4 + (abs(j-i)+abs(i))-1
	bill = min(t,bill)
print(bill)

n = int(input())
a = [int(i) for i in input().split()]
ans_min = 1000000
for x in range(n):
    ans = 0
    for i in range(n):
       ans += (abs(i - x) + i + x) * 2 * a[i]
    ans_min = min(ans, ans_min)
print(ans_min)

num_floor=input('')
num_floor=int(num_floor)
floor_count=input('')
floor_count_list=floor_count.split(' ')
floor_count_list=[int(x) for x in floor_count_list]
floor=0
max_ppl=floor_count_list.index(max(floor_count_list))+1
result=0
electricty_count=0
for numppl in floor_count_list:
    floor+=1
    if numppl!=0:

        floor_drive=abs(floor-max_ppl)
        floor_drive+=abs(max_ppl-1)
        floor_drive=floor_drive*2
        electricty_count+=numppl*(floor_drive+(2*(floor-1)))

print(electricty_count)

n=int(input())
l=list(map(int,input().split()))
x=l.index(max(l))
print(x)
s=0
s+=2*l[0]*x
for i in range(1,n):
	print(i,2*l[i]*(abs(i-x)+i+x))
	s+=2*l[i]*(abs(i-x)+i+x)

print(s)

x=int(input())
l=[0]+list(map(int,input().split()))
level=l.index(max(l))
counter=0
for i in range(2,x+1):
    counter+=abs(level-i)*2*l[i]
    counter+=+abs(level-1)*2*l[i]
    counter+=(i-1)*l[i]*2
print(counter)

# 1084 A

import os
import math
f = input()
x = math.ceil(float(f)/2.0)
p = []
sum = 0.0
one_way = 0
ptemp = raw_input()
ptemp = ptemp.split(" ")
for j in ptemp:
    p.append(int(j))
for i in range(1,f+1):
    if(p[i-1]!=0):
        one_way = one_way + p[i-1]*((abs(x-i))+(i-1)+(x-1))
print(int(one_way*2))

n = int(input())
flours = list(map(int, input().split()))
best = 1000000
for x in range (n):
    sum = 0
    for i in range (n):
        if i <= x:
            sum += (x * 4) * flours[i]

        else:
            sum += (i * 4) * flours[i]
    if best > sum:
        best = sum

print(best)

#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))

x = a.index(max(a))

u = []
for f, k in enumerate(a):
  u.append(4 * k * (abs(x - f) + x))
print(sum(u))

n = int(input())
l = list(map(int, input().split()))

x = l.index(max(l))

ans = 0
for i in range(n):
	ans += l[i]  * (i + abs(i - x) + x) * 2

print(ans)

import sys
n=int(input())
arr=[int(x) for x in input().split()]
ans=sys.maxsize
for x in range(1,n+1):
	t=0
	for j in range(1,n+1):
		t+=2*(abs(x-j)+abs(j-1)+abs(1-x))
		t=t*arr[j-1]
	ans=min(ans,t)
print(ans)

n = int(input())
a = [0] + [int(a) for a in list(input().strip().split())]
mn=9999999999999999
for f in range(2,n+1):
    sm=0
    for i in range(2,n+1):
        sm += (abs(f-i) + f-1 + i-1) * a[i]
        #print(f,i,sm)
    mn=min(mn,sm)

print(mn * 2)

import math
n = int(input())
a = list(map(int, input().strip().split()))

m = 10000000000000
su = 0

for j in range(1,len(a)):
    su = 0
    for i in range(1,len(a)+1):
        su += a[i-1]*(abs(j-i)+abs(i-1)+abs(j-1))
    if(su < m):
        m = su

print(2*su)

def calc(a,x):
    sum = 0
    for values in a:
        sum+= abs(values-1)+abs(x-1)+abs(values-x)
    return sum

n = int(input())
a = []
a = input()
a = list(map(int,a.split()))
temp = []
for i in range(1,n+1):
    temp.append(calc(a,i))
print(min(temp))

n = input()
cc = input().split(" ")
sum =0
for i in range(len(cc)):
    sum = sum + (int(cc[i-1]) *((i)*4))
print(sum)