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 \leq n \leq 100$) — the number of floors.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 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 \cdot 2 + 8 \cdot 1 = 16$.

In the second example, the answer can be achieved by choosing the first floor as the $x$-th floor.

Difficulty: EASY

Solutions:
def e(x):
	s = 0
	for i in range(1, n + 1):
		s = s + 2 * a[i] * (abs(i - x) + abs(i - 1) + abs(x - 1))
	return s
n = int(input())
a = [0]
b = list(map(int, input().split()))
a.extend(b)
mn = 10000000000000
for x in range(1, n + 1):
	p = e(x)
	if p < mn:
		mn = p
print(mn)


n = int(input())
a = list(map(int, input().split()))
ma = 10 ** 12
ind = -1
for i in range(101):
	ans = 0
	for j in range(1, n + 1):
		ans += a[j - 1] * (abs(j - i) + abs(j - 1) + abs(i - 1)) * 2
	if ans < ma:
		ma = ans
print(ma)


def orehus(lst):
	best = 1000000000
	for i in range(len(lst)):
		count = 0
		for j in range(len(lst)):
			p = i + j + abs(i - j)
			count += 2 * p * lst[j]
		best = min(best, count)
	return best
n = int(input())
a = [int(x) for x in input().split()]
print(orehus(a))


import sys
input = sys.stdin.readline
n = int(input())
(Arr, Ans) = (list(map(int, input().split())), 0)
for i in range(1, n):
	Ans += i * 4 * Arr[i]
print(Ans)


n = int(input())
a = list(map(int, input().split()))
max_num = max(a)
x = 0
energy = 0
for i in range(len(a)):
	energy += (x + i + abs(x - i)) * a[i]
	energy += (abs(i - x) + i + x) * a[i]
print(energy)


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())
a = list(map(int, input().split()))
su = 0
for i in range(len(a)):
	su += a[i] * i
print(su * 4)


n = int(input())
A = list(map(int, input().split()))
ans = 10 ** 18
for i in range(n):
	x = i + 1
	temp = 0
	for j in range(n):
		k = j + 1
		temp += (abs(k - x) + abs(k - 1) + abs(x - 1)) * A[j]
		temp += (abs(1 - x) + abs(1 - k) + abs(k - x)) * A[j]
		y = abs(k - x) + abs(x - 1) + abs(x - 1) + abs(1 - x) + abs(1 - k) + abs(k - x)
	ans = min(ans, temp)
print(ans)


import math
n = int(input())
people = list(map(int, input().split()))
l = []
for f in range(1, n + 1):
	e = 0
	for (floor, p) in enumerate(people):
		e += (math.fabs(f - (floor + 1)) + floor + f + 1 - 2) * 2 * p
	l.append(e)
print(int(min(l)))


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()))

def f(x):
	sum = 0
	for i in range(0, n):
		sum += 4 * a[i] * max(i, x)
	return sum
min = f(0)
for i in range(1, n):
	temp = f(i)
	if temp < min:
		min = temp
print(min)


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


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


n = int(input())
a = [int(i) for i in input().split()]
M = 100000000
for index in range(n):
	k = 0
	for i in range(n):
		k += a[i] * (abs(i - index) + i + index)
	if 2 * k < M:
		M = 2 * k
print(M)


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)


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

def cost(x):
	res = 0
	for (i, a) in enumerate(A):
		res += (abs(x - i) + abs(i - 0) + abs(x - 0)) * a
		res += (abs(x - 0) + abs(0 - i) + abs(i - x)) * a
	return res
print(min((cost(x) for x in range(len(A)))))


n = int(int(input()))
a = [int(i) for i in input().split()]
min_ = 100000000
for x in range(n):
	sum_ = 0
	for i in range(n):
		sum_ += (abs(x - i) + i + x) * 2 * a[i]
	if sum_ < min_:
		min_ = sum_
print(min_)


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


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))


n = int(input())
a = list(map(int, input().split()))
l = []
for x in range(1, n + 1):
	sum = 0
	for i in range(n):
		sum = sum + a[i] * 2 * (abs(i + 1 - x) + x - 1 + i)
	l.append(sum)
minr = l[0]
for i in l:
	k = i
	if k < minr:
		minr = k
print(minr)


n = int(input())
a = list(map(int, input().split()))
Minimum_Energy_Unit = None
for i in range(n):
	Energy_Units = None
	for j in range(n):
		x = i + 1
		currunt_floor = j + 1
		if Energy_Units == None:
			Energy_Units = a[j] * (abs(currunt_floor - x) + abs(currunt_floor - 1) + abs(1 - x))
		else:
			Energy_Units += a[j] * (abs(currunt_floor - x) + abs(currunt_floor - 1) + abs(1 - x))
	if Minimum_Energy_Unit == None:
		Minimum_Energy_Unit = Energy_Units
	else:
		Minimum_Energy_Unit = min(Minimum_Energy_Unit, Energy_Units)
print(2 * Minimum_Energy_Unit)


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)


floor = int(input())
nut = input().split()
nut = list(map(int, nut))
count = []

def FindMin(list):
	min = list[0]
	for i in range(0, len(list)):
		if list[i] < min:
			min = list[i]
	return min
for x in range(0, floor):
	power = 0
	for p in range(0, floor):
		power += (abs(p - x) + abs(p) + abs(x)) * nut[p] * 2
	count.append(power)
minPower = FindMin(count)
print(minPower)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	a = lst()
	ans = 0
	for i in range(n):
		ans += a[i] * (4 * i)
	print(ans)


n = int(input())
a = [int(j) for j in input().split()]
r = 4
summ = 0
for i in range(1, len(a)):
	summ += r * a[i]
	r += 4
print(summ)


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

def cost(x):
	total = 0
	for (i, people) in enumerate(a):
		total += people * 2 * (abs(x - i) + i + x)
	return total
min_cost = min([cost(x) for x in range(n)])
print(min_cost)


e = enumerate
n = int(input())
a = [*map(int, input().split())]
s = sum(a)
print(2 * (sum((i * k for (i, k) in e(a))) + min((s * x + sum((k * abs(x - i) for (i, k) in e(a))) for x in range(n)))))


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

def fun():
	if len(l) == 1:
		print(0)
		return
	else:
		z = 0
		ab = 0
		x = 1
		for i in range(1, len(l)):
			z = z + i * l[i]
			ab = ab + abs((i - x) * l[i])
		f = sum(l) - l[0]
		print(2 * z + 2 * ab + 2 * f)
fun()


a = eval(input())
b = list(map(int, input().split()))
i = 0
sum = 0
while i < len(b):
	sum += b[i] * i * 4
	i += 1
print(sum)


n = int(input())
p = input().split()
for i in range(n):
	p[i] = int(p[i])
minElec = 1000000000000
for x in range(n):
	elec = 0
	for i in range(n):
		if x > i:
			elec += 4 * p[i] * x
		else:
			elec += 4 * p[i] * i
	if elec < minElec:
		minElec = elec
print(minElec)


n = int(input())
arr = [int(x) for x in input().split()]
ans = pow(10, 18)
for x in range(n):
	unit = 0
	for i in range(n):
		unit += 2 * abs(i - x) * arr[i]
		unit += 2 * x * arr[i]
		unit += 2 * i * arr[i]
	if unit < ans:
		ans = unit
print(ans)


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


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	tmp = 0
	for j in range(n):
		tmp += 2 * a[j] * (abs(i - j) + j + i)
	if not i:
		ans = tmp
	elif tmp < ans:
		ans = tmp
print(ans)


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


n = int(input())
a = [int(el) for el in input().split()]
z = 99999999999
for i in range(n):
	mm = 0
	for j in range(n):
		mm += abs(i - j) * a[j] + a[j] * j + i * a[j]
		mm += i * a[j] + j * a[j] + abs(i - j) * a[j]
	z = min(mm, z)
print(z)


N = int(input())
aN = list(map(int, input().split()))
ans = float('inf')
for i in range(N):
	total = 0
	for j in range(N):
		elec = (i + j + abs(i - j)) * 2
		total += aN[j] * elec
	ans = min(total, ans)
print(ans)


floor = int(input())
ppl = list(map(int, input().split()))
ans = 0
for i in range(1, floor):
	ans += 4 * ppl[i] * i
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
n = int(input())
arr = list(map(int, input().strip().split()))
print(min_energy(n, arr))


n = int(input())
floors = list(map(int, input().strip().split()))
import math
mino = 10000000000.0
for (index, elem) in enumerate(floors):
	res = index * elem * 2
	for (ind, ele) in enumerate(floors):
		if index != ind:
			res += (abs(index - ind) + index) * ele * 2
	if mino > res:
		mino = res
print(mino * 2)


from sys import stdin
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
mn = float('inf')
for i in range(1, n + 1):
	result = 0
	for j in range(1, n + 1):
		result += (abs(i - j) + abs(j - 1) + abs(i - 1)) * 2 * arr[j - 1]
	mn = min(mn, result)
print(mn)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
n = get_int()
lst = get_int_list()
res = [0] * n
for x in range(n):
	for floor in range(n):
		res[x] += 2 * lst[floor] * (abs(floor - x) + floor + abs(x))
print(min(res))


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):
		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]
	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(final)


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)


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


n = int(input())
cl = list(map(int, input().split()))
mn = 10 ** 9
for i in range(1, n + 1):
	t = sum(cl[:i]) * (i - 1) * 4
	for j in range(i + 1, n + 1):
		t += 4 * cl[j - 1] * (j - 1)
	if t < mn:
		mn = t
print(mn)


n = int(input())
lis = list(map(int, input().split()))
lis.insert(0, 0)
m = 7 + 10 ** 9
for i in range(1, n + 1):
	c = 0
	for j in range(1, n + 1):
		x = abs(i - j)
		x += abs(j - 1)
		x += abs(i - 1)
		x *= 2
		c += x * lis[j]
	m = min(m, c)
print(m)


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())
arr = [int(x) for x in input().split()]

def get_for(x):
	global n, arr
	ret = 0
	for i in range(n):
		ret += (abs(x - i) + i + x) * arr[i] * 2
	return ret
mn = get_for(0)
for i in range(1, n):
	mn = min(mn, get_for(i))
print(mn)


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())
a = list(map(int, input().split()))
ans = []
for x in range(1, n + 1):
	s = 0
	for ai in range(n):
		s += (abs(ai + 1 - x) + ai + x - 1) * 2 * a[ai]
	ans.append(s)
print(min(ans))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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)]))


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)):
		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()))
minn = 10000000
for i in range(n):
	summ = 0
	for j in range(n):
		summ += a[j] * 2 * (abs(j) + abs(j - i) + abs(i))
	if summ < minn:
		minn = summ
print(minn)


(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())
a = [int(x) for x in input().split()]
min_len = 1000000000
for x in range(n):
	cur = 0
	for j in range(len(a)):
		cur += a[j] * (abs(x + 1 - j - 1) * 2 + abs(1 - j - 1) * 2 + abs(x + 1 - 1) * 2)
	if cur < min_len:
		min_len = cur
print(min_len)


t = int(input())
l = list(map(int, input().split()))
mi = float('Inf')
for i in range(t):
	x = 0
	for j in range(t):
		x += (abs(i - j) * l[j] + j * l[j] + i * l[j]) * 2
	if x < mi:
		mi = x
print(mi)


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())
L = [int(i) for i in input().split()]
s = 0
for i in range(len(L)):
	s = s + L[i] * i * 4
print(s)


def eCost(x, people):
	cost = 0
	for p in range(len(people)):
		tCost = (abs(x - p) + p + x) * 2
		cost += tCost * people[p]
	return cost
n = int(input())
people = list(map(int, input().split()))
minC = -1
for p in range(len(people)):
	if minC == -1:
		minC = eCost(p, people)
	else:
		minC = min(minC, eCost(p, people))
print(minC)


n = int(input())
A = list(map(int, input().split()))
answer = 0
lol = 10 ** 9
for i in range(n):
	num_ = i + 1
	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
	if answer < lol:
		lol = answer
print(lol)


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


_ = input()
people_floors = list(map(int, input().split()))
cost = 0
for (index, people) in enumerate(people_floors):
	cost += 4 * people * index
print(cost)


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)


(n, a) = (int(input()), list(map(int, input().split())))
print(min([sum([a[j - 1] * 2 * (abs(j - i) + (j - 1) + (i - 1)) for j in range(1, n + 1)]) for i in range(1, n + 1)]))


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


n = int(input())
a = list(map(int, input().split()))
m = float('inf')
for x in range(n):
	e = 0
	for f in range(n):
		e += a[f] * (abs(x - f) + f + x) * 2
	m = min(e, m)
print(m)


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())
a = list(map(int, input().split()))
num = float('inf')
for i in range(1, n + 1):
	tmp = 0
	for j in range(1, n + 1):
		tmp += 2 * (abs(i - j) + j - 1 + i - 1) * a[j - 1]
	num = min(num, tmp)
print(num)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	n = int(stdin.readline())
	a = [0] + [int(x) for x in stdin.readline().split()]
	res = 1
	minc = 99999999999999999999999999999
	for x in range(1, n + 1):
		c = 0
		for i in range(1, n + 1):
			c = c + a[i] * (abs(i - x) + abs(i - 1) + abs(1 - x) + abs(x - 1) + abs(1 - i) + abs(i - x))
		if c < minc:
			res = x
			minc = c
	stdout.write(str(minc))
	return 0

def __starting_point():
	main()
__starting_point()


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
n = int(input())
l = list(map(int, input().split()))
m = float('infinity')
for i in range(n):
	count = 0
	for j in range(n):
		count += 2 * l[j] * (abs(i - j) + abs(j) + abs(i))
	m = min(m, count)
print(m)


import sys
n = int(sys.stdin.readline().strip())
a = sys.stdin.readline().strip().split()
result = 0
for i in range(0, n):
	result = result + 4 * i * int(a[i])
print(result)


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


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


minEnergy = 10 ** 50
n = int(input())
g = list(map(int, input().split()))
for x in range(1, n + 1):
	sum = 0
	for i in range(len(g)):
		et = i + 1
		count = g[i]
		sum += (abs(x - et) + abs(et - 1) + abs(x - 1)) * 2 * count
	minEnergy = min(minEnergy, sum)
print(minEnergy)


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):
	units = 0
	for (floor, p) in enumerate(arr, start=1):
		units += (abs(1 - floor) + abs(floor - 1)) * 2 * p
	all_units.append(units)
print(min(all_units))


def cost(n, arr, x):
	tot = 0
	for i in range(n):
		tot += (abs(x - i) + i + x) * arr[i]
	return tot * 2

def prog():
	n = int(input())
	arr = [int(x) for x in input().split()]
	currcost = 10 ** 18
	for i in range(n):
		currcost = min(currcost, cost(n, arr, i))
	return currcost
print(prog())


n = int(input())
arr = list(map(int, input().split()))
ans = 0
min1 = 99999999999999
for i in range(n):
	maxin = i
	for i in range(n):
		ans += arr[i] * 2 * abs(abs(i - maxin) + abs(i) + abs(maxin))
	min1 = min(min1, ans)
print(min1)


n = int(input())
mini = 1000000000000000
l = [int(i) for i in input().split()]
for i in range(1, n + 1):
	curr = i
	s = 0
	for j in range(n):
		csm = 0
		csm += abs(curr - (j + 1))
		csm += abs(j + 1 - 1)
		csm += abs(curr - 1)
		s += csm * l[j]
	if s < mini:
		mini = s
		ans = curr
print(mini * 2)


n = int(input())
a = [int(x) for x in input().split()]
j = 0
units = 0
for i in a:
	units += i * j
	j += 2
print(2 * units)


n = 3
n = int(input())
astr = '0 2 1'.strip().split(' ')
astr = input().strip().split(' ')
min_cnt = None
for x in range(n):
	total = 0
	for y in range(len(astr)):
		p = int(astr[y])
		if x == y:
			total += p * (4 * x)
		else:
			total += p * (abs(x - y) + y + x + x + y + abs(x - y))
	if min_cnt == None or total < min_cnt:
		min_cnt = total
print(min_cnt)


from sys import stdin
n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
units = 0
for (floor, p) in enumerate(arr, start=1):
	units += (abs(1 - floor) + abs(floor - 1)) * 2 * p
print(units)


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

def count(n, people):
	min_floor = 0
	min_count = None
	for x in range(1, n + 1):
		count = calculate_total(people, x)
		if not min_count or count < min_count:
			min_count = count
			min_floor = x
		else:
			break
	return min_count

def calculate_total(people, x):
	count = 0
	for (i, p) in enumerate(people):
		floor = i + 1
		count += p * 2 * (x + floor - 2 + abs(floor - x))
	return count
print(count(n, people))


n = int(input())
L = [int(x) for x in input().split()]
s = 10 ** 10
for i in range(1, n + 1):
	temp = 0
	for j in range(1, n + 1):
		temp += (2 * i + 2 * j - 4 + 2 * abs(i - j)) * L[j - 1]
	if temp < s:
		s = temp
print(s)


n = int(input())
a = list(map(int, input().split()))
ans = 1e+18
for i in range(n):
	cnt = 0
	for j in range(n):
		x = 2 * (abs(i - j) + j + i)
		cnt += a[j] * x
	ans = min(ans, cnt)
print(ans)


n = int(input())
k = list(map(int, input().split()))
x = []
i = 0
while i < n:
	j = 0
	y = 0
	while j < n:
		y += (abs(j - i) + j + i) * 2 * k[j]
		j += 1
	x += [y]
	i += 1
print(min(x))


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


n = int(input())
a = list(map(int, input().split()))
ANS = float('inf')
for i in range(n):
	ans = 0
	for j in range(n):
		ans += a[j] * (abs(i - j) + j + i)
	if ans < ANS:
		ANS = ans
print(2 * ANS)


n = int(input())
l = list(map(int, input().split()))
miny = 4294967296
for i in range(n):
	units = 0
	for j in range(n):
		units += (abs(i - j) + j + i) * 2 * l[j]
	if units < miny:
		miny = units
print(miny)


n = int(input())
a = [int(x) for x in input().split()]
(cost, ans) = (0, 9999999)
for i in range(n):
	for j in range(n):
		cost += a[j] * (2 * abs(i - j) + 2 * (j + i))
	if cost < ans:
		ans = cost
print(ans)


n = int(input())
ar = list(map(int, input().split()))
mn = float('inf')
for x in range(n):
	cur = 0
	for y in range(0, n):
		cur += ar[y] * (abs(x - y) * 4 + abs(x) * 4)
	mn = min(cur, mn)
print(mn)


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)


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


n = int(input())
p = list(map(int, input().split()))
ans = 10 ** 19
for f in range(100):
	cur = 0
	for (i, pi) in enumerate(p):
		cur += (abs(f - i) + f + i) * 2 * pi
	ans = min(ans, cur)
print(ans)


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
ans = float('inf')
for i in range(n):
	cnt = 0
	for j in range(n):
		cnt += values[j] * (abs(i - j) + j + i + (i + j + abs(j - i)))
	ans = min(ans, cnt)
stdout.write(str(ans))


n = int(input())
arr = [int(x) for x in input().split(' ')]
ans = 999999999
for x in range(1, n + 1):
	temp = 0
	for a in range(1, n + 1):
		each = a - 1 + (a - x) + (x - 1)
		temp += each * arr[a - 1]
	ans = min(ans, temp)
print(ans * 2)


n = int(input())
a = [int(x) for x in input().split()]
energy = 0
min_energy = 100000000000000
for i in range(1, n + 1):
	k = 1
	for item in a:
		energy += 4 * (max(i, k) - 1) * item
		k += 1
	if energy < min_energy:
		min_energy = energy
print(min_energy)


n = int(input())
a = list(map(int, input().split()))
p = 100000000000000
ans = -1
for i in range(1, n + 1):
	t = 0
	for j in range(n):
		t += a[j] * abs(j + 1 - i)
		t += a[j] * j
		t += a[j] * (i - 1)
		t += a[j] * (i - 1)
		t += a[j] * abs(j)
		t += a[j] * abs(j + 1 - i)
	if t < p:
		p = t
print(p)


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


def foo(a):
	outs = []
	for i in range(n):
		temp = 0
		for j in range(n):
			temp += 2 * a[j] * (abs(i - j) + j + i)
		outs.append(temp)
	print(min(outs))
n = int(input())
a = list(map(int, input().strip().split(' ')))
foo(a)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	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 get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def datainput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
n = int(input())
a = listinput()
mn = 10000000000
for i in range(n):
	totalcost = 0
	for j in range(n):
		cost = a[j] * (abs(j - i) + j + i + i + j + abs(j - i))
		totalcost += cost
	if totalcost < mn:
		mn = totalcost
print(mn)


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


from sys import stdin, stdout

def sum_list(arr):
	cnt = 0
	for num in arr:
		cnt += num
	return cnt
n = int(stdin.readline())
arr = [int(x) for x in input().split()]
sum = sum_list(arr)
b = 0
for i in range(1, n):
	b += 2 * i * arr[i]
b = 2 * b
for x in range(2, n + 1):
	c = sum * 2 * (x - 1)
	for k in range(1, n + 1 - x):
		c += 2 * k * arr[x + k - 1]
	c = 2 * c
	if c < b:
		b = c
print(b)


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

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())
s = list(map(int, input().split()))
s_u = []
for i in range(n):
	summ = 0
	for (j, el) in enumerate(s):
		summ += 2 * el * (abs(j - i) + i + j)
	s_u.append(summ)
print(min(s_u))


n = int(input())
a = list(map(int, input().split(' ')))
mn = n * 2 * 10000
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)


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):
	fans = min(fans, solve(i))
print(fans)


floors = []

def solve(x):
	ans = 0
	for floor in floors:
		ans += 2 * abs(1 - floor) + 2 * abs(x - floor) + 2 * abs(x - 1)
	return ans
n = int(input())
ppl = list(map(int, input().split()))
for floor in range(len(ppl)):
	for i in range(ppl[floor]):
		floors.append(floor + 1)
best_x = -1
minCost = 90000000
for x_cand in range(1, 101):
	cost = solve(x_cand)
	if cost < minCost:
		minCost = cost
		best_x = x_cand
print(solve(best_x))


n = int(input())
a = list(map(int, input().split()))
print(4 * min((sum((a[i] * max(x, i) 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)


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 = list(map(int, input().split()))
x = [0] * n
for i in range(n):
	for j in range(len(a)):
		x[i] += 2 * a[j] * (abs(i - j) + j + i)
print(min(x))


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)


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


n = int(input())
a = [int(x) for x in input().split()]
imin = int(1000000000.0)
for x in range(1, n + 1):
	suma = 0
	for j in range(n):
		t = j + 1
		suma += 2 * a[j] * (x - 1 + j + abs(t - x))
	imin = min(imin, suma)
print(imin)


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
f = 1000000000
for x in range(1, n + 1):
	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
	if u < f:
		f = u
print(f * 2)


n = int(input())
l = list(map(int, input().split()))
k = 0
for i in range(n):
	s = 0
	for j in range(n):
		s += 2 * l[j] * (abs(i - j) + i + j)
	if i == 0 or (i != 0 and s < k):
		k = s
print(k)


n = int(input())
a = list(map(int, input().split()))
min_en = 10000000000
for i in range(n):
	x = i
	en = 0
	for j in range(n):
		en += (abs(j - x) + abs(j) + abs(x)) * 2 * a[j]
	if en < min_en:
		min_en = en
print(min_en)


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)


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
ans = 10 ** 9 + 7
for x in range(N + 1):
	res = 0
	for i in range(N):
		a = A[i]
		res += (abs(x - i) + x + i) * a
	ans = min(ans, res)
print(2 * 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())
arr = list(map(int, input().strip().split(' ')))
ans = 10 ** 18
for i in range(1, n + 1):
	temp = 0
	for j in range(1, n + 1):
		temp += arr[j - 1] * 2 * (abs(j - i) + abs(j - 1) + abs(1 - i))
	ans = min(ans, temp)
print(ans)


n = int(input())
a = list(map(int, input().split()))
minans = 999999
for z in range(n):
	x = z + 1
	ans = 0
	for b in range(n):
		ans += a[b] * (abs(x - (b + 1)) * 2 + b * 2 + (x - 1) * 2)
	if z == 0:
		minans = ans
	minans = min(minans, ans)
print(minans)


def inint():
	return int(input())

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

def main():
	n = inint()
	a = inlist()
	sol = 999999999
	for j in range(n):
		sol1 = 0
		x = j
		for i in range(n):
			sol1 += a[i] * (abs(i - x) + i + x + abs(x - 0) + abs(i - 0) + abs(x - i))
		sol = min(sol, sol1)
	print(sol)
main()


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)


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


n = int(input())
ar = list(map(int, input().strip().split(' ')))
t = 0
i = 0
m = 1000000000
while i < n:
	c = 0
	for j in range(n):
		c += (i + abs(i - j) + j) * ar[j] * 2
	if c < m:
		m = c
	i += 1
print(m)


a = int(input())
ais = [int(i) for i in input().split()]
mn = -1
for i in range(a):
	cs = 0
	for (idx, ai) in enumerate(ais):
		cs += ai * 2 * (idx + i + abs(i - idx))
	if cs < mn or mn == -1:
		mn = cs
print(mn)


n = int(input())
ps = input().split()
ps = [int(i) for i in ps]
x = ps.index(max(ps))
sum = ps[x] * x * 2 * 2
for i in range(len(ps)):
	if i == x:
		continue
	sum += i * 2 * ps[i] * 2
print(sum)


n = int(input())
x = [int(a) for a in input().split()]
m = 0
for i in range(n):
	if i != 0:
		k = 4 * i * x[i]
		m += k
	elif i == 0:
		k = 4 * x[0]
	else:
		continue
print(m)


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
	if ans > el:
		ans = el
print(ans)


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))


a = int(input())
b = input()
c = []
for d in b.split():
	c.append(int(d))
s = 0
t = 0
for f in range(0, a):
	t = t + 4 * f * c[f]
s = t
w = 0
for k in c:
	t = 0
	for n in range(1, a + 1):
		if k >= n:
			t += 4 * k * c[n - 1]
		else:
			t += 4 * n * c[n - 1]
	if t <= s:
		s = t
	else:
		w = 0
print(s)


n_floors = int(input())
people = []
people_str = input().split(' ')
for item in people_str:
	try:
		people.append(int(item))
	except:
		pass
cost_move_N_to_A = lambda n, a, c: n * 2 * (abs(a - c) + abs(a) + abs(c))
costs = [0] * n_floors
for x in range(n_floors):
	costs[x] = sum((cost_move_N_to_A(people[i], i, x) for i in range(n_floors)))
print(min(costs))


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


n = int(input())
a = list(map(int, input().split()))
costs = []
for i in range(n):
	tot = 0
	for j in range(n):
		tot += 4 * a[j] * max((i, j))
	costs.append(tot)
print(min(costs))


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)


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()))
a = [0] + a
maxi = -1
index = -1
for i in range(n):
	if a[i] > maxi:
		maxi = a[i]
		index = i
ans = 10 ** 10
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)


n = int(input())
li = [int(x) for x in input().split()]
zer = [0] * n
for i in range(n):
	zer[i] = 2 * i
final = [0] * n
for i in range(n):
	final[i] = li[i] * zer[i]
foo = [0] * n
for x in range(n):
	for i in range(x):
		foo[x] += 4 * x * li[i]
	for j in range(x, n):
		foo[x] += (abs(j - x) + j + x + x + j + abs(j - x)) * li[j]
print(min(foo))


n = int(input())
a = [int(s) for s in input().split()]
mn = float('inf')
for i in range(1, n + 1):
	sum = 0
	for j in range(n):
		sum += a[j] * (abs(j + 1 - i) + j + i - 1) * 2
	mn = min(mn, sum)
print(mn)


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


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import *
(n,) = I()
l = I()
opt = MOD
floor = 0
for x in range(n):
	cnt = 0
	for i in range(n):
		cnt += l[i] * (2 * abs(x - i) + 2 * i + 2 * x)
	if cnt < opt:
		opt = cnt
		floor = i
print(opt)


n = int(input())
k = 0
mi = 100000000000000
l = [int(i) for i in input().split()]
for i in range(n):
	k = 0
	for j in range(n):
		k += (abs(j - i) * 2 + i * 2) * l[j]
	if k < mi:
		mi = k
print(mi * 2)


n = int(input())
l = [2 * int(i) for i in input().split()]
s = 0
for i in range(n):
	s += int(i) * 2 * l[i]
print(s)


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

def sol(x):
	total = 0
	for i in range(1, n + 1):
		current = abs(i - 1) + abs(x - i) + abs(x - 1)
		current *= 2 * a[i - 1]
		total += current
	return total
maxV = 100000000
for i in range(n):
	maxV = min(sol(i + 1), maxV)
print(maxV)


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)


n = int(input())
arr = map(int, input().split())
arr = list(arr)
mini = 1000000000
for i in range(1, 101):
	ans = 0
	for (j, x) in enumerate(arr):
		dist = abs(j + 1 - i) + abs(i - 1) + abs(j) + abs(j) + abs(i - 1) + abs(j + 1 - i)
		dist *= x
		ans = ans + dist
	mini = min(mini, ans)
print(mini)


n = int(input())
a = list(map(int, input().split()))
u = []
for (f, k) in enumerate(a):
	u.append(4 * k * f)
print(sum(u))


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

def I():
	return int(sys.stdin.readline())

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
N = I()
A = Neo()
Ans = 10 ** 20
for i in range(1, N + 1):
	t = 0
	for j in range(N):
		t += (abs(j + 1 - i) + j + abs(1 - i)) * 2 * A[j]
	Ans = min(Ans, t)
print(Ans)


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)


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

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


n = int(input())
a = [0] + [int(i) for i in input().split()]
mn = 10 ** 12
for x in range(1, n + 1):
	z = 0
	for u in range(1, n + 1):
		z += 2 * a[u] * (abs(x - u) + abs(u - 1) + abs(x - 1))
	if z < mn:
		mn = z
print(mn)


def ans(arr, x):
	temp = [0] * len(arr)
	for i in range(n):
		temp[i] += 2 * (abs(i - x) + abs(i - 0) + abs(0 - x))
	cnt = 0
	for i in range(n):
		cnt += arr[i] * temp[i]
	return cnt
n = int(input())
arr = list(map(int, input().strip().split()))
xxx = []
for i in range(n):
	xxx.append(ans(arr, i))
print(min(xxx))


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


n = int(input())
l = [int(i) for i in input().split()]
res = []
x = 0
for i in range(n):
	for j in range(n):
		x += (2 * abs(i - j) + 2 * j) * l[j]
	res.append(x)
print(min(res))


n = int(input())
num = list(map(int, input().split()))
ans = 10 ** 18
for x in range(1, n + 1):
	res = 0
	for i in range(1, n + 1):
		res += (abs(x - i) + abs(i - 1) + abs(x - 1)) * num[i - 1]
	for i in range(1, n + 1):
		res += (abs(x - 1) + abs(i - 1) + abs(x - i)) * num[i - 1]
	ans = min(res, ans)
print(ans)


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


input()
(SUM, X) = (0, list(map(int, input().split())))
print(sum((i * 4 * X[i] for i in range(len(X)))))


r = i = 0
for x in map(int, [*open(0)][1].split()):
	r += 4 * i * x
	i += 1
print(r)


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


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()
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]
		m += s_floor
	minn = min(m, minn)
print(minn)


n = int(input())
arr = list(map(int, input().split()))
e = 0
x = arr[0]
for i in range(n):
	y = i * 2
	e += y * 2 * arr[i]
print(e)


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())
p = list(map(int, input().strip().split()))
ans = []
for k in range(n):
	sum = 0
	x = k + 1
	for i in range(1, len(p)):
		f = i + 1
		sum += p[i] * (abs(f - x) + abs(f - 1) + abs(x - 1)) * 2
	ans.append(sum)
print(min(ans))


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

def fl(p):
	r = 0
	for x in range(1, n + 1):
		r += flors[x - 1] * 2 * (abs(p - x) + abs(x - 1) + abs(p - 1))
	return r
result = 1000000000
for x in range(1, n + 1):
	result = min(result, fl(x))
print(result)


import math
n = int(input())
arr = [int(i) for i in input().split()]
for i in range(1, n + 1):
	summ = 0
	for k in range(1, len(arr) + 1):
		summ += 2 * arr[k - 1] * (math.fabs(i - k) + math.fabs(k - 1) + math.fabs(i - 1))
	if i == 1:
		summ_min = summ
	else:
		summ_min = min(summ, summ_min)
print(int(summ_min))


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())
min = 0
res = input().split()
for i in range(n):
	min += i * int(res[i])
print(4 * min)


n = int(input())
a = list(map(int, input().split()))
s = 10 ** 9 + 7
for x in range(n):
	ss = 0
	for j in range(n):
		if j <= x:
			ss += 2 * x * a[j]
		else:
			ss += j * 2 * a[j]
	if ss < s:
		s = ss
print(s * 2)


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


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


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


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


input()
print(4 * sum((x * y for (x, y) in enumerate(map(int, input().split())))))


n = int(input())
A = list(map(int, input().split()))
ANS = 10 ** 10
for x in range(1, 101):
	e = 0
	for i in range(n):
		e += A[i] * (abs(x - (i + 1)) + abs(1 - (i + 1)) + abs(1 - x)) * 2
	if ANS > e:
		ANS = e
print(ANS)


def solve():
	_ = map(int, input())
	m = list(map(int, input().split()))
	answer = 0
	for i in range(len(m)):
		answer += i * 4 * m[i]
	return answer
print(solve())


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


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


n = int(input())
a = list(map(int, input().split()))
(result, res) = (1000000000000, 0)
for x in range(1, n + 1):
	for (i, y) in enumerate(a):
		i += 1
		res += 2 * y * (abs(x - i) + i - 1 + x - 1)
	result = min(result, res)
	res = 0
print(result)


import math
n = int(input())
arr = [int(x) for x in input().split()]
ans = 10000000 * 100000
for i in range(1, 102):
	val = 0
	for j in range(n):
		val += arr[j] * (abs(j + 1 - i) + abs(j) + abs(j) + abs(i - 1) + abs(i - 1) + abs(j - i + 1))
	ans = min(val, ans)
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
min = 10 ** 9
for i in range(n):
	s = 0
	for j in range(n):
		s += (2 * j + 2 * abs(i - j) + 2 * i) * a[j]
	if s < min:
		min = s
print(min)


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


n = int(input())
entrada = input()
A = [int(x) for x in entrada.split()]

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


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


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(0, n):
	cost += 4 * a[i] * i
print(cost)


import math
n = int(input())
floor = list(map(int, input().split()))
el = math.inf
for q in range(n):
	temp = 0
	for w in range(len(floor)):
		temp += (abs(q - w) + w + q) * floor[w]
	if el > temp:
		el = temp
print(el * 2)


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()
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
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):
	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():
	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(p)
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):
	(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')
main()


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)
threading.stack_size(2 ** 27)
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, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

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):
	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):
	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
TestCases = False
testingMode = False
optimiseForReccursion = False

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)
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()


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


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)
	check = arr[0][1]
	index = -1
	while index < n - 1 and arr[index][1] == check:
		index += 1
	count = 0
	for i in range(n):
		count += 2 * (arr[i][1] * 2 * arr[i][0])
	print(count)
main()


import sys

def getelec(x, floors):
	total = 0
	for i in range(len(floors)):
		total += 4 * i * floors[i]
	return total
while True:
	line = sys.stdin.readline()
	if not line:
		break
	line = int(line.strip())
	people = []
	floors = [int(x) for x in sys.stdin.readline().split()]
	minunits = sys.maxsize
	for x in range(len(floors)):
		curr = getelec(x, floors)
		minunits = min(minunits, curr)
	print(minunits)


def energy(x, A):
	energy_option = 0
	for (floor, count) in enumerate(A):
		lift_to_person = abs(x - floor)
		lift_with_person_to_first = floor
		lift_back_to_default_position = x
		energy_option += count * (lift_to_person + lift_with_person_to_first + lift_back_to_default_position)
	return 2 * energy_option
n = int(input())
A = [int(j) for j in input().split(' ')]
min_e = 2000000000
for x in range(n):
	min_e = min(energy(x, A), min_e)
print(min_e)


n = eval(input())
l = list(map(int, input().split()))
x = 0
i = 0
y = len(l) - 1
m = 0
list = []
while x < len(l):
	while y >= 0:
		m += (abs(y - x) + y + abs(x)) * l[y]
		y -= 1
	list = list + [m]
	y = len(l) - 1
	x += 1
print(min(list) * 2)


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


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

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

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

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

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	a = li()
	ans = 10000000000000000
	for x in range(1, n + 1):
		cur = 0
		for i in range(1, n + 1):
			cur += (abs(i - x) + abs(i - 1) + abs(x - 1)) * a[i - 1]
		ans = min(cur, ans)
	print(ans * 2)
t = 1
for _ in range(t):
	solve()


n = int(input())
ls = list(map(int, input().split()))
lt = []
for i in range(n):
	s = 0
	for j in range(1, n):
		m = ls[j] * 4 * max(i, j)
		s += m
	lt.append(s)
print(min(lt))


n = int(input())
a = [1] + [int(x) for x in input().strip().split(' ')]
res = 0
power = []
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if j > i:
			res = a[j] * ((j - i) * 2 + (j - 1) * 2) * 2 + res
		else:
			res = a[j] * (j - 1) * 2 * 2 + res
	power.append(res)
	res = 0
ans = min(power)
print(ans)


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


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))


def req_elec(cap, x):
	return 2 * sum([c * (abs(x - f) + f + x) for (f, c) in enumerate(cap)])
n_floors = int(input())
cap_per_floor = [int(c) for c in input().split()]
print(min([req_elec(cap_per_floor, x) for x in range(n_floors)]))


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


n = int(input())
result = [int(i) for i in input().split()]
tot = 0
for i in range(n):
	tot += 2 * (2 * i) * result[i]
print(tot)


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


n = int(input())
l = list(map(int, input().split()))
E = 0
for i in range(len(l)):
	x = 2 * 2 * l[i] * i
	E = E + x
print(E)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
n = int(input())
l = list(map(int, input().split()))
m = sys.maxsize
for i in range(n):
	x = 0
	for j in range(n):
		y = 2 * l[j] * (abs(i - j) + j + i)
		x += y
	m = min(m, x)
print(m)


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
mi = 10 ** 18
for i in range(n):
	s = 0
	for j in range(n):
		s += (abs(i - j) + i + j) * L[j] * 2
	mi = min(mi, s)
print(mi)


n = int(input())
a = list(map(int, input().split()))
m = 99999999999999
for i in range(1, n + 1):
	cost = 0
	for j in range(1, n + 1):
		if j > i:
			cost += 4 * (j - 1) * a[j - 1]
		else:
			cost += 4 * (i - 1) * a[j - 1]
	m = min(cost, m)
print(m)


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())
a = [int(i) for i in input().split()]
ans = float('infinity')
for i in range(n):
	cost = 4 * i * a[i]
	for j in range(n):
		if i != j:
			cost += 2 * (abs(i - j) + i + j) * a[j]
	ans = min(ans, cost)
print(ans)


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())
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))


n = int(input())
a = [int(x) for x in input().split(' ')]
minUnits = -1
for i in range(n):
	currentUnits = 0
	for j in range(n):
		currentUnits += 2 * a[j] * (2 * (abs(i - j) + i))
	if minUnits == -1:
		minUnits = currentUnits
	else:
		minUnits = min(minUnits, currentUnits)
print(minUnits)


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)


def main():
	n = int(input())
	cnt = list(map(int, input().split()))
	ans = float('inf')
	for i in range(1, n):
		sum = 0
		for j in range(n):
			sum += cnt[j] * abs(j + 1 - i)
			sum += cnt[j] * j
			sum += cnt[j] * (i - 1)
			sum += cnt[j] * (i - 1)
			sum += cnt[j] * j
			sum += cnt[j] * abs(j + 1 - i)
		ans = min(ans, sum)
	print(0 if ans == float('inf') else ans)
main()


n = int(input())
a = [int(i) for i in input().split()]
opt = float('inf')
for x in range(1, n + 1):
	en = 0
	for i in range(2, n + 1):
		en = en + (2 * abs(i - x) + 2 * abs(i - 1) + 2 * abs(x - 1)) * a[i - 1]
	if en < opt:
		opt = en
print(opt)


def totalElectricity(curr, floors):
	return sum([2 * ppl * (abs(curr - ind) + ind + curr) for (ind, ppl) in enumerate(floors)])
n = int(input())
line = input()
floorsString = line.split()
floors = [int(x) for x in floorsString]
mncost = 999999999
for i in range(n):
	tot = totalElectricity(i, floors)
	mncost = min(mncost, tot)
print(mncost)


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)


def ans(arr):
	Min = float('inf')
	for i in range(0, n):
		min_ = 0
		for j in range(1, n):
			min_ += 2 * (abs(i - j) + i + j) * arr[j]
		Min = min(Min, min_)
	return Min
n = int(input())
a = list(map(int, input().strip().split()))
print(ans(a))


n = int(input())
h = list(map(int, input().split()))
ans = []
for i in range(n):
	s = 0
	for y in range(n):
		s += (abs(i - y) + y + i + i + y + abs(i - y)) * h[y]
	ans.append(s)
print(min(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())
A = [*map(int, input().split())]
MAX = 9223372036854775807
m = MAX
for x in range(0, n):
	c = 0
	for a in range(0, n):
		c += (abs(x - a) + a + x) * A[a] * 2
	m = min(m, c)
print(m)


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


t = int(input())
mini = 9999999
l = list(map(int, input().split()))
for i in range(1, t + 1):
	x = i
	ans = 0
	for i in range(1, t + 1):
		ans += (abs(x - i) + abs(1 - i) + abs(x - 1)) * 2 * l[i - 1]
	if mini > ans:
		mini = ans
print(mini)


n = int(input())
print(4 * sum([int(x) * i for (i, x) in enumerate([int(y) for y in input().split()])]))


n = int(input())
numOfPeople = list(map(int, input().split(' ')))
counter = 0
while n > 1:
	counter = counter + 2 * (numOfPeople[n - 1] * (2 * n - 2))
	n = n - 1
print(counter)


n = int(input())
a = list(map(int, input().split()))
m = 1000000
for x in range(1, n + 1):
	s = 0
	for b in range(1, n + 1):
		s += (abs(b - x) + abs(1 - b) + abs(1 - x)) * a[b - 1]
	if s < m:
		m = s
print(2 * m)


n = int(input())
a = [0] + [int(s) for s in input().split()]
min = 10 ** 10
for x in range(1, n + 1):
	energy = 0
	for i in range(1, len(a)):
		first = a[i] * (abs(x - i) + abs(i - 1) + abs(x - 1))
		second = a[i] * (abs(x - 1) + abs(i - 1) + abs(x - i))
		energy = energy + first + second
	if energy < min:
		min = energy
print(min)


n = int(input())
fs = input().split()
guar = 0
totppl = 0
for floor in range(1, n + 1):
	ppl = int(fs[floor - 1])
	guar += ppl * (floor - 1)
	totppl += ppl
print(guar * 4)


def retarray():
	return list(map(int, input().split()))
n = int(input())
a = retarray()
a = [0] + a
totcost = 1000000000
for x in range(1, n + 1):
	cost = 0
	for i in range(1, 1 + n):
		cost += 2 * a[i] * (abs(x - i) + (i - 1) + (x - 1))
	if cost < totcost:
		totcost = cost
print(totcost)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
su = 0
for j in range(1, n):
	su = su + a[j] * 4 * j
print(su)


n = int(input())
a = [int(i) for i in input().split()]
m = 10 ** 9
for x in range(n):
	s = 0
	for b in range(n):
		i = x + 1
		j = b + 1
		s += a[b] * ((abs(i - j) + j - 1 + i - 1) * 2)
	m = min(m, s)
print(m)


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))


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)]
	v = sum(ll)
	ans = min(ans, v)
	pos += 1
print(ans)


import sys
input = sys.stdin.read()
(n, *a) = list(map(int, input.split()))
sum1 = 0
for i in range(len(a)):
	sum1 += a[i] * i * 2
print(sum1 * 2)


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


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


def d(x, i, a):
	return 2 * a * (abs(x - i) + abs(i - 1) + abs(1 - x))
n = int(input())
arr = [int(k) for k in input().split()]

def e(x):
	return sum((d(x, i + 1, a) for (i, a) in enumerate(arr)))
print(min((e(x) for x in range(1, n + 1))))


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
ans = 0
for i in range(n):
	ans += i * 4 * a[i]
print(ans)


import sys
r = lambda : sys.stdin.readline()
n = int(input())
arr = list(map(int, input().split()))
hab = []
for i in range(1, n + 1):
	hh = 0
	for j in range(1, n + 1):
		if j == 1:
			d = 0
		else:
			d = (i - 1) * 2 + (j - 1) * 2 + abs(i - j) + abs(i - j)
			d = d * arr[j - 1]
		hh += d
	hab += [hh]
print(min(hab))


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)


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

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)

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


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
input = sys.stdin.readline
from collections import *
n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 18
for i in range(n):
	ans_cand = 0
	for j in range(n):
		ans_cand += 2 * a[j] * (abs(j - i) + i + j)
	ans = min(ans, ans_cand)
print(ans)


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

def podshet(i, j):
	return abs(i - j) + (j - 1) + (i - 1)

def cheak2(x, a):
	t = 0
	for j in range(0, len(a)):
		t = t + a[j] * podshet(x, j + 1)
	return t
l = 2 * cheak2(1, a)
for i in range(2, n + 1):
	t = 2 * cheak2(i, a)
	if t < l:
		l = t
print(l)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
elec = 0
elecnext = 0
for k in range(n):
	elec = elec + k * a[k] * 4
for i in range(n):
	for j in range(n):
		elecnext = elecnext + 2 * (i + abs(i - j) + j) * a[j]
	if elecnext <= elec:
		elec = elecnext
	elecnext = 0
print(elec)


n = int(input())
p = [int(k) for k in input().split()]
res = None
best = None
for x in range(1, n + 1):
	cur = 0
	for (i, v) in enumerate(p):
		cur += v * (abs(x - (i + 1)) + i + (x - 1) + x - 1 + i + abs(x - (i + 1)))
	if res is None or cur < res:
		res = cur
		best = x
print(res)


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 = 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)


t = 1
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)


import sys
from math import ceil
n = [int(val) for val in input().split()][0]
a = [int(val) for val in input().split()]
best = float('inf')
for x in range(1, 100):
	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())
l = list(map(int, input().split()))
emp = []
for i in range(n):
	c = 0
	for j in range(n):
		if j <= i:
			c += l[j] * i * 4
		else:
			c += l[j] * j * 4
	emp.append(c)
print(min(emp))


n = int(input())
x = 0
maxx = 1000000000
l = list(map(int, input().split()))
for i in range(1, n + 1):
	if l[i - 1] > 0:
		if maxx > int(i / l[i - 1]):
			maxx = min(x, int(i / l[i - 1]))
			x = i
ans = 0
for i in range(1, n + 1):
	ans += l[i - 1] * (abs(x - i) + i - 1 + x - 1)
print(2 * ans)


def calc(a, x, k):
	return 2 * int(a[k - 1]) * (abs(x - k) + x + k - 2)

def main():
	n = eval(input())
	a = input().split()
	res = 9999999999
	for i in range(n):
		temp = 0
		for j in range(n):
			temp += calc(a, i + 1, j + 1)
		res = min(res, temp)
	print(res)
main()


n = int(input())
m = list(map(int, input().split()))
mins = float('inf')
v = 0
total = 0
for i in range(1, n + 1):
	for a in range(1, n + 1):
		v += abs(a - i) + abs(i - 1) + abs(a - 1) + abs(i - a) + abs(i - 1) + abs(a - 1)
		mins = min(mins, v)
		v = 0
	total += mins * m[i - 1]
	mins = float('inf')
print(total)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(mn, mnv) = (-1, 10 ** 9)
	for x in range(n):
		sm = 0
		for (i, c) in enumerate(a):
			sm += c * max(i, x) * 4
		if sm < mnv:
			(mn, mnv) = (x, sm)
	print(mnv)
solve()


import math
import sys
input = sys.stdin.readline
n = int(input())
f = list(map(int, input().split()))
ans = int(1000000000.0) + 7
for x in range(n):
	unit = 0
	for i in range(n):
		a = f[i]
		unit += a * (abs(x - i) + i + x) * 2
	ans = min(ans, unit)
print(ans)


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


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

def f(x, l):
	s = 0
	for i in range(len(l)):
		s += l[i] * 2 * (abs(x - i) + abs(x) + abs(i))
	return s
q = 10 ** 10
for x in range(n):
	q = min(f(x, l), q)
print(q)


n = int(input())
a = [int(a) for a in list(input().strip().split())]
mn = pow(10, 18)
for f in range(n):
	mv = 0
	for i in range(n):
		mv += 2 * abs(f - i) * a[i]
		mv += 2 * i * a[i]
		mv += 2 * f * a[i]
	if mn > mv:
		mn = mv
print(mn)


n = int(input())
a = input().split()
start = -1
for i in range(n):
	res = 0
	for j in range(n):
		res += 2 * (abs(i - j) + j + i) * int(a[j])
	if start > res or start == -1:
		start = res
print(start)


n = int(input())
a = [int(i) for i in input().split()]
ans_min = 100000000
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)


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 - j) + j + i) * w[j]
	r.append(e)
print(min(r) * 2)


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


n = int(input().strip())
a = list(map(int, input().strip().split()))
s = 0
for i in range(n):
	s += 2 * 2 * i * a[i]
print(s)


N = int(input())
line = input().split()
list = []
for i in range(N):
	list.append(int(line[i]))
res = 100000000
for x in range(N):
	s = 0
	for i in range(N):
		s += 4 * i * list[i]
	res = min(res, s)
print(res)


n = int(input())
arr = [int(x) for x in input().split()]
s = 0
r = 2
for i in arr[1:]:
	s += i * r * 2
	r += 2
print(s)


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


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())
a = list(map(int, input().split()))
min_units = 2000000
for i in range(n):
	units = 0
	for j in range(n):
		units += max(i, j) * 4 * a[j]
	min_units = min(min_units, units)
print(min_units)


n = int(input())
arr = [int(p) for p in input().split()]
minE = float('inf')
for i in range(1, n + 1):
	curr = 0
	for j in range(1, n + 1):
		curr += 2 * arr[j - 1] * (abs(i - j) + abs(j - 1) + abs(i - 1))
	minE = min(curr, minE)
print(minE)


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


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

def cost(i, x, ai):
	return (abs(i - x) + abs(i - 1) + abs(x - 1)) * ai * 2

def costs_x(x):
	return [cost(i, x, a[i - 1]) for i in range(1, n + 1)]
print(min([sum(costs_x(x)) for x in range(1, n + 1)]))


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


from functools import reduce
import sys
from os.path import isfile
(fin, fout) = (open('a.in'), open('a.out', 'w')) if isfile('a.in') else (sys.stdin, sys.stdout)

def ris():
	return map(int, fin.readline().split())

def ri():
	return int(fin.readline())
n = ri()
f = list(ris())

def cost(x):
	return 2 * sum((p * (abs(x - a) + a + x) for (a, p) in enumerate(f)))
(l, r) = (0, n)
while l != r:
	gap = (r + l) / 3
	(x, y) = (int(gap), int(2 * gap))
	if cost(x) <= cost(y):
		r = y if y != l + 1 else l
	else:
		l = x
fout.write('%d\n' % cost(l))
(fin.close(), fout.close())


n = int(input())
A = []
x = 0
h = 0
B = list(map(int, input().split()))
for i in range(1, n + 1):
	x = i
	for j in range(1, n + 1):
		h += (abs(j - x) + abs(j - 1) + abs(1 - x)) * B[j - 1]
		h += (abs(j - 1) + abs(j - x) + abs(x - 1)) * B[j - 1]
	A.append(h)
	h = 0
print(min(A))


import math
import sys
import os
if os.path.isfile('C:\\work\\python\\input.txt'):
	sys.stdin = open('C:\\work\\python\\input.txt', 'r')
	sys.stdout = open('C:\\work\\python\\output.txt', 'w')
n = int(input())
a = [int(x) for x in input().split()]
ans = 1000000000.0
for i in range(n):
	c = 0
	for j in range(n):
		c += a[j] * (abs(i - j) + j + i) * 2
	ans = min(ans, c)
print(ans)


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


import math, sys, itertools

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

def main():
	n = int(input())
	a = mp()
	ans = int(1000000000.0)
	for i in range(n):
		res = 0
		for j in range(n):
			res += a[j] * (2 * i + 2 * abs(i - j) + 2 * j)
		ans = min(ans, res)
	print(ans)
deb = 0
if deb:
	file = open('input.txt', 'r')
	input = file.readline
else:
	input = sys.stdin.readline
main()


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


n = int(input())
a = [int(x) for x in input().split()]
min = 1000000000000
for i in range(1, n + 1):
	ans = 0
	for j in range(n):
		ans += (2 * abs(i - j - 1) + 2 * j + 2 * (i - 1)) * a[j]
	if ans < min:
		min = ans
print(min)


amount = int(input())
array = [int(s) for s in input().split()]
min_sum = 10000000000.0
for i in range(1, amount + 1):
	sum_ = 0
	for j in range(amount):
		sum_ += array[j] * (abs(j + 1 - i) + j + i - 1)
	if 2 * sum_ < min_sum:
		min_sum = 2 * sum_
print(min_sum)


import math
n = int(input())
passengers = list(map(int, input().rstrip().split()))
xvalues = []
for j in range(n):
	elec = 0
	for i in range(n):
		distanceper = abs(j - i) + i + j + j + i + abs(j - i)
		distancetotal = distanceper * passengers[i]
		elec += distancetotal
	xvalues.append(elec)
print(min(xvalues))


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(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
	total += 2 * 2 * i * a[i]
print(total)


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]
	ans.append(e)
print(min(ans))


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))


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	n = int(input())
	arr = inar()
	ans = 10 ** 18
	for i in range(n):
		temp = 0
		for j in range(n):
			temp += 2 * (abs(j - i) + j + i) * arr[j]
		ans = min(ans, temp)
	print(ans)
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l = [*map(int, input().split())]

def cost(x):
	x -= 1
	res = 0
	for i in range(n):
		res += l[i] * (abs(x - i) + abs(i - 0) + abs(0 - x))
	return res
res = float('inf')
for x in range(1, n + 1):
	res = min(res, cost(x))
print(2 * res)


t = int(input())
b = list(map(int, input().split()))
a = [i for i in range(t)]
c = list(zip(a, b))
if len(c) > 1:
	x = c[1][0]
else:
	x = 0
d = 0
g = 0
for i in c[1:]:
	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)


n = int(input())
jit = list(map(int, input().split()))
cnt = 0
for u in range(n):
	cnt += jit[u] * 4 * u
print(cnt)


n = int(input())
a = list(map(int, input().split()))
ans = 0
e = 10 ** 9
for i in range(n):
	ne = 0
	for j in range(n):
		ne += (abs(i - j) + j + i) * 2 * a[j]
	if ne < e:
		e = ne
		ans = i
print(e)


from math import *
n = int(input())
a = list(map(int, input().split()))
mn = inf
for i in range(n):
	sm = 0
	for j in range(n):
		sm += a[j] * (abs(i - j) + j + i + i + j + abs(i - j))
	if sm < mn:
		mn = sm
print(mn)