A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.

Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite.

You want to buy at least L liters of lemonade. How many roubles do you have to spend?


-----Input-----

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.

The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types.


-----Output-----

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.


-----Examples-----
Input
4 12
20 30 70 90

Output
150

Input
4 3
10000 1000 100 10

Output
10

Input
4 3
10 100 1000 10000

Output
30

Input
5 787787787
123456789 234567890 345678901 456789012 987654321

Output
44981600785557577



-----Note-----

In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.

In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.

In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.

Difficulty: MEDIUM_HARD

Solutions:
cin = input().split()
n = int(cin[0])
m = int(cin[1])
data = list(map(int, input().split()))
for x in range(1, max(len(data), len(bin(m)) - 2) + 10):
	if x < len(data):
		if data[x] > data[x - 1] * 2:
			data[x] = data[x - 1] * 2
	else:
		data.append(data[x - 1] * 2)
for x in reversed(range(0, len(data) - 1)):
	data[x] = min(data[x + 1], data[x])
m = bin(m)
m = list(reversed(m))
ans = 0
for x in range(max(len(data), len(m) - 2)):
	if x >= len(m) - 2:
		ans = min(ans, data[x])
	elif m[x] == '1':
		ans += int(data[x])
	else:
		ans = min(ans, data[x])
print(ans)


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
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')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

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

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, k) = mp()
arr = lmp()
for i in range(1, n):
	arr[i] = min(arr[i], 2 * arr[i - 1])
ans = 0
mn = inf
for i in range(n - 1, -1, -1):
	ans += arr[i] * (k // (1 << i))
	k %= 1 << i
	if k:
		mn = min(mn, ans + arr[i])
	else:
		mn = min(mn, ans)
print(mn)


s = 0
ans = 100 ** 1000
(n, l) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(0, n - 1):
	a[i + 1] = min(a[i + 1], 2 * a[i])
for i in range(n - 1, -1, -1):
	d = l // (1 << i)
	s += d * a[i]
	l -= d << i
	ans = min(ans, s + (l > 0) * a[i])
print(ans)


INF = int(1e+18)

def read_int():
	return list(map(int, input().split()))
(n, l) = read_int()
costs = read_int()
bottles = [(1 << i, c) for (i, c) in enumerate(costs)]
bottles.sort(key=lambda b: (b[1] / b[0], 1 / b[1]))
min_cost = dict()

def find_min_cost(l):
	if l == 0:
		return 0
	if l in min_cost:
		return min_cost[l]
	c = INF
	for b in bottles:
		c1 = (l + b[0] - 1) // b[0] * b[1]
		c2 = l // b[0] * b[1] + find_min_cost(l % b[0]) if l > b[0] else INF
		c = min(c, c1, c2)
	min_cost[l] = c
	return min_cost[l]
print(find_min_cost(l))


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
eff = [0]
best = 0
for i in range(1, n):
	if c[i] < 2 ** (i - best) * c[best]:
		eff.append(i)
		best = i
cost = 0
fcost = 10 ** 1000
for curr in range(len(eff) - 1, -1, -1):
	num = l // 2 ** eff[curr]
	l -= 2 ** eff[curr] * num
	cost += num * c[eff[curr]]
	fcost = min(fcost, cost + c[eff[curr]])
print(min(fcost, cost))


import math
N = 31
(n, l) = map(int, input().split())
cost = [int(x) for x in input().split()]
for i in range(n, N):
	cost.append(math.inf)
for i in range(N - 1):
	cost[i + 1] = min(cost[i + 1], cost[i] * 2)
ans = math.inf
cur_cost = 0
for i in range(N - 1, -1, -1):
	if 2 ** i >= l:
		ans = min(ans, cur_cost + cost[i])
	else:
		cur_cost += cost[i]
		l -= 2 ** i
print(ans)


def dec(costs, V):
	r = 0
	(price, typ) = costs[len(costs) - 1]
	fills = int((V - V % int(2 ** (typ - 1))) / int(2 ** (typ - 1)))
	r = r + price * fills
	V = V - int(2 ** (typ - 1)) * fills
	if V <= 0:
		return r
	elif len(costs) > 1:
		smallerCosts = dec(costs[:len(costs) - 1], V)
		if smallerCosts + r < price + r:
			return smallerCosts + r
		else:
			return price + r
	else:
		return price + r
trap = input()
t = trap.split(sep=' ')
n = int(int(t[0]))
V = int(int(t[1]))
tra = input()
t = tra.split(sep=' ')
costs = []
for k in range(0, n):
	costs.append([int(t[k]), k + 1])
k = 1
while k < len(costs):
	ivaluec = costs[k][0] / 2 ** (costs[k][1] - costs[k - 1][1])
	ivaluep = costs[k - 1][0]
	if ivaluec > ivaluep:
		costs.pop(k)
		k = k - 1
	k = k + 1
k = 1
while k < len(costs):
	if costs[k][0] < costs[k - 1][0]:
		costs.pop(k - 1)
		k = k - 1
	k = k + 1
r = 0
print(dec(costs, V))


(n, l) = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(1, n):
	a[i] = min(a[i], 2 * a[i - 1])
for i in range(32 - n):
	a.append(a[-1] * 2)
ans = 0
lastset = 0
for i in range(32):
	if 1 << i & l == 1 << i:
		lastset = i
for j in range(0, 32):
	if 1 << j & l == 1 << j:
		ans += a[j]
	else:
		ans = min(ans, a[j])
print(ans)


(n, L) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
size = [2 ** p for p in range(n)]
for index in range(n):
	if index > 0:
		c[index] = min(c[index], c[index - 1] * 2)
for index in range(n):
	if index > 0:
		temp = n - 1 - index
		c[temp] = min(c[temp], c[temp + 1])
poss = []
base = 0
maxindex = 0
while size[maxindex] < L and maxindex < n - 1:
	maxindex += 1
if size[maxindex] < L:
	base = L // size[maxindex] * c[maxindex]
	L = L % size[maxindex]
if L == 0:
	print(base)
else:
	poss.append(base + c[maxindex])
	curr = base
	while L > 0:
		while size[maxindex] >= 2 * L:
			maxindex -= 1
		poss.append(curr + c[maxindex])
		if maxindex == 0:
			curr += c[0]
			L = 0
		else:
			L -= size[maxindex - 1]
			curr += c[maxindex - 1]
	poss.append(curr)
	print(min(poss))


entrada = input().split()
n = int(entrada[0])
L = int(entrada[1])
arr_c = [int(c) for c in input().split()]
for i in range(0, n - 1):
	arr_c[i + 1] = min(arr_c[i + 1], 2 * arr_c[i])
result = 4 * 10 ** 18
soma = 0
i = n - 1
while i >= 0:
	temp = L // (1 << i)
	soma += temp * arr_c[i]
	L -= temp << i
	result = min(result, soma + (L > 0) * arr_c[i])
	i -= 1
print(result)


(n, liters) = (int(x) for x in input().split())
prices = list(map(int, input().split()))
answer = 10 ** 18
cache = 0
for i in range(n - 1):
	prices[i + 1] = min(prices[i + 1], prices[i] * 2)
for i in range(n - 1, -1, -1):
	div = 1 << i
	cache += prices[i] * (liters // div)
	liters %= div
	mult = liters != 0
	answer = min(answer, cache + mult * prices[i])
print(answer)


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
c += [float('inf')] * (35 - len(c))
for i in range(len(c) - 1):
	if c[i] * 2 < c[i + 1]:
		c[i + 1] = 2 * c[i]

def main():
	l = bin(L)[2:][::-1]
	ans = 0
	for i in range(len(c)):
		if ans > c[i]:
			ans = c[i]
		if i < len(l) and l[i] == '1':
			ans += c[i]
	return ans
print(main())


def solve(a, l):
	if l == 0:
		return 0
	if l == 1:
		return a[0]
	k = 0
	while 2 ** k < l:
		k += 1
	return min(a[k], a[k - 1] + solve(a, l - 2 ** (k - 1)))

def main():
	(n, l) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n - 2, -1, -1):
		if a[i] > a[i + 1]:
			a[i] = a[i + 1]
	for i in range(1, n):
		if a[i] > 2 * a[i - 1]:
			a[i] = 2 * a[i - 1]
	while len(a) < 35:
		a.append(2 * a[len(a) - 1])
	print(solve(a, l))
main()


(n, l) = map(int, input().split())
b = list(map(int, input().split()))
c = [float('inf')] * 31
for i in range(n):
	c[i] = b[i]
i = 0
while i < n:
	p = 2 ** i
	r = i
	while r < 30:
		j = 2 ** r
		c[r] = min(c[r], b[i] * (j // p))
		r += 1
	i += 1
c[30] = min(c[30], 2 * c[29])
s = bin(l)[2:]
s = s[::-1]
while len(s) != 31:
	s += '0'
res = 10 ** 30
j = 30
p = 0
while j >= 0:
	if s[j] == '0':
		res = min(res, p + c[j])
	else:
		p += c[j]
	j += -1
res = min(res, p)
print(res)


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
v = []
for i in range(n):
	v.append(2 ** i)
from math import ceil

def sl(n, l, c, bl):
	s = []
	for i in range(n):
		if i not in bl:
			s.append((v[i], v[i] / c[i], c[i], i))
	sm = min(s, key=lambda x: -x[1])
	ct = ceil(l / sm[0])
	if sm[0] == 1:
		return ct * sm[2]
	ans = (ct - 1) * sm[2]
	ans1 = min(sm[2], sl(n, l - (ct - 1) * sm[0], c, bl + [sm[3]]))
	return ans + ans1
print(sl(n, l, c, []))


(n, L) = map(int, input().split())
A = list(map(int, input().split())) + [1 << 64] * 30
n += 30
for i in range(1, n):
	A[i] = min(A[i], A[i - 1] * 2)
cur = 0
now_cost = 0
ans = 1 << 64
for i in range(n - 1, -1, -1):
	if cur | 1 << i >= L:
		ans = min(ans, now_cost + A[i])
	else:
		cur |= 1 << i
		now_cost += A[i]
print(ans)


from math import ceil, floor
(n, L) = map(int, input().split(' '))
cost = list(map(int, input().split(' ')))
cost.extend([-1 for _ in range(30 - len(cost))])
for i in range(1, 30):
	if 2 * cost[i - 1] < cost[i] or cost[i] == -1:
		cost[i] = 2 * cost[i - 1]
for i in range(29, 1, -1):
	if cost[i - 1] > cost[i]:
		cost[i - 1] = cost[i]
totalCost = 0
altTotalCost = 100000000000000000000000
while L > 0:
	index1 = L.bit_length() - 1
	index2 = L.bit_length()
	if index2 >= 30:
		num = floor(L / 2 ** index1)
		totalCost += cost[index1] * num
		L -= num * 2 ** index1
		continue
	L -= 2 ** index1
	totalCost += cost[index1]
	altTotalCost = min(altTotalCost, totalCost - cost[index1] + cost[index2])
print(min(totalCost, altTotalCost))


def main():
	(n, m) = map(int, input().split())
	(v, l, nxt) = (1, [], [(0, m)])
	for c in map(int, input().split()):
		l.append((c / v, v, c))
		v *= 2
	minv = hi = 1 << 60
	for (_, v, c) in sorted(l):
		if minv > v:
			(minv, cur, nxt) = (v, nxt, [])
			for (cost, rest) in cur:
				nxt.append((cost + rest // v * c, rest % v))
				cost += (rest + v - 1) // v * c
				if hi > cost:
					hi = cost
	print(hi)
main()


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
C = [[0 for i in range(30)] for i in range(n)]
for i in range(n):
	for j in range(30):
		if j <= i:
			C[i][j] = c[i]
		else:
			C[i][j] = c[i] << j - i
ans = 0
for i in range(30):
	tmp = 1e+18
	pos = 0
	for j in range(n)[::-1]:
		if tmp > C[j][i]:
			tmp = C[j][i]
			pos = j
	if pos >= i and tmp < ans:
		ans = tmp
	if L >> i & 1:
		ans += tmp
print(ans)


s = input().split()
(n, L) = (int(s[0]), int(s[1]))
c = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
	if c[i] < c[i - 1]:
		c[i - 1] = c[i]
for i in range(1, n):
	if c[i] > c[i - 1] * 2:
		c[i] = c[i - 1] * 2
while len(c) < 31:
	c.append(c[-1] * 2)
s = set()
ans = 0
for i in range(30, -1, -1):
	if L == 0:
		break
	if L >= pow(2, i):
		L -= pow(2, i)
		ans += c[i]
	else:
		s.add(ans + c[i])
s.add(ans)
print(min(s))


import sys
(n, L) = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
for i in range(1, n):
	c[i] = min(c[i], 2 * c[i - 1])
for i in range(n - 2, -1, -1):
	c[i] = min(c[i], c[i + 1])
res = L // 2 ** (n - 1) * c[n - 1]
L %= 2 ** (n - 1)
tres = 0
for sh in range(n):
	if L & 2 ** sh != 0:
		tres += c[sh]
	else:
		tres = min(tres, c[sh])
res += tres
print(res)


import math
(n, L) = map(int, input().split())
c = list(map(int, input().split()))
t = [c[i] if i < n else float('inf') for i in range(32)]
for i in range(1, 32):
	t[i] = min(t[i], 2 * t[i - 1])
a = 0
for i in range(0, 32):
	q = 2 ** i
	if L & q > 0:
		a += t[i]
	else:
		a = min(a, t[i])
print(a)


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
ad = [len([1 for j in range(i + 1, n) if c[j] <= c[i]]) == 0 and len([1 for j in range(0, i) if c[j] * 2 ** (i - j) < c[i]]) == 0 for i in range(n)]
order = [i for i in range(n) if ad[i]]

def solve(L, max_i):
	if L == 0:
		return 0
	if max_i == 0:
		return (L // 2 ** order[max_i] + (1 if L % 2 ** order[max_i] else 0)) * c[order[max_i]]
	cost = 0
	l = L // 2 ** order[max_i]
	L %= 2 ** order[max_i]
	if L == 0:
		return l * c[order[max_i]]
	cost1 = (l + 1) * c[order[max_i]]
	cost2 = l * c[order[max_i]] + solve(L, max_i - 1)
	return min(cost1, cost2)
print(solve(L, len(order) - 1))


(n, L) = tuple(map(int, input().split()))
cost = list(map(int, input().split()))
x = '0' * (n - len(bin(L)[2:])) + bin(L)[2:]
z = [x]
for i in range(len(x)):
	if x[i] == '0':
		l = x[:i] + '1' + '0' * (len(x) - i - 1)
		assert len(l) == len(x)
		z.append(l)
for i in range(len(cost) - 1):
	cost[i + 1] = min(cost[i + 1], 2 * cost[i])
for i in range(len(cost), len(x)):
	cost.append(cost[-1] * 2)
assert len(cost) == len(x)
c = []
for l in z:
	co = 0
	for i in range(len(x)):
		co += int(l[i]) * cost[len(x) - 1 - i]
	c.append(co)
print(min(min(c), 2 * cost[-1]))


def ceil(a, b):
	if a % b:
		return a // b + 1
	return a // b
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
b[0] = a[0]
for i in range(1, n):
	b[i] = min(a[i], 2 * b[i - 1])

def check(i, k, b):
	if i == -1:
		return 0
	return min(b[i] * (k // 2 ** i) + check(i - 1, k % 2 ** i, b), b[i] * ceil(k, 2 ** i))
print(check(n - 1, k, b))


import functools
import math

def compare(a, b):
	A = a[0] / a[1]
	B = b[0] / b[1]
	if A < B:
		return -1
	if A > B:
		return 1
	if A == B:
		if a[1] > b[1]:
			return -1
		else:
			return 1
(n, L) = input().split()
n = int(n)
L = int(L)
a = [int(x) for x in input().split()]
v = []
for i in range(n):
	if i == 0:
		v.append([a[i], math.pow(2, i)])
	else:
		a[i] = min(a[i], 2 * a[i - 1])
		v.append([a[i], math.pow(2, i)])
v = sorted(v, key=functools.cmp_to_key(compare))

def solve(dp, L, m):
	for i in range(len(dp)):
		if dp[i][0] <= m:
			pp = m // dp[i][0]
			m -= dp[i][0] * pp
			L -= dp[i][1] * pp
			if L <= 0:
				return True
	if L <= 0:
		return True
	else:
		return False
l = 1
r = 10000000000000000000
res = r
while l <= r:
	if l == r:
		if solve(v, L, l):
			res = min(res, l)
		break
	else:
		m = (l + r) // 2
		if solve(v, L, m) == True:
			res = min(res, m)
			r = m - 1
		else:
			l = m + 1
print(res)


(n, l) = map(int, input().split())
cost = list(map(int, input().split()))
for i in range(1, n):
	cost[i] = min(2 * cost[i - 1], cost[i])
ans = 10 ** 20
comp = 0
for i in range(n - 1, -1, -1):
	to = l // (1 << i)
	comp += to * cost[i]
	l -= to << i
	if l > 0:
		ans = min(ans, comp + cost[i])
	else:
		ans = min(ans, comp)
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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')
(n, L) = map(int, input().split())
c = list(map(int, input().split()))
t = [c[i] if i < n else float('inf') for i in range(32)]
for i in range(1, 32):
	t[i] = min(t[i], 2 * t[i - 1])
a = 0
for i in range(0, 32):
	q = 2 ** i
	if L & q > 0:
		a += t[i]
	else:
		a = min(a, t[i])
print(a)


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

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

def li():
	return list(mi())
(n, L) = mi()
C = li()
for i in range(1, n):
	C[i] = min(C[i], C[i - 1] * 2)
x = 2 ** (n - 1)
y = 0
z = 10 ** 18
for i in range(n - 1, -1, -1):
	t = L // x
	y += C[i] * t
	z = min(z, y + C[i])
	L %= x
	x //= 2
z = min(z, y)
print(z)


import os
import sys
from io import BytesIO, IOBase
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')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
from fractions import Fraction
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
(n, l) = Ri()
a = Ri()
aa = [(Fraction(2 ** i, a[i]), i) for i in range(len(a))]
aa.sort(key=lambda x: -x[0])
ans = 0
i = 0
maxx = 10 ** 18
for i in range(i, len(a)):
	div = l // 2 ** aa[i][1]
	if div == 0:
		maxx = min(maxx, ans + a[aa[i][1]])
		continue
	else:
		l = l % 2 ** aa[i][1]
		ans += div * a[aa[i][1]]
		if l > 0:
			maxx = min(maxx, ans + a[aa[i][1]])
		else:
			maxx = min(maxx, ans)
	if l <= 0:
		break
print(maxx)


def tt(l, r):
	h = len(l)
	o = l[h - r:]
	c = h - r
	for i in range(h - r - 1, -1, -1):
		if l[i] == '1':
			o = '0' + o
			break
		else:
			o = '1' + o
		c -= 1
	else:
		return '0'
	return l[:c - 1] + o
(n, l) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] = min(a[i - 1] * 2, a[i])
r = 2 ** (n - 1)
t = l // r * a[-1]
l %= r
t2 = 0
b = [0] * n
l = bin(l)[2:]
t3 = float('inf')
t2 = 0
for i in range(len(l)):
	if l[-1 - i] == '1':
		t2 += a[i]
t3 = t2
t4 = 0
l = '0' * (n - len(l)) + l
for i in range(len(l)):
	if l[-1 - i] == '1':
		t4 += a[i]
	else:
		t3 = min(t2 - t4 + a[i], t3)
print(t + t3)


(n, lit) = map(int, input().split())
cost = list(map(int, input().split())) + [1 << 100] * 33
n = len(cost)
rlit = lit
for i in range(n):
	for j in range(i - 1, -1, -1):
		cost[i] = min(cost[i], cost[j] * (1 << i - j))
res = 0
for i in range(n):
	if 1 << i & lit:
		res += cost[i]
b = []
while lit:
	b.append(lit % 2)
	lit //= 2
rres = res
for i in range(len(b) - 1, -1, -1):
	if b[i] == 1:
		for j in range(i - 1, -1, -1):
			if b[j] == 0:
				add = cost[j]
				sub = 0
				for k in range(j - 1, -1, -1):
					if b[k] == 1:
						sub += cost[k]
				res = min(res, rres + add - sub)
for i in range(n):
	if 1 << i > rlit and cost[i] < res:
		res = cost[i]
print(res)


(n, l) = map(int, input().split())
(c, s) = (0, 10 ** 18)
a = list(map(int, input().split()))
for i in range(len(a) - 1):
	a[i + 1] = min(a[i + 1], a[i] * 2)
for i in range(n - 1, -1, -1):
	d = 1 << i
	c += a[i] * (l // d)
	l %= d
	s = min(s, c + (l != 0) * a[i])
print(s)


from math import ceil
(n, l) = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [0 for i in range(32)]
for i in range(32):
	dp[i] = 2 ** i * arr[0]
for i in range(1, n):
	for j in range(i, 32):
		f = 2 ** j
		cur = 2 ** i
		fac = f // cur
		dp[j] = min(dp[j], fac * arr[i])
temp = []
for i in range(n):
	temp.append([dp[i] / 2 ** i, 2 ** i, dp[i]])
temp.sort()

def checker(cost):
	cur_vol = 0
	while True:
		f = 0
		for i in range(n):
			if cost >= temp[i][2]:
				fac = cost // temp[i][2]
				num = fac * temp[i][1]
				cur_vol += num
				f = 1
				cost = cost - fac * temp[i][2]
				break
		if f == 0:
			break
	if cur_vol >= l:
		return 1
	else:
		return -1
low = 0
high = 10 ** 19
while low < high:
	mid = (low + high) // 2
	f = checker(mid)
	if f == 1:
		high = mid
	else:
		low = mid
	if high - low == 1:
		break
if checker(low) == 1:
	print(low)
else:
	print(high)


(n, L) = map(int, input().split())
lst = []
for x in input().split():
	lst.append(int(x))
lst.extend([10 ** 20] * (31 - n))
for x in range(len(lst) - 1):
	lst[x + 1] = min(lst[x + 1], 2 * lst[x])
s = bin(L)[2:]
s = s[::-1]
price = 0
for x in range(len(s)):
	price += int(s[x]) * lst[x]
for x in range(len(lst)):
	if x >= len(s):
		price = min(price, lst[x])
	elif s[x] == '0':
		p = lst[x]
		for y in range(x + 1, len(s)):
			p += int(s[y]) * lst[y]
		price = min(price, p)
print(price)


(n, L) = map(int, input().split())
bottles = (int(x) for x in input().split())
bottles = [(2 ** i, p) for (i, p) in enumerate(bottles)]
perliter = lambda x: x[1] / x[0]
bottles = sorted(bottles, key=perliter)
temp = 0
paid = float('inf')
for (liters, price) in bottles:
	(got, L) = divmod(L, liters)
	temp += got * price
	paid = min(paid, temp + price if L else temp)
print(paid)


from math import ceil, inf

def put():
	return map(int, input().split())
(n, k) = put()
l = list(put())
for i in range(1, n):
	l[i] = min(l[i], 2 * l[i - 1])
sum = 0
ans = inf
for i in range(n - 1, -1, -1):
	q = k // (1 << i)
	k %= 1 << i
	z = 0 if k == 0 else l[i]
	sum += q * l[i]
	ans = min(ans, z + sum)
print(ans)


def solve(a1, b1, cur_sum, cur_L, idx):
	if cur_L == 0:
		return cur_sum
	if idx == len(a1) - 1:
		if cur_L > 0:
			ost = cur_L % b1[-1] > 0
			if ost:
				cur_sum += a1[-1]
			cur_sum += a1[-1] * (cur_L // b1[-1])
			return cur_sum
		else:
			return cur_sum
	else:
		ost = cur_L % b1[idx] > 0
		if ost:
			s1 = solve(a1, b1, cur_sum + a1[idx] * (cur_L // b[idx] + 1), 0, idx + 1)
			s2 = solve(a1, b1, cur_sum + a1[idx] * (cur_L // b[idx]), cur_L % b1[idx], idx + 1)
			return min(s1, s2)
		else:
			return solve(a1, b1, cur_sum + a1[idx] * (cur_L // b[idx]), cur_L % b1[idx], idx + 1)
(n, L) = map(int, input().split())
a = list(map(int, input().split()))
b = [2 ** i for i in range(len(a))]
for i in range(len(a)):
	for j in range(len(a) - 1, i, -1):
		if a[j] / b[j] < a[j - 1] / b[j - 1]:
			(a[j], a[j - 1]) = (a[j - 1], a[j])
			(b[j], b[j - 1]) = (b[j - 1], b[j])
ans = solve(a, b, 0, L, 0)
print(ans)


(n, l) = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(1, len(arr)):
	arr[i] = min(arr[i], arr[i - 1] * 2)
for i in range(64):
	arr.append(arr[-1] * 2)
dp = 0
for i in range(64):
	if l >> i & 1:
		dp += arr[i]
	else:
		dp = min(dp, arr[i])
print(dp)


(n, L) = list(map(int, input().split()))
arr = [int(x) for x in input().split()]

def pos(x):
	ans = 0
	while x:
		x //= 2
		ans += 1
	return ans - 1

def solve(ltr):
	if ltr == 0:
		return 0
	val = pos(ltr)
	if val + 1 < n:
		Bmin = min(arr[val + 1:])
	else:
		val = n - 1
		Bmin = 4e+20
	minCost = 4e+20
	amt = 0
	for i in range(val + 1):
		v = arr[i] / 2 ** i
		if v <= minCost:
			minCost = v
			amt = i
	minCost = arr[amt]
	minCost *= ltr // 2 ** amt
	return min(minCost + solve(ltr % 2 ** amt), Bmin)
print(solve(L))


import math

def remove_items(a, removed):
	return [a[i] for i in range(len(a)) if i not in removed]

def refine1(c, v):
	removed = set()
	for i in range(len(c) - 1):
		if i in removed:
			continue
		for j in range(i + 1, len(c)):
			if j in removed:
				continue
			if c[i] / v[i] < c[j] / v[j]:
				removed.add(j)
	return (remove_items(c, removed), remove_items(v, removed))

def refine2(c, v):
	removed = set()
	for i in range(len(c)):
		for j in range(i + 1, len(c)):
			if c[i] >= c[j]:
				removed.add(i)
	return (remove_items(c, removed), remove_items(v, removed))

def result(L, c, v, cutoff):
	ans = 0
	while L > 0:
		if cutoff == 0:
			num = math.ceil(L / v[-1])
			ans += num * c[-1]
			return ans
		num = L // v[-1]
		L -= num * v[-1]
		ans += num * c[-1]
		cutoff -= 1
		v.pop()
		c.pop()
	return ans
(n, L) = map(int, input().split())
c = list(map(int, input().split()))
v = [2 ** i for i in range(n)]
(c, v) = refine1(c, v)
(c, v) = refine2(c, v)
ans = float('inf')
for cutoff in range(len(c)):
	ans = min(ans, result(L, c[:], v[:], cutoff))
print(ans)


(n, L) = map(int, input().split())
c = [int(i) for i in input().split()]
for i in range(n):
	if i > 0:
		c[i] = min(c[i], c[i - 1] * 2)
s = 0
ret = -1
for i in range(n - 1, -1, -1):
	if L > 0:
		cnt = L // 2 ** i
		s += c[i] * cnt
		L %= 2 ** i
		if L == 0:
			continue
		if ret == -1 or s + c[i] < ret:
			ret = s + c[i]
if ret == -1 or s < ret:
	ret = s
print(ret)


(n, L) = map(int, input().split())
P = L

def log(n):
	a = 1
	while a * 2 <= n:
		a *= 2
	return a
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i - 1] * 2, c[i])
for i in range(n - 2, -1, -1):
	c[i] = min(c[i], c[i + 1])
Mark = list(map(int, ('0 ' * n).split()))
d = len(c) - 2
a = 2 ** d
ans = c[-1] * (L // 2 ** (n - 1))
L %= 2 ** (n - 1)
while L != 0:
	while L < a:
		a //= 2
		d -= 1
	Mark[d] = 1
	L -= a
	ans += c[d]
P = 0
for i in range(len(c)):
	if Mark[i] == 1:
		P += c[i]
		continue
	ans -= max(0, P - c[i])
	if P - c[i] > 0:
		P = c[i]
print(ans)


def ev(l, costs):
	s = 0
	for i in range(0, len(costs) - 1):
		s += costs[i] * (l % 2)
		l = l // 2
	s += l * costs[-1]
	return s
(n, l) = map(int, input().split())
cs = list(map(int, input().split()))
for i in range(1, n):
	if cs[i - 1] * 2 < cs[i]:
		cs[i] = 2 * cs[i - 1]
res = ev(l, cs)
for i in range(0, 31):
	if l // 2 ** i % 2 == 1:
		continue
	res = min(res, ev((l // 2 ** i + 1) * 2 ** i, cs))
print(res)


(n, l) = map(int, input().split())
m = [0] + list(map(int, input().split()))
for i in range(2, n + 1):
	m[i] = min(m[i], m[i - 1] * 2)
ans = 10 ** 18
z = 1
k = 0
while z < n + 1:
	k += l // 2 ** (n - z) * m[-z]
	l = l % 2 ** (n - z)
	if l == 0:
		ans = min(ans, k)
		break
	else:
		ans = min(ans, k + m[-z])
	z += 1
print(ans)


(n, l) = input().split()
n = int(n)
l = int(l)
c = list(map(int, input().strip().split()))[:n]
pow2 = [1]
for i in range(n - 1):
	pow2.append(2 * pow2[i])
for i in range(n - 1):
	c[i + 1] = min(c[i + 1], 2 * c[i])

def cost(pos, money):
	if pos == 0:
		return c[pos] * money
	take = int(money / pow2[pos])
	ret = c[pos] * take
	money -= pow2[pos] * take
	if money == 0:
		return ret
	return c[pos] * take + min(cost(pos - 1, money), c[pos])
print(cost(n - 1, l))


inf = 10 ** 20
dp = [inf] * 31
(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(n):
	dp[i] = a[i]
for i in range(1, 31):
	c = 1
	for j in range(i, -1, -1):
		dp[i] = min(dp[i], dp[j] * c)
		c *= 2
m = bin(m)[2:]
an = inf
for i in range(len(m), n + 1):
	an = min(an, dp[i])
tt = 0
p = len(m) - 1
for i in m:
	if i == '1':
		tt += dp[p]
	else:
		tt += dp[p]
		an = min(tt, an)
		tt -= dp[p]
	p -= 1
an = min(tt, an)
print(an)


(n, L) = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(0, n - 1):
	a[i + 1] = min(a[i + 1], 2 * a[i])
s = 0
ans = 1000 ** 1000
for i in range(n - 1, -1, -1):
	d = L // (1 << i)
	s += d * a[i]
	L -= d << i
	ans = min(ans, s + (L > 0) * a[i])
print(ans)


(n, l) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
b[0] = a[0]
if n == 1 and l == 1:
	print(a[0])
else:
	for i in range(1, n):
		b[i] = min(a[i], b[i - 1] * 2)
		if b[i] < b[i - 1]:
			for j in range(i):
				b[j] = min(b[i], b[j])
	c = [0] * n
	c[0] = 1
	s = 0
	z = 100000000000000000000
	for i in range(1, n):
		c[i] = c[i - 1] * 2
	while l > c[n - 1]:
		s += b[n - 1] * (l // c[n - 1])
		l = l % c[n - 1]
	while l > 0:
		for i in range(1, n):
			if l <= c[i] and l >= c[i - 1]:
				z = min(z, s + b[i])
				l -= c[i - 1]
				s += b[i - 1]
	print(min(z, s))


import sys
MAXN = 31
INF = 2 ** 62 - 1 + 2 ** 62

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

def read():
	ints = get_ints()
	n = ints[0]
	L = ints[1]
	cost = get_ints()
	assert len(cost) == n, 'MUST have the same number of elements'
	return (n, L, cost)

def tobinary(L, minn):
	assert L > 0, 'only handle L > 0'
	digits = []
	while L > 0:
		digits.append(L % 2)
		L = L // 2
	digits.append(0)
	while len(digits) < minn:
		digits.append(0)
	return digits

def get_each_min_cost(cost, length):
	min_cost = []
	for i in range(length):
		min_c = INF
		max_len = min(i + 1, len(cost))
		for j in range(max_len):
			min_c = min((1 << i - j) * cost[j], min_c)
		min_cost.append(min_c)
	return min_cost

def solve(digits, min_cost):
	length = len(digits)
	d = [0] * length
	d[0] = min_cost[0] if digits[0] == 1 else 0
	for t in range(1, length):
		if digits[t] == 1:
			d[t] = min(d[t - 1] + min_cost[t], min_cost[t] * 2)
		else:
			d[t] = min(d[t - 1], min_cost[t])
	return d[-1]
(n, L, cost) = read()
digits = tobinary(L, len(cost) + 1)
min_cost = get_each_min_cost(cost, len(digits))
print(solve(digits, min_cost))


import math
(n, L) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(n - 1):
	c[i + 1] = min(c[i + 1], c[i] * 2)
ans = 2e+18 + 1
mid = 0
for i in range(n - 1, -1, -1):
	need = L >> i
	mid += need * c[i]
	L -= need << i
	ans = min(ans, mid + (L > 0) * c[i])
print(ans)


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i], 2 * c[i - 1])
for i in range(n, 32):
	c.append(2 * c[-1])
s = 0
for i in range(32):
	v = 1 << i
	if v & l:
		s += c[i]
	elif c[i] < s:
		s = c[i]
print(s)


(n, L) = map(int, input().split())
c = [*map(int, input().split())]
rational = [True] * n
for i in range(n):
	for j in range(n):
		if i < j and c[i] >= c[j]:
			rational[i] = False
		if i < j and c[i] * 2 ** (j - i) <= c[j]:
			rational[j] = False

def dfs(i, L):
	if i == 0:
		return L * c[0]
	elif rational[i]:
		Li = 2 ** i
		if Li >= L:
			return min(c[i], dfs(i - 1, L))
		else:
			return L // Li * c[i] + dfs(i, L % Li)
	else:
		return dfs(i - 1, L)
print(dfs(n - 1, L))


def GETBIT(x, bit):
	return x >> bit & 1
(n, volume) = map(int, input().split())
c = list(map(int, input().split()))
rs = 1000000000000000000
pos = 30
s = 0
while pos >= 0:
	if 1 << pos >= volume and pos <= n - 1:
		rs = min(rs, c[pos])
	if GETBIT(volume, pos) == 1:
		for j in range(min(pos + 1, n)):
			rs = min(rs, s + (1 << pos + 1 - j) * c[j])
		if pos < len(c) - 1:
			rs = min(rs, s + c[pos + 1])
		mi = 1000000000000000000
		for j in range(min(pos + 1, n)):
			mi = min(mi, (1 << pos - j) * c[j])
		s += mi
	else:
		for j in range(min(pos + 1, n)):
			rs = min(rs, s + (1 << pos - j) * c[j])
	pos -= 1
rs = min(rs, s)
print(rs)


def validator(chunk: int) -> int:
	pass
n: int
L: int
bottle_L: int
total: int = 0
answer: int = float('inf')
(n, L) = list(map(int, input().split()))
costs: list = list(map(int, input().split()))
for i in range(len(costs) - 1):
	costs[i + 1] = min(costs[i + 1], 2 * costs[i])
for i in range(len(costs) - 1, -1, -1):
	bottle_L = L // (1 << i)
	total += bottle_L * costs[i]
	L -= bottle_L << i
	if L > 0:
		answer = min(answer, total + costs[i])
	else:
		answer = min(answer, total)
print(answer)


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
for i in range(1, n):
	l[i] = min(l[i], 2 * l[i - 1])
c = l + [l[-1] * 2 ** i for i in range(1, 32)]

def cost(x):
	ans = 0
	for i in range(32):
		if x & 1 << i:
			ans += c[i]
	return ans
ans = cost(m)
for i in range(32):
	if not m & 1 << i:
		tmp = m - m % (1 << i) + (1 << i)
		ans = min(ans, cost(tmp))
print(ans)


(n, L) = map(int, input().split(' '))
c = list(map(int, input().split(' ')))
min_cost = [c[0]]
for i in range(n - 1):
	min_cost.append(min([min_cost[i] * 2, c[i + 1]]))
sumval = 0
ans = float('inf')
for i in range(n - 1, -1, -1):
	times = L // (1 << i)
	sumval += times * min_cost[i]
	L %= 1 << i
	if L == 0:
		ans = min([ans, sumval])
	else:
		ans = min([ans, sumval + min_cost[i]])
print(ans)


(n, L) = map(int, input().split())
c = list(map(int, input().split())) + [0] * (30 - n)
for i in range(len(c) - 1):
	if c[i + 1] > 2 * c[i]:
		c[i + 1] = 2 * c[i]
	if c[i + 1] == 0:
		c[i + 1] = 2 * c[i]
k = 0
litres = 0
cost = 0
x = L
while k < 30:
	if c[k] <= cost:
		cost = c[k]
		litres = pow(2, k)
	if x & 1:
		cost += c[k]
		litres += pow(2, k)
	x >>= 1
	k += 1
print(cost)


(n, L) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
costPerLemon = []
ans = 12345678901234567890
for i in range(n):
	costPerLemon.append(c[i] / 2 ** i)
size = n
money = 0
while size > 1:
	target = min(costPerLemon)
	i = costPerLemon.index(target)
	times = int(L / 2 ** i)
	money += c[i] * times
	L -= 2 ** i * times
	ans = min(ans, money + c[i])
	size = i
	while len(costPerLemon) > size:
		costPerLemon.pop(-1)
money += L * c[0]
ans = min(ans, money)
print(ans)


import os
import sys
from io import BytesIO, IOBase
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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

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

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	(n, l) = RL()
	arr = RLL()
	for i in range(n - 1):
		arr[i + 1] = min(arr[i] * 2, arr[i + 1])
	for i in range(n, 32):
		arr.append(arr[-1] * 2)
	res = 0
	for i in range(32):
		if 1 << i & l == 1 << i:
			res += arr[i]
		else:
			res = min(res, arr[i])
	print(res)
main()


from math import floor

def MAX(a, b):
	if a > b:
		return a
	else:
		return b

def MIN(a, b):
	if a < b:
		return a
	else:
		return b
entrada = input()
entrada_str = list(entrada.split(' '))
entrada_int = list(map(int, entrada_str))
n = entrada_int[0]
L = entrada_int[1]
entrada = input()
entrada_str = list(entrada.split(' '))
vetor = list(map(int, entrada_str))
for i in range(n - 1):
	vetor[i + 1] = min(vetor[i + 1], vetor[i] * 2)
x = 0
resposta = 10 ** 18
for i in range(n - 1, -1, -1):
	y = 1 << i
	x += vetor[i] * floor(L / y)
	L = floor(L % y)
	resposta = MIN(resposta, x + (L != 0) * vetor[i])
print(resposta)


(n, l) = map(int, input().split())
p = list(map(int, input().split()))
d = []
d = [[p[i] / 2 ** i, i + 1] for i in range(n)]
d.sort(key=lambda x: x[0])
res = 10 ** 18
q = l
curres = 0
for i in d:
	if i[1] == 1:
		curres += p[i[1] - 1] * q
		res = min(res, curres)
		break
	curb = q // 2 ** (i[1] - 1)
	curres += curb * p[i[1] - 1]
	res = min(res, curres + p[i[1] - 1])
	q %= 2 ** (i[1] - 1)
print(res)


(n, L) = map(int, input().split())
powers = []
fir = 1
for i in range(n):
	powers.append(fir)
	fir *= 2
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(2 * c[i - 1], c[i])
cost = 0
fincost = []
for i in range(n - 1, -1, -1):
	cost += L // powers[i] * c[i]
	L = L % powers[i]
	if L == 0:
		fincost.append(cost)
	else:
		fincost.append(cost + c[i])
print(int(min(fincost)))


(n, l) = tuple(map(int, input().split()))
cost = list(map(int, input().split()))
for i in range(1, n):
	cost[i] = min(cost[i], 2 * cost[i - 1])
(ans, s) = (float('inf'), 0)
for i in range(n - 1, -1, -1):
	litre = 1 << i
	need = l // litre
	s += cost[i] * need
	l = l % litre
	ans = min(ans, s + (l != 0) * cost[i])
print(ans)


from sys import stdin, stdout
sze = 100
INF = float('inf')
(n, l) = map(int, stdin.readline().split())
c = list(map(int, stdin.readline().split()))
may = [1 for i in range(sze)]
for i in range(n - 1, -1, -1):
	for j in range(i):
		if c[i] > c[j] * 2 ** (i - j):
			may[i] = 0
ans = INF
cnt = 0
value = 0
for i in range(n - 1, -1, -1):
	if not may[i]:
		continue
	v = l - value
	if not v % 2 ** i:
		ans = min(ans, cnt + v * c[i] // 2 ** i)
	else:
		ans = min(ans, cnt + (v // 2 ** i + 1) * c[i])
	cnt += v // 2 ** i * c[i]
	value += v // 2 ** i * 2 ** i
stdout.write(str(ans))


(n, l) = [int(x) for x in input().strip().split()]
c = [int(x) for x in input().strip().split()]
tc = 0
for i in range(1, len(c)):
	c[i] = min(c[i], 2 * c[i - 1])
for i in range(32):
	c.append(c[-1] * 2)
tc = 0
bl = bin(l)[:1:-1]
bl += '0' * (len(c) - len(bl) - 1)
for i in range(len(bl)):
	if bl[i] == '1':
		tc += c[i]
	else:
		tc = min(tc, c[i])
print(tc)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, l) = map(int, input().split())
	c = list(map(int, input().split()))
	(mi, su) = (4 * 10 ** 18, 0)
	for i in range(1, n):
		c[i] = min(c[i], 2 * c[i - 1])
	for i in range(n - 1, -1, -1):
		y = 1 << i
		z = l // y
		su += z * c[i]
		l -= z * y
		mi = min(mi, su + (l != 0) * c[i])
	print(mi)
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, lt) = (int(x) for x in input().split())
costs = [int(x) for x in input().split()]
c1 = costs[0]
costs = costs[1:]
maincost = lt * c1
mainlen = lt
remcost = 0
currv = 1
for c in costs:
	currv *= 2
	nmainl = lt - lt % currv
	prevc = maincost / mainlen if maincost != 0 else 0
	if prevc > c / currv:
		nremlen = mainlen - nmainl
		remcost += maincost * nremlen // mainlen
		mainlen = nmainl
		maincost = mainlen * c // currv
	if remcost > c:
		remcost = c
print(maincost + remcost)


(n, L) = [int(a) for a in input().strip().split()]
costs_n = [int(a) for a in input().strip().split()]
costs = [0 for i in range(31)]
for i in range(n):
	costs[i] = costs_n[i]
for i in range(1, n):
	costs[i] = min(costs[i], costs[i - 1] * 2)
for i in range(n - 2, -1, -1):
	costs[i] = min(costs[i], costs[i + 1])
for i in range(n, 31):
	costs[i] = costs[i - 1] * 2
res = 0
for i in range(31):
	if res > costs[i]:
		res = costs[i]
	if L & 2 ** i:
		res += costs[i]
print(str(res))


def main():
	(n, needed) = map(int, input().split())
	costs = list(map(int, input().split()))
	done = False
	while not done:
		done = True
		cur = costs[0]
		for (i, x) in enumerate(costs[1:], 1):
			cur <<= 1
			if cur < x:
				costs[i] = cur
				done = False
			else:
				cur = x
		for i in range(n - 2, -1, -1):
			if costs[i] > costs[i + 1]:
				costs[i] = costs[i + 1]
				done = False

	def calc(total):
		result = 0
		for i in range(31):
			if total & 1 << i:
				if i < n:
					result += costs[i]
				else:
					result += costs[-1] << i - n + 1
		return result
	result = calc(needed)
	for i in range(30, -1, -1):
		x = (needed >> i | 1) << i
		if x >= needed:
			result = min(result, calc(x))
	print(result)
try:
	while True:
		main()
except EOFError:
	pass


import math
(n, l) = map(int, input().split())
lis = list(map(int, input().split()))
for i in range(n):
	lis[i] = (lis[i] / 2 ** i, 2 ** i, lis[i])
lis.sort(key=lambda e: e[0])
s1 = 0
s2 = 0
m = 10 ** 18
i = 0
while l > 0:
	s1 = s2 + math.ceil(l / lis[i][1]) * lis[i][2]
	m = min(m, s1)
	s2 += l // lis[i][1] * lis[i][2]
	l -= l // lis[i][1] * lis[i][1]
	i += 1
m = min(m, s2)
print(m)


(types, volume) = map(int, input().split())
(c, s) = (0, 10 ** 18)
a = list(map(int, input().split()))
for i in range(len(a) - 1):
	a[i + 1] = min(a[i + 1], a[i] * 2)
for i in range(types - 1, -1, -1):
	d = 1 << i
	c += a[i] * (volume // d)
	volume %= d
	s = min(s, c + (volume != 0) * a[i])
print(s)


read = lambda : map(int, input().split())
(n, L) = read()
c = list(read())
for _ in range(5):
	for i in range(n - 2, -1, -1):
		c[i] = min(c[i], c[i + 1])
	for i in range(1, n):
		c[i] = min(c[i], c[i - 1] * 2)
cur = 0
ans = 10 ** 30
L1 = L
for i in range(n - 1, -1, -1):
	cnt = L1 // 2 ** i
	cur += cnt * c[i]
	ans = min(ans, cur + c[i])
	L1 -= cnt * 2 ** i
ans = min(ans, cur)
for i in range(n - 1, -1, -1):
	if 2 ** i >= L:
		ans = min(ans, c[i])
print(ans)


(n, L) = [int(k) for k in input().split(' ') if k]
dp = [int(k) for k in input().split(' ') if k]
for i in range(1, n):
	dp[i] = min(2 * dp[i - 1], dp[i])
binary = []
while L != 0:
	binary.append(L % 2)
	L //= 2
while len(dp) < len(binary):
	dp.append(2 * dp[-1])

def minify(p):
	result = 999999999999999999999999999
	for i in range(p + 1, len(dp)):
		result = min(result, dp[i])
	if p == 0:
		return min(result, dp[p] if binary[p] else 0)
	return min(result, (dp[p] if binary[p] else 0) + minify(p - 1))
print(minify(len(binary) - 1))


n = input().split()
l = int(n[1])
n = int(n[0])
c = input().split()
cperl = []
for i in range(n):
	c[i] = int(c[i])
	cperl.append([c[i] / 2 ** i, 2 ** i, i])
cperl.sort()
f = False
nl = [0]
nc = [0]
i = 0
while not f:
	p = nl[i]
	nl[i] += cperl[i][1] * ((l - p) // cperl[i][1])
	nc[i] += c[cperl[i][2]] * ((l - p) // cperl[i][1])
	if nl[i] == l:
		f = True
		break
	nl.append(nl[i])
	nc.append(nc[i])
	nl[i] += cperl[i][1]
	nc[i] += c[cperl[i][2]]
	i += 1
	if i == n:
		break
print(min(nc))


s = input()
s1 = s.split()
tot = int(s1[1])
s = input()
s1 = s.split()
l = [int(i) for i in s1]
avg = [[l[i] / 2 ** i, i] for i in range(len(l))]
avg.sort()
cost = 0
i = 0
d = {}

def fun(i, tot):
	if i == len(avg):
		return 100000000.0
	elif (i, tot) in d:
		return d[i, tot]
	elif tot % 2 ** avg[i][1] == 0:
		return tot // 2 ** avg[i][1] * l[avg[i][1]]
	else:
		a = (tot // 2 ** avg[i][1] + 1) * l[avg[i][1]]
		b = tot // 2 ** avg[i][1] * l[avg[i][1]] + fun(i + 1, tot % 2 ** avg[i][1])
		d[i, tot] = min(a, b)
		return min(a, b)
print(fun(0, tot))


import math
(n, l) = map(int, input().split())
ll = l
cost = list(map(int, input().split()))
min_cost = [0] * n
min_cost[0] = cost[0]
for i in range(1, n):
	min_cost[i] = min(min_cost[i - 1] * 2, cost[i])
ans = 0
realans = 10 ** 25
for i in range(n - 1, -1, -1):
	if 2 ** i >= l:
		realans = min(realans, ans + min_cost[i])
	else:
		times = l // 2 ** i
		ans += min_cost[i] * times
		l -= 2 ** i * times
		if l == 0:
			realans = min(realans, ans)
		else:
			realans = min(realans, ans + min_cost[i])
	if l <= 0:
		break
print(realans)


(n, l) = map(int, input().split())
d = 32 * [10737418240000000000]
m = [10737418240000000000]
c = list(map(int, input().split()))
d[0] = c[0]
if n <= 30:
	for t in range(n, 32):
		c.append(1073741824000000000)
for t in range(32):
	if t != 0:
		if c[t] <= 2 * d[t - 1]:
			d[t] = c[t]
		else:
			d[t] = 2 * d[t - 1]
x = len(bin(l)) - 2
ans = 0
cur = 0
s = bin(l)[2:]
for t in range(x):
	if s[t] == '1':
		ans += d[x - int(t) - 1]
	else:
		cur = ans + d[x - int(t) - 1]
		m.append(cur)
print(min(ans, min(m), min(d[x:])))


from sys import maxsize
(n, l) = map(int, input().split())
cost = list(map(int, input().split()))
min_rubles = 0
prev = maxsize
for i in range(31):
	if i < n:
		prev = min(2 * prev, cost[i])
	else:
		prev *= 2
	if l & 2 ** i:
		min_rubles += prev
	else:
		min_rubles = min(min_rubles, prev)
print(min_rubles)


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
v = [2 ** i for i in range(len(c))]
for i in range(n - 1):
	c[i + 1] = min(c[i + 1], c[i] * 2)
s = 0
ans = 100 ** 10
for i in range(n - 1, -1, -1):
	d = l // (1 << i)
	s += d * c[i]
	l -= d << i
	ans = min(ans, s + (l > 0) * c[i])
print(ans)


from math import *
(n, l) = map(int, input().split())
c = list(map(int, input().split()))
d = []
for i in range(n):
	d += [c[i] * (1 << n - 1 - i)]
cur = 0
ans = -1
m = n - 1
while l > 0:
	for i in range(m):
		if d[i] < d[m]:
			m = i
	temp = cur + ceil(l / (1 << m)) * c[m]
	cur += l // (1 << m) * c[m]
	if temp < ans or ans == -1:
		ans = temp
	l = l % (1 << m)
	m -= 1
print(ans)


read = lambda : map(int, input().split())
(n, L) = read()
c = list(read())
for i in range(n):
	for j in range(i + 1, n):
		p = c[i] * (1 << j - i)
		c[j] = min(c[j], p)
while len(c) <= 30:
	c.append(c[-1] * 2)
ans = c[-1]
s = 0
for i in range(30, -1, -1):
	if L & 1 << i > 0:
		s += c[i]
	else:
		ans = min(ans, s + c[i])
ans = min(ans, s)
print(ans)


(n, li) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(n - 1):
	if c[i] * 2 < c[i + 1]:
		c[i + 1] = c[i] * 2
for i in range(n - 2, -1, -1):
	if c[i] > c[i + 1]:
		c[i] = c[i + 1]
i = n - 1
ans = 0
a = []
while li > 0:
	ans += c[i] * (li >> i)
	li %= 2 ** i
	if li < 2 ** i:
		a.append(ans + c[i])
	i -= 1
a.append(ans)
print(min(a))


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
best = [(c[i] / (1 << i), i) for i in range(0, n)]
best.sort()
cost = 0
costs = [0] * n
for i in range(0, n):
	(a, b) = best[i]
	q = L // (1 << b)
	L -= q * (1 << b)
	cost += q * c[b]
	if L > 0:
		costs[i] = cost + c[b]
	else:
		costs[i] = cost
print(min(min(costs), cost))


(n, L) = map(int, input().split(' '))
a = [int(x) for x in input().split()]
for i in range(1, n):
	a[i] = min(a[i], 2 * a[i - 1])
minans = 2 * 10 ** 18
ans = 0
for i in range(n - 1, -1, -1):
	h = L // (1 << i)
	ans += h * a[i]
	L -= h * (1 << i)
	minans = min(minans, ans + a[i])
print(min(ans, minans))


import sys
input = sys.stdin.readline
import copy
from math import *
(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
dp = [0 for i in range(65)]
for i in range(n):
	dp[i] = min(a[i:])
	for j in range(i):
		dp[i] = min(dp[i], 2 ** (i - j) * a[j])
for i in range(n, 65):
	dp[i] = dp[n - 1] * 2 ** (i - n + 1)
b = list(bin(m)[2:])[::-1]
c = 0
for i in range(len(b)):
	if b[i] == '1':
		c += dp[i]
	if b[i] == '0':
		c = min(c, dp[i])
print(min(c, dp[len(b)]))


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
v = [2 ** i for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if v[i] * c[j] < v[j] * c[i]:
			(c[i], c[j]) = (c[j], c[i])
			(v[i], v[j]) = (v[j], v[i])
(lo, hi) = (1, int(1e+18))
while lo < hi:
	md = (lo + hi) // 2
	r = md
	l = 0
	for i in range(n):
		k = r // c[i]
		r -= k * c[i]
		l += k * v[i]
		if r == 0:
			break
	if l >= L:
		hi = md
	else:
		lo = md + 1
print(lo)


(n, l) = [int(k) for k in input().split()]
w = [int(k) for k in input().split()]
w = [[2 ** k, w[k]] for k in range(n)]
w.sort(key=lambda x: x[1] * 2 ** 30 // x[0])
res = 0
c = 0
new = []
while l > 0:
	if l >= w[c][0]:
		res += l // w[c][0] * w[c][1]
		l = l % w[c][0]
		if l != 0:
			new.append(res + w[c][1])
		else:
			new.append(res)
	else:
		new.append(res + w[c][1])
	c += 1
print(sorted(new)[0])


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i], c[i - 1] * 2)
for i in range(30):
	c.append(c[-1] * 2)
r = 0
for i in range(31):
	if L >> i & 1:
		r += c[i]
	else:
		r = min(r, c[i])
print(r)


def f(bs):
	return int(bs, 2) // (1 << n - 1) * a[-1] + sum((a[i] for i in range(min(n - 1, len(bs))) if bs[-i - 1] == '1'))
(n, x) = map(int, input().split())
(*a,) = map(int, input().split())
for i in range(1, n):
	a[i] = min(a[i], 2 * a[i - 1])
bx = '0' * n + bin(x)[2:]
ans = f(bx)
for i in range(len(bx)):
	if bx[i] == '0':
		ans = min(ans, f(bx[:i] + '1' + '0' * (len(bx) - i - 1)))
print(ans)


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
p = [10 ** 18] * 31
p[0] = c[0]
for i in range(1, 31):
	if i < n:
		p[i] = c[i]
	for j in range(i):
		p[i] = min(p[i], p[j] * 2 ** (i - j))
s = bin(L)[::-1][:-2]
ans = 0
for i in range(len(s)):
	if s[i] == '1':
		ans += p[i]
for i in range(len(s), 31):
	ans = min(ans, p[i])
s = bin(L)[2:]
cur = p[len(s) - 1]
for i in range(1, len(s)):
	if s[i] == '1':
		cur += p[len(s) - i - 1]
		continue
	if s[i + 1:].count('1'):
		ans = min(ans, cur + p[len(s) - i - 1])
print(ans)


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

def get_cost(num):
	res = 0
	for i in range(32):
		if num & 1 << i:
			res += cs[i]
	return res
(n, l) = R()
cs = list(R())
for i in range(1, 32):
	if i >= len(cs):
		cs.append(2 * cs[i - 1])
	elif cs[i] > 2 * cs[i - 1]:
		cs[i] = 2 * cs[i - 1]
res = get_cost(l)
while l <= 1 << 31:
	res = min(res, get_cost(l))
	l += l & -l
print(res)


import sys
input = sys.stdin.readline
(n, L) = map(int, input().split())
c = list(map(int, input().split()))
a = [c[0]]
for i in range(1, 31):
	cand = [a[-1] * 2]
	if i < n:
		cand.append(c[i])
	a.append(min(cand))
ans = []
sum = 0
for i in reversed(range(31)):
	if L <= 1 << i:
		ans.append(sum + a[i])
	else:
		L -= 1 << i
		sum += a[i]
print(min(ans))


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i], c[i - 1] * 2)
x = 0
d = l
for sht in range(n - 1):
	if l >> sht & 1:
		x += c[sht]
		d -= 2 ** sht
x += c[-1] * (d // 2 ** (n - 1))
ans = x
u = '0' * (n - len(str(bin(l)[2:]))) + str(bin(l)[2:])
uu = len(u)
for j in range(uu):
	if u[j] == '1':
		continue
	m = u[:j] + '1' + '0' * (uu - 1 - j)
	m = int(m, 2)
	mm = m
	x = 0
	for sht in range(n - 1):
		if m >> sht & 1:
			x += c[sht]
			m -= 2 ** sht
	x += c[-1] * (m // 2 ** (n - 1))
	x = min(x, c[-1] * ((mm - 1) // 2 ** (n - 1) + 1))
	ans = min(ans, x)
ans = min(ans, c[-1] * ((l - 1) // 2 ** (n - 1) + 1))
print(ans)


import sys
(n, l) = map(int, input().split())
cs = list(map(int, input().split()))
cbs = [(c / 2 ** i, c, 2 ** i) for (i, c) in enumerate(cs)]
cbs.sort()

def solve(i, r):
	(_, c, q) = cbs[i]
	rem = r % q
	if rem == 0:
		return r // q * c
	a = (r // q + 1) * c
	if i + 1 == len(cbs):
		return a
	b = r // q * c + solve(i + 1, rem)
	return min(a, b)
print(solve(0, l))


from itertools import permutations
MOD = 10 ** 9 + 7

def find_best(c):
	n = 2 ** len(c)
	best_c = c[0] * n
	best_i = 0
	for (i, ci) in enumerate(c):
		if n // 2 ** i * c[i] < best_c:
			best_c = n // 2 ** i * c[i]
			best_i = i
	return best_i

def main():
	(n, l) = [int(c) for c in input().split(' ')]
	c = [int(c) for c in input().split(' ')]
	ans = []
	cur_ans = 0
	while l:
		ind = find_best(c[:n])
		vol = 2 ** ind
		cnt = l // vol
		l %= vol
		cur_ans += cnt * c[ind]
		ans.append(cur_ans + (l % vol and c[ind] or 0))
		n = ind
	print(min(ans))
while 1:
	main()
	break


(variants, volume) = map(int, input().split())
cost = [int(x) for x in input().split()]
for i in range(1, variants):
	cost[i] = min(cost[i], 2 * cost[i - 1])
while len(cost) < 32:
	cost.append(cost[-1] * 2)
ans = 0
binaryRepresentation = list(bin(volume)[2:])
while len(binaryRepresentation) < 32:
	binaryRepresentation = ['0'] + binaryRepresentation
binaryRepresentation.reverse()
for i in range(len(cost)):
	if binaryRepresentation[i] == '1':
		ans += cost[i]
	else:
		ans = min(ans, cost[i])
print(ans)


(n, L) = list(map(int, input().split()))
c = list(map(int, input().split()))
total_max = pow(2, n - 1)
cost_dp = [i for i in c]
for i in range(1, n):
	if 2 * cost_dp[i - 1] < cost_dp[i]:
		cost_dp[i] = 2 * cost_dp[i - 1]

def solve(L, ind):
	if L == 0:
		return 0
	if ind < 0:
		return 10000000000.0
	if pow(2, ind) > L:
		cost = min(cost_dp[ind], solve(L, ind - 1))
	else:
		cost = min(L // pow(2, ind) * cost_dp[ind] + solve(L % pow(2, ind), ind - 1), (L // pow(2, ind) + 1) * cost_dp[ind])
	return cost
cost = solve(L, n - 1)
print(cost)


(n, L) = map(int, input().split())
pr = list(map(int, input().split()))
res = 0
poss = []
ber = [(pr[i] / 2 ** i, i) for i in range(n)]
ber.sort()
for i in range(n):
	d = L // 2 ** ber[i][1]
	res += d * pr[ber[i][1]]
	L -= d * 2 ** ber[i][1]
	if L == 0:
		poss.append(res)
	poss.append(res + pr[ber[i][1]])
print(min(poss))


import heapq
(n, L) = [int(x) for x in input().split()]
costs = [int(x) for x in input().split()]

def heuristic(remaining, lowest_cost_per_liter):
	return remaining * lowest_cost_per_liter

def neighbors(remaining, costs):
	(lowest_cost_per_liter, cost, power) = min(((cost / 2 ** power, cost, power) for (power, cost) in enumerate(costs) if 2 ** power <= remaining))
	new_liters = 2 ** power
	new_cost = cost * (remaining // new_liters)
	new_remaining = remaining % new_liters
	yield (new_remaining, new_cost)
	lowest_cost_total = min((cost for (power, cost) in enumerate(costs) if 2 ** power >= remaining), default=None)
	if lowest_cost_total is not None:
		yield (0, lowest_cost_total)

def a_star(L, costs):
	lowest_cost_per_liter = min((cost / 2 ** power for (power, cost) in enumerate(costs)))
	g_score = {}
	g_score[L] = 0
	f_score = {}
	f_score[L] = heuristic(L, lowest_cost_per_liter)
	open_queue = [(f_score[L], L)]
	open_set = {L}
	while len(open_queue) > 0:
		(current_f, current_remaining) = heapq.heappop(open_queue)
		if current_remaining == 0:
			return g_score[0]
		if current_remaining not in open_set:
			continue
		open_set.remove(current_remaining)
		for (new_remaining, cost) in neighbors(current_remaining, costs):
			new_g_score = g_score[current_remaining] + cost
			if new_remaining not in g_score or new_g_score < g_score[new_remaining]:
				g_score[new_remaining] = new_g_score
				f_score[new_remaining] = new_g_score + heuristic(new_remaining, lowest_cost_per_liter)
				heapq.heappush(open_queue, (f_score[new_remaining], new_remaining))
				if new_remaining not in open_set:
					open_set.add(new_remaining)
	return None
(lowest_cost_per_liter, cost, power) = min(((cost / 2 ** power, cost, power) for (power, cost) in enumerate(costs)))
liters = 2 ** power
start_cost = cost * (L // liters)
L = L % liters
print(start_cost + a_star(L, costs))


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
L = format(L, 'b')[::-1]
dp = [0] * (len(L) + 1)
l = []
for i in range(len(L)):
	if i < n:
		l.append(c[i])
	m = min(l)
	if m < dp[i]:
		dp[i + 1] = m
	else:
		dp[i + 1] = dp[i]
	if L[i] == '1':
		dp[i + 1] += m
	for j in range(len(l)):
		l[j] *= 2
ans = dp[-1]
for i in range(len(L), n):
	ans = min(ans, c[i])
print(ans)


import sys
import math
import collections
from pprint import pprint as pp
mod = 1000000007
MAX = 10 ** 19

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat
(n, l) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i], 2 * c[i - 1])
r = []
for i in range(n):
	r.append(c[i] / 2 ** i)
ans = MAX
temp = 0
for i in range(n - 1, -1, -1):
	lit = 2 ** i
	temp += c[i] * (l // lit)
	l %= lit
	ans = min(ans, temp + (l > 0) * c[i])
print(ans)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def check(n, x, l):
	tot = 0
	while 1:
		flag = 1
		i = 0
		while i < len(v):
			c = int(v[i][1] * v[i][0])
			if c <= x:
				cnt = x // c
				x -= cnt * c
				tot += v[i][1] * cnt
				flag = 0
				break
			else:
				i += 1
		if tot >= l:
			return 1
		if flag:
			break
	return 0

def getkey(item):
	return item[0]

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
v = []
t = 1
for tt in range(t):
	(n, l) = map(int, sys.stdin.readline().split(' '))
	aa = list(map(int, sys.stdin.readline().split(' ')))
	for i in range(n):
		val = 1 << i
		a = aa[i]
		v.append([a / val, val])
	v = sorted(v, key=getkey)
	ans = 10000000000000000000000000000000
	low = 0
	high = ans
	while low <= high:
		mid = (low + high) // 2
		if check(n, mid, l):
			high = mid - 1
			ans = min(ans, mid)
		else:
			low = mid + 1
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
import math
pre = [z[0]]
for i in range(1, len(z)):
	pre.append(min(z[i], 2 * pre[-1]))
q = [1]
for i in range(len(z) - 1):
	q.append(q[-1] * 2)
cost = 0
p = len(q) - 1
pos = []
mini = math.inf
while 1:
	if b >= q[p]:
		nos = b // q[p]
		rem = b % q[p]
		cost += nos * pre[p]
		if rem == 0:
			print(min(mini, cost))
			break
		else:
			pos.append(cost + pre[p])
			mini = min(mini, min(pos))
			b = rem
			p = p - 1
	else:
		pos.append(cost + pre[p])
		p = p - 1
		mini = min(mini, min(pos))


(n, L) = map(int, input().split())
c = list(map(int, input().split()))
while len(c) < 32:
	c.append(c[-1] * 2)
n = 32
for i in range(n):
	for j in range(i + 1, n):
		k = 2 ** (j - i)
		if k * c[i] < c[j]:
			c[j] = k * c[i]
ans = 0
for i in range(n):
	if L & 1 << i:
		ans = min(ans + c[i], 2 * c[i])
	else:
		ans = min(ans, c[i])
print(ans)


(n, l) = map(int, input().split())
ci = list(map(int, input().split()))
mini = ci[-1]
for i in range(n - 2, -1, -1):
	if ci[i] < mini:
		mini = ci[i]
	else:
		ci[i] = mini
for i in range(1, n):
	ci[i] = min(ci[i], ci[i - 1] * 2)
for i in range(n, 34):
	ci += [ci[-1] * 2]
s = bin(l)[2:]
ans = 0

def rec(i):
	if i < 1:
		return 0
	return min(rec(i - 1) + ci[i - 1] * int(s[-i]), ci[i])
print(rec(len(s)))


(n, L) = [int(i) for i in input().split()]
L = list(bin(L).replace('0b', ''))
L.reverse()
c = [int(i) for i in input().split()]
l = 0
C = []
for i in range(len(L)):
	c_l = {}
	for j in range(n):
		if j > i:
			c_l[c[j] / 2 ** i] = j
		elif j <= i:
			c_l[c[j] / 2 ** j] = j
	c_ls = list(c_l.keys())
	m = c_l[min(c_ls)]
	if m > i:
		Ci = c[m]
	if m <= i:
		Ci = c[m] / 2 ** m * 2 ** i
	Cc1 = l + int(Ci * int(L[i]))
	c_l.clear()
	for j in range(n):
		if j > i + 1:
			c_l[c[j] / 2 ** (i + 1)] = j
		elif j <= i + 1:
			c_l[c[j] / 2 ** j] = j
	c_ls = list(c_l.keys())
	m = c_l[min(c_ls)]
	if m > i + 1:
		Ci = c[m]
	if m <= i + 1:
		Ci = c[m] / 2 ** m * 2 ** (i + 1)
	Cc2 = int(Ci * int(L[i]))
	x = min(Cc1, Cc2)
	l = l + x
	if x == 0:
		C.append(l)
	else:
		C.append(x)
		l = x
print(int(C[-1]))


(n, L) = map(int, input().split())
c = input().split()
for i in range(n):
	c[i] = int(c[i])
	if i > 0 and c[i - 1] * 2 < c[i]:
		c[i] = c[i - 1] * 2
ans = c[0] * L
cur = 0
for i in range(n - 1, -1, -1):
	ans = min(ans, cur + (L + 2 ** i - 1) // 2 ** i * c[i])
	cur += c[i] * (L // 2 ** i)
	L -= 2 ** i * (L // 2 ** i)
print(ans)


import os
import sys
import time
from io import BytesIO, IOBase
import heapq
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def main():
	(n, l) = map(int, input().split())
	c = list(map(int, input().split()))
	dp = [0] * 31
	dp[0] = c[0]
	for i in range(1, 31):
		dp[i] = dp[i - 1] * 2
		if i < n:
			dp[i] = min(dp[i], c[i])
	(curr, ret, best, final) = (1 << 30, 0, float('inf'), float('inf'))
	for i in range(30, -1, -1):
		if l >= curr:
			l -= curr
			final = min(final, ret + best)
			ret += dp[i]
		else:
			best = min(best, dp[i])
		curr //= 2
	print(min(ret, final))
start_time = time.time()
main()
print(f'Execution time: {time.time() - start_time} s', file=sys.stderr)


(n, L) = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(1, n):
	a[i] = min(a[i], a[i - 1] * 2)
ans = float('inf')
cos = 0
for i in range(n - 1, -1, -1):
	tem = L // (1 << i)
	cos += tem * a[i]
	L -= tem << i
	if L > 0:
		ans = min(ans, cos + a[i])
	else:
		ans = min(ans, cos)
print(ans)


import math
(n, L) = list(map(int, input().split()))
l = list(map(int, input().split()))
for i in range(1, n):
	l[i] = min(l[i], 2 * l[i - 1])
ans = float('inf')
tot = 0
for i in range(n - 1, -1, -1):
	temp = L // 2 ** i
	L -= temp * 2 ** i
	tot += temp * l[i]
	ans = min(ans, tot + math.ceil(L / 2 ** i) * l[i])
print(ans)


(types, volume) = map(int, input().split())
(cost, payment) = (0, 10 ** 18)
a = list(map(int, input().split()))
for i in range(len(a) - 1):
	a[i + 1] = min(a[i + 1], a[i] * 2)
for i in range(types - 1, -1, -1):
	d = 1 << i
	cost += a[i] * (volume // d)
	volume %= d
	payment = min(payment, cost + (volume != 0) * a[i])
print(payment)


import math

def getCost(L):
	global n, b, c
	if L == 0:
		return 0
	p = math.floor(math.log(L, 2)) + 1
	ind = b.index(min(b[:p]))
	fill = L // 2 ** ind
	rem = L - fill * 2 ** ind
	cp = c[ind] * fill
	if p < n:
		return min(cp + getCost(rem), min(c[p:]))
	return cp + getCost(rem)
(n, L) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
b = [c[i] / 2 ** i for i in range(n)]
ans = getCost(L)
p = math.floor(math.log(L, 2)) + 1
if p < n:
	ans = min(ans, min(c[p:]))
print(ans)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(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
MAXN = int(100000.0 + 5)

def spf_sieve():
	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, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, x) = int_array()
a = int_array()
cnt = [0] * n
k = x
for i in range(n - 1, -1, -1):
	p = 2 ** i
	cnt[i] += k // p
	k %= p
mnt = a.copy()
for i in range(1, n):
	mnt[i] = min(2 * mnt[i - 1], mnt[i])
ans = 0
for i in range(n):
	ans += mnt[i] * cnt[i]
this = 0
for i in range(n - 1, -1, -1):
	this += (cnt[i] + 1) * mnt[i]
	ans = min(ans, this)
	this -= mnt[i]
print(ans)


def process(n, c):
	for i in range(n, 30 + 1):
		c.append(0)
	for i in range(1, 30 + 1):
		if c[i] == 0:
			c[i] = c[i - 1] * 2
		else:
			c[i] = min(c[i], c[i - 1] * 2)
	mn = c[30]
	for i in range(30, 0 - 1, -1):
		c[i] = min(c[i], mn)
		mn = min(c[i], mn)
	return c

def solve(n, l, c):
	c = process(n, c)
	(case1, case2) = (0, 0)
	for i in range(0, 30 + 1):
		if l & 1 << i != 0:
			case1 += c[i]
	case2 = case1
	res = case1
	for i in range(0, 30 + 1):
		if l & 1 << i != 0:
			case2 -= c[i]
			res = min(res, case2 + c[i + 1])
	return res

def dp009_party_lemonande(n, l, c):
	return solve(n, l, c)
(n, l) = list(map(int, input().split()))
c = list(map(int, input().split()))
print(dp009_party_lemonande(n, l, c))


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
	c[i] = min(c[i], c[i - 1] * 2)
d = [2 ** i for i in range(n)]
i = n - 1
while i >= 1:
	if c[i] < c[i - 1]:
		c[i - 1] = c[i]
		d[i - 1] = d[i]
	i -= 1
i = n - 1
cost = 0
mini = 999999999999999999999999999999999999
while i >= 0:
	cost = cost + l // d[i] * c[i]
	l = l % d[i]
	mini = min(mini, cost + (l > 0) * c[i])
	i -= 1
print(mini)


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

def lemonade():
	(n, L) = get_ints()
	costs = get_ints()
	mini = L * costs[0]
	ratio = [(costs[i] / 2 ** i, 2 ** i, costs[i]) for i in range(n)]
	ratio.sort()
	mini_overweight = mini
	current_cost = 0
	remaining = L
	for (cost, liters, c) in ratio:
		nb_of_bottle = remaining // liters
		current_cost += nb_of_bottle * c
		remaining -= nb_of_bottle * liters
		if remaining > 0:
			overweight = current_cost + c
			if overweight < mini_overweight:
				mini_overweight = overweight
	print(min(mini_overweight, current_cost))
lemonade()


(n, l) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] = min(a[i], 2 * a[i - 1])
ans = 10 ** 18
count = 0
for i in range(n - 1, -1, -1):
	count += a[i] * (l // 2 ** i)
	l = l % 2 ** i
	if l == 0:
		ans = min(ans, count)
	else:
		ans = min(ans, count + a[i])
print(ans)


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
res = 0
for i in range(1, n):
	c[i] = min(c[i - 1] * 2, c[i])
p = 1 << n - 1
y = l // p
l -= y * p
res += c[n - 1] * y
RES = []
if l > 0:
	RES.append(res + c[n - 1])
for i in range(n - 2, -1, -1):
	p //= 2
	y = l // p
	if y == 1:
		res += c[i]
		l -= 1 << i
		if l > 0:
			RES.append(res + c[i])
	elif l > 0:
		RES.append(res + c[i])
RES.append(res)
print(min(RES))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, L) = map(int, input().split())
C = [int(x) for x in input().split()]
for i in range(1, N):
	C[i] = min(C[i], 2 * C[i - 1])
bestans = 2 * 10 ** 18
exactans = 0
for i in range(N - 1, -1, -1):
	here = L // (1 << i)
	exactans += here * C[i]
	L -= here * (1 << i)
	bestans = min(bestans, exactans + C[i])
print(min(bestans, exactans))


import math
import bisect
import sys
from collections import OrderedDict
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
(N, L) = invr()
C = inlt()
for c in range(N - 1):
	if C[c] * 2 <= C[c + 1]:
		C[c + 1] = C[c] * 2
out = 10 ** 18
summ = 0
for i in range(N - 1, -1, -1):
	a = 2 ** i
	curr = L // a
	L = L % a
	summ += curr * C[i]
	if L == 0:
		out = min(out, summ)
	else:
		out = min(out, summ + C[i])
print(out)


import sys
from collections import Counter
(n, l) = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(1, n):
	arr[i] = min(2 * arr[i - 1], arr[i])
cost = 0
ans = 9999999999999999999
for i in range(n - 1, -1, -1):
	cost += arr[i] * (l // 2 ** i)
	l = l % 2 ** i
	ans = min(ans, cost + (l > 0) * arr[i])
print(ans)


(n, L) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
for i in range(1, n):
	if c[i] > c[i - 1] * 2:
		c[i] = c[i - 1] * 2
ans1 = 0
ans2 = 0
ans = 10 ** 20
for i in range(n - 1, -1, -1):
	r1 = L // 2 ** i
	r2 = (L + 2 ** i - 1) // 2 ** i
	L -= r1 * 2 ** i
	ans1 = ans2 + r2 * c[i]
	ans2 += r1 * c[i]
	ans = min(ans, ans1)
ans = min(ans, ans2)
print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
from bisect import bisect_left, bisect_right
(n, k) = map(int, input().split())
b = bin(k)[2:][::-1]
l = list(map(int, input().split()))
for i in range(1, n):
	l[i] = min(l[i], 2 * l[i - 1])
ans = 0
for i in range(max(0, len(b) - len(l))):
	l.append(l[-1] * 2)
for i in range(len(l)):
	if i < len(b):
		if b[i] == '1':
			if 2 * l[i] < ans + l[i]:
				ans = 2 * l[i]
			else:
				ans += l[i]
		elif l[i] < ans:
			ans = l[i]
	elif l[i] < ans:
		ans = l[i]
print(ans)


import os, sys
from io import BytesIO, IOBase

def main():
	(n, L) = map(int, input().split())
	c = list(map(int, input().split()))
	for i in range(n - 2, -1, -1):
		c[i] = min(c[i], c[i + 1])
	for i in range(1, n):
		c[i] = min(c[i], 2 * c[i - 1])
	while len(c) != 31:
		c.append(c[-1] * 2)
	(mask, su, ans, tk) = (1 << 30, 0, float('inf'), 0)
	for i in range(30, -1, -1):
		if mask & L:
			z = L - tk
			ans = min(ans, su + c[z.bit_length() - (not z & z - 1)])
			su += c[i]
			tk |= mask
		mask >>= 1
	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()


def merge(a, b):
	c = []
	while len(a) != 0 and len(b) != 0:
		if a[0][0] < b[0][0]:
			c.append(a[0])
			a.remove(a[0])
		else:
			c.append(b[0])
			b.remove(b[0])
	if len(a) == 0:
		c += b
	else:
		c += a
	return c

def mergesort(x):
	if len(x) == 0 or len(x) == 1:
		return x
	else:
		middle = len(x) // 2
		a = mergesort(x[:middle])
		b = mergesort(x[middle:])
		return merge(a, b)

def get_int_list(string):
	ls = []
	sum = ''
	for s in string:
		if s == ' ':
			ls.append(int(sum))
			sum = ''
		else:
			sum += s
	ls.append(int(sum))
	return ls

def get_ans(l, ls2):
	cost = 0
	while l > 0:
		if l <= ls2[0][1]:
			price = cost + ls2[0][2]
			if len(ls2) > 1:
				ls2.pop(0)
				cost = min(price, cost + get_ans(l, ls2))
			else:
				cost = price
			break
		else:
			num = l // ls2[0][1]
			l -= ls2[0][1] * num
			cost += num * ls2[0][2]
	return cost
x = input().split()
n = int(x[0])
l = int(x[1])
ls = get_int_list(input())
ls2 = []
for i in range(1, n + 1):
	vol = 2 ** (i - 1)
	unit = ls[i - 1] / vol
	ls2.append([unit, vol, ls[i - 1]])
ls2 = mergesort(ls2)
cost = 0
print(get_ans(l, ls2))


def solve(l, costs):
	ans = 0
	for i in range(31, -1, -1):
		if l >> i & 1 == 1:
			ans += min(costs[i + 1], costs[i] + solve(l - ex(2, i), costs))
			break
	return ans

def ex(base, exp):
	ans = 1
	for i in range(exp):
		ans = ans * base
	return ans
(n, l) = str(input()).split(' ')
(n, l) = (int(n), int(l))
costs = str(input()).split(' ')
costs = [int(c) for c in costs]
for i in range(1, n):
	costs[i] = min(costs[i], 2 * costs[i - 1])
for i in range(len(costs), 32):
	costs.append(2 * costs[i - 1])
for i in range(30, -1, -1):
	costs[i] = min(costs[i], costs[i + 1])
print(solve(l, costs))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
L = []
L1 = []
for i in range(n):
	L.append([l[i] / 2 ** i, i])
L.sort()
f = 123123123
s = 0
for i in range(n):
	if f > L[i][1]:
		if m % 2 ** L[i][1] == 0:
			L1.append(s + m // 2 ** L[i][1] * l[L[i][1]])
		else:
			L1.append(s + (m // 2 ** L[i][1] + 1) * l[L[i][1]])
		s += m // 2 ** L[i][1] * l[L[i][1]]
		m -= m // 2 ** L[i][1] * 2 ** L[i][1]
		f = L[i][1]
print(min(L1))


(n, L) = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
for i in range(0, n):
	T[i] = (2 ** i, T[i])

def f(n, L, T):
	if L == 0:
		return 0
	if n == 1:
		return ((L - 1) // T[0][0] + 1) * T[0][1]
	else:
		best = (T[0][0], T[0][1])
		for j in T:
			if best[1] * j[0] > j[1] * best[0]:
				best = j
		cost = (L - 1) // best[0] * best[1]
		paid = (L - 1) // best[0] * best[0]
		x = best[1]
		T.remove(best)
		return cost + min(f(n - 1, L - paid, T), x)
print(f(n, L, T))


val = input()
(n, L) = val.split()
n = int(n)
L = int(L)
ans = 0
string = input()
string = string.split()
for i in range(1, len(string)):
	if 2 * int(string[i - 1]) < int(string[i]):
		string[i] = 2 * int(string[i - 1])
for i in range(len(string)):
	if ans > int(string[i]):
		ans = int(string[i])
	if L & 1:
		ans += int(string[i])
	L //= 2
L *= 2
ans += L * int(string[n - 1])
print(ans)


from math import log2, ceil
(n, L) = [int(i) for i in input().split()]
costs = [int(i) for i in input().split()]
for i in range(len(costs) - 2, -1, -1):
	costs[i] = min(costs[i], costs[i + 1])
mincosts_len = ceil(log2(L)) + 1
mincosts = [costs[0]]
for i in range(1, mincosts_len):
	if i >= len(costs):
		mincosts.append(mincosts[i - 1] * 2)
	else:
		mincosts.append(min(mincosts[i - 1] * 2, costs[i]))
bitmask_cost = 0
purchased_index = []
for i in range(mincosts_len - 1, -1, -1):
	if L >= 2 ** i:
		bitmask_cost += mincosts[i]
		L -= 2 ** i
		purchased_index.append(i)
	if L == 0:
		break
for i in range(max(purchased_index)):
	if i not in purchased_index:
		purchased_index.append(i)
		purchased_index = list(filter(lambda a: a >= i, purchased_index))
		cost = sum([mincosts[j] for j in purchased_index])
		if cost < bitmask_cost:
			bitmask_cost = cost
print(min(bitmask_cost, mincosts[-1]))


(n, l) = map(int, input().split())
c = list(map(int, input().split()))
dp = [0] * 31
dp[0] = c[0]
for i in range(1, 31):
	if i >= n:
		dp[i] = 2 * dp[i - 1]
	else:
		dp[i] = min(2 * dp[i - 1], c[i])
for i in range(29, -1, -1):
	dp[i] = min(dp[i], dp[i + 1])
b = bin(l)[2:]
k = len(b)
m = dp[k]
x = 0
for i in range(k - 1, -1, -1):
	z = l >> i & 1
	if z == 1:
		x += dp[i]
	else:
		m = min(x + dp[i], m)
print(min(m, x))


(num_types, req_l) = list(map(int, input().split()))
costs = [0]
costs.extend(map(int, input().split()))
if req_l == 0:
	print(0)
else:
	volumes = [0]
	for x in range(num_types):
		if 2 ** x <= req_l:
			volumes.append(2 ** x)
		else:
			break
	volume_len = len(volumes)
	extra_part = costs[volume_len:] + [999999999999999999999999999999]
	min_extra = min(extra_part)
	min_idx = extra_part.index(min_extra) + volume_len
	costs = costs[:volume_len]
	best = 999999999999999999999999999
	for (idx, v) in enumerate(volumes):
		if idx == 0:
			continue
		new_best = costs[idx] / v
		if new_best < best:
			best = new_best
		else:
			costs[idx] = -1
	for i in range(len(volumes) - 1, -1, -1):
		if costs[i] < 0:
			costs[i:i + 1] = []
			volumes[i:i + 1] = []
	volume_len = len(volumes)
	out = []
	for i in range(volume_len - 1, -1, -1):
		if req_l > 0:
			needed = req_l // volumes[i]
			req_l -= volumes[i] * needed
			out.append((costs[i] * needed, costs[i] * (1 + needed)))
		else:
			out.append((0, costs[i]))
	prev = 999999999999999999999999999999
	running_total = 0
	for (curr_contrib, override_cost) in out[::-1]:
		running_total += curr_contrib
		if override_cost < running_total:
			running_total = override_cost
	ans = min(running_total, min_extra)
	print(ans)


R = lambda : map(int, input().split())
(n, L) = R()
L2 = '{0:b}'.format(L)
t = len(L2)
c = list(R())
b = [0] * max(n, t)
l = [0] * max(n, t)
b[0] = float('inf')
temp = 0
for i in range(n - 1, -1, -1):
	if c[i] < b[0]:
		b[0] = c[i]
		temp = i
	l[0] = 2 ** temp
for i in range(1, n):
	if l[i - 1] >= 2 ** i:
		b[i] = b[i - 1]
		l[i] = l[i - 1]
	elif min(2 * b[i - 1], min(c[i:])) == 2 * b[i - 1]:
		b[i] = 2 * b[i - 1]
		l[i] = 2 * l[i - 1]
	else:
		temp = 0
		b[i] = float('inf')
		for j in range(n - 1, i - 1, -1):
			if c[j] < b[i]:
				b[i] = c[j]
				temp = i
		l[i] = 2 ** temp
for i in range(n, t):
	b[i] = 2 * b[i - 1]
	l[i] = 2 * l[i - 1]

def solve(t, price):
	if t <= 0:
		return price
	t2 = '{0:b}'.format(t)
	try:
		return min(solve(t - l[len(t2) - 1], price + b[len(t2) - 1]), solve(t - l[len(t2)], price + b[len(t2)]))
	except:
		return solve(t - l[len(t2) - 1], price + b[len(t2) - 1])
print(solve(L, 0))


def min_cost(l, a):
	if l <= 0:
		return 0
	bl = bin(l)[2:]
	lb = len(bl)
	temp_cost = a[lb - 1] + min_cost(l - pow(2, lb - 1), a)
	if min(a[lb:]) <= temp_cost:
		return min(a[lb:])
	return temp_cost
(n, l) = input().split()
n = int(n)
l = int(l)
a = [int(x) for x in input().split()]
for i in range(1, n):
	if a[i] > 2 * a[i - 1]:
		a[i] = 2 * a[i - 1]
for i in range(n, 31):
	a.append(2 * a[i - 1])
print(min_cost(l, a))


listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, l) = mapin()
c = listin()
lc = [c[0]]
for i in range(1, n):
	lc.append(min(lc[-1] * 2, c[i]))
ans = 10 ** 20
s = 0
for i in range(n - 1, -1, -1):
	num = l // 2 ** i
	s += num * lc[i]
	l -= num * 2 ** i
	ans = min(ans, s + (l > 0) * lc[i])
print(ans)


import math
l1 = input().split()
l2 = input().split()
l1 = [int(i) for i in l1]
l2 = [int(i) for i in l2]
n = l1[0]
lit = l1[1]
for i in range(n - 1):
	l2[i + 1] = min(l2[i + 1], 2 * l2[i])
r = 4e+18
s = 0
j = n - 1
while j >= 0:
	need = int(lit / (1 << j))
	s += need * l2[j]
	lit -= need << j
	r = min(r, s + (lit > 0) * l2[j])
	j -= 1
print(r)