Problem:
 Score : 300 points    Problem Statement You've come to your favorite store Infinitesco to buy some ice tea.  The store sells ice tea in bottles of different volumes at different costs.
Specifically, a 0.25 -liter bottle costs Q yen, a 0.5 -liter bottle costs H yen, a 1 -liter bottle costs S yen, and a 2 -liter bottle costs D yen.
The store has an infinite supply of bottles of each type.  You want to buy exactly N liters of ice tea. How many yen do you have to spend?      Constraints  1 \leq Q, H, S, D \leq 10^8  1 \leq N \leq 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  Q  H  S  D  N       Output Print the smallest number of yen you have to spend to buy exactly N liters of ice tea.        Sample Input 1 20 30 70 90
3      Sample Output 1 150  Buy one 2 -liter bottle and two 0.5 -liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.       Sample Input 2 10000 1000 100 10
1      Sample Output 2 100  Even though a 2 -liter bottle costs just 10 yen, you need only 1 liter.
Thus, you have to buy a 1 -liter bottle for 100 yen.       Sample Input 3 10 100 1000 10000
1      Sample Output 3 40  Now it's better to buy four 0.25 -liter bottles for 10 + 10 + 10 + 10 = 40 yen.       Sample Input 4 12345678 87654321 12345678 87654321
123456789      Sample Output 4 1524157763907942

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

q, h, s, d = ril()
n = ri()
x = min(4 * q, 2 * h, s)
if 2 * x < d:
    print(n * x)
else:
    print(n // 2 * d + n % 2 * x)

Solution (Python):
a,b,c,d,n=map(int,open(0).read().split())
print(n//2*min(8*a,4*b,2*c,d)+(n%2)*min(4*a,2*b,c))

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())

ans = (n//2) * min(q*8, h*4, s*2, d) + (n%2) * min(q*4, h*2,s)
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
n=int(input())
if a*4==min(a*4,b*2,c,d//2):
    print(n*a*4)
elif b*2==min(a*4,b*2,c,d//2):
    print(n*b*2)
elif c==min(a*4,b*2,c,d//2):
    print(n*c)
else:
    if n==1:
        ans=d*(n//2)
        if a*4==min(a*4,b*2,c):
            ans+=a*4
        elif b*2==min(a*4,b*2,c):
            ans+=b*2
        elif c==min(a*4,b*2,c):
            ans+=c
        print(ans)
    elif n%2==0:
        print((n*d)//2)
    else:
        ans=d*(n//2)
        if a*4==min(a*4,b*2,c):
            ans+=a*4
        elif b*2==min(a*4,b*2,c):
            ans+=b*2
        elif c==min(a*4,b*2,c):
            ans+=c
        print(ans)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
ans = 0

if N >= 2:
    tmp = N // 2
    ans += (min(Q * 8, H * 4, S * 2, D) * tmp)
if N % 2 != 0:
    ans += min(Q * 4, H * 2, S)

print(ans)

Solution (Python):

Q, H, S, D = map(int, input().split())
N = int(input())

qhs = min(4 * Q, 2 * H, S)
if N % 2 == 0:
    used = min(2 * qhs, D)
    ans = used * (N // 2)
else:
    if 2 * qhs >= D:
        ans = D * (N // 2) + qhs
    else:
        ans = N * qhs
print(ans)

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
 
x = min(4*q, 2*h, s)
y = min(d, 2*x)
 
print((n//2)*y+(n%2)*x)

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

x = min(4*q, 2*h, s)
y = min(d, 2*x)

print((n//2)*y+(n%2)*x)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z,a = inpl()
n = inp()
b = min(x*4,y*2,z)
a,b = b,a

if n%2==0:
    print(min(b*(n//2),a*n))
else:
    print(min(b*(n//2)+a,a*n))

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

s = min(2 * min(2 * q, h), s)

print((n // 2) * min(2 * s, d) + (n % 2) * s)

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())*4

k = [
    [q*8,q,1],
    [h*4,h,2],
    [s*2,s,4],
    [d,d,8]
    ]
k.sort() 
cost = 0
for i in range(4):
    num = n // k[i][2] * k[i][1]
    cost += num
    n %= k[i][2]
print(int(cost))

Solution (Python):
def main():
    q, h, s, d = map(int, input().split())
    n = int(input())

    two = [8 * q, 4 * h, 2 * s, d]
    two.sort()
    one = [4 * q, 2 * h, s]
    one.sort()

    t, o = divmod(n, 2)
    ans = t * two[0] + o * one[0]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
sc=min(s,h*2,q*4)
if sc*2<d:
    print(n*sc)
else:
    print(n//2*d+n%2*sc)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

q = Q * 8
h = H * 4
s = S * 2
d = D

print(N // 2 * min(q, h, s, d) + N % 2 * min(q, h, s) // 2)

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())

l20 = [q*8,h*4,s*2,d]
l10 = [q*4,h*2,s]
l05 = [q*2,h]
l025 = [q]

cst = 0


if(n>=2):
    divi = int(n/2)
    cst += min(l20)*divi
    r = n%2
    n = r
if(n>=1):
    divi = int(n/1)
    cst += min(l10)*divi
    r = n%1
    n = r
if(n>=0.5):
    divi = int(n/0.5)
    cst += min(l05)*divi
    r = n%0.5
    n = r
if(n>=0.25):
    divi = int(n/0.25)
    cst += min(l025)*divi
    
print(cst)

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

twoL = [q * 8, h * 4, s * 2, d]
twoL.sort()

if n % 2 == 0 :
    print(twoL[0] * (n // 2))
else :
    L = [q * 4, h * 2, s]
    L.sort()
    print(twoL[0] * (n // 2) + L[0])

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

if n % 2 == 0:
    l = [4*q*n, 2*h*n, s*n, d*(n//2)]
    l.sort()
    print(int(l[0]))
else:
    l = [4*q*(n-1), 2*h*(n-1), s*(n-1), d*((n-1)//2)]
    l_rest =  [4*q, 2*h, s]
    l.sort()
    l_rest.sort()
    if n > 1:
        print(int(l[0]+l_rest[0]))
    elif n == 1:
        print(l_rest[0])

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

l1, l2 = min(q*4, h*2, s), min(q*8, h*4, s*2, d)
if n % 2 == 0:
    print(l2 * (n//2))
else:
    print(l2 * (n//2) + l1)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

array = [[Q*8, Q*4, 1], [H*4, H*2, 1], [S*2, S, 1], [D, D, 2]]

array.sort()

total = 0
for i in range(4):
    total += N // array[i][2] * array[i][1]
    N %= array[i][2]
    
print(int(total))

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

Q = q * 4
H = h * 2
S = s
D = d / 2

if n == 1:
    print(int(min(Q, H, S)))
else:
    if min(Q, H, S) <= D:
        print(int(n * min(Q, H, S)))
    else:
        print((n // 2) * d + (n % 2) * min(Q, H, S))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  q,h,s,d=LI()
  n=I()

  q*=4
  h*=4
  s*=4
  d*=4
  n*=4

  l=[]
  l.append([q,1,q/1])
  l.append([h,2,h/2])
  l.append([s,4,s/4])
  l.append([d,8,d/8])

  l=sorted(l,key=lambda x:x[2])

  ans=0
  for x in l:
    if n%x[1]==0:
      ans+=(n//x[1])*x[0]
      return ans//4
    else:
      ans+=(n//x[1])*x[0]
      n%=x[1]


print(main())

Solution (Python):
q, h, s, d = map(int,input().split())
n = int(input())
h = min(q*2, h)
s = min(h*2, s)
d = min(s*2, d)

print((n//2) * d + (n%2) * s)

Solution (Python):
q,h,s,d = map(int,input().split())	
s=min(4*q,2*h,s)
d=min(2*s,d)
n=int(input())
print((n//2)*d+(n%2)*s)

Solution (Python):
Q,H,S,D=map(int,input().split())
N=int(input())

T=min(4*Q,2*H,S)

if T<=D/2:
    ans=T*N
else:
    ans=D*(N//2)+T*(N%2)

print(ans)

Solution (Python):
def f(n, l, price):
    if l == 0.25:
        return int(n / 0.25 * price[l])
    t = int(n / l)
    return min(f(n - l * t, l / 2, price) + t * price[l], f(n, l / 2, price))


Q, H, S, D = map(int, input().split())
N = int(input())

price = {0.25: Q, 0.5: H, 1.0: S, 2.0: D}
print(f(N, 2.0, price))

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
l1=min(4*q,2*h,s)
l2=min(l1*2,d)
ans=n//2*l2+n%2*l1
print(ans)

Solution (Python):
import os

Q,H,S,D = (int(x) for x in input().split())
N = int(input())
h = min(Q*2,H)
s = min(h*2,S)
d = min(s*2,D)

ans = 0

ans += d*(N//2)
if N%2:
    ans += s
print(ans)

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())
twoL = min(q*8,4*h,2*s,d)
oneL = min(q*4,2*h,s)
p = (n//2)*twoL + (n%2)*oneL
print(p)

Solution (Python):
import itertools

def solve(q, h, s, d, n):
    records = [(1, q), (2, h), (4, s), (8, d)]
    best = 10**30
    for p in itertools.permutations(range(4)):
        x = 4 * n
        cur = 0
        for i in p:
            size, price = records[i]
            amount = x // size
            cur += amount * price
            x -= size * amount
        cur += x * q
        best = min(best, cur)
    return best

q, h, s, d = map(int, input().split())
n = int(input())
print(solve(q, h, s, d, n))

Solution (Python):
Q,H,S,D,N=map(int,open(0).read().split());m=min(4*Q,2*H,S);print(min(N*m,N//2*D+N%2*m))

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())

one = min([q * 4, h * 2, s])
two = min(one * 2, d)

ans = n // 2 * two + n % 2 * one
print(ans)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())





N *= 4
ans = 0

price = [(Q / 1, 1, Q), (H / 2, 2, H), (S / 4, 4, S), (D / 8, 8, D)]
price.sort()

for _, n, p in price:
    cnt = N // n
    ans += cnt * p
    N -= cnt * n

print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())

l2=[q*8,h*4,s*2,d]
l1=[q*4,h*2,s]
print((n//2)*min(l2)+(n%2)*min(l1))

Solution (Python):
Q,H,S,D=map(int,input().split())
N=int(input())

N*=4
T=[[1,4*Q,4*Q],[2,4*H,2*H],[4,4*S,S],[8,4*D,D/2]]
T.sort(key=lambda x: x[2])

ans=0
for t in T:
  ans+=N//t[0]*t[1]
  N%=t[0]
print(ans//4)

Solution (Python):
A=list(map(int,input().split()))
N=int(input())

for i in range(3):
	if A[i]*2<A[i+1]:
		A[i+1]=A[i]*2

k=[0.25, 0.5, 1, 2]
ans=0
for i in range(4)[::-1]:
	ans += (N//k[i])*A[i]
	N-=k[i]*(N//k[i])
	if N==0:break


print(int(ans))

Solution (Python):
q, g, s, d = map(int, input().split())
n = int(input())

g = min(g, q * 2)
s = min(s, g * 2)
d = min(d, s * 2)

ans = 0


n *= 4

ans += n // 8 * d
n %= 8

ans += n // 4 * s
n %= 4

ans += n // 8 * g
n %= 2

ans += n

print(ans)

Solution (Python):
Q, H, S, D = tuple(map(int, input().split()))
N = int(input())
min2l = min(8 * Q, 4 * H, 2 * S, D)
min1l = min(4 * Q, 2 * H, S)
print((N // 2) * min2l + (N % 2) * min1l)

Solution (Python):
Q, H, S, D = tuple(map(int, input().split()))
N = int(input())
if N == 1:
    print(min(4 * Q, 2 * H, S))
    exit()

min2l = min(8 * Q, 4 * H, 2 * S, D)
min1l = min(4 * Q, 2 * H, S)
print((N // 2) * min2l + (N % 2) * min1l)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
one = min(4*Q, 2*H, S)
two = min(one*2, D)

d, m = divmod(N, 2)
print(d*two + m*one)

Solution (Python):
inp = list(map(int,input().split()))
q = inp[0] 
h = inp[1] 
s = inp[2] 
d = inp[3] 
n = int(input())
q *= 4
h *= 2
num = min(q,h,s) 
if n >= 2:
    N = n // 2
    total = min(2*num*N, d*N) + num*(n % 2)
else:
    total = n * num
print(total)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
Q *= 4
H *= 2
l = min(Q, H, S)

if N >= 2:
    n = N // 2
    price = min(2*l*n, D*n) + l*(N%2)
else:
    price = N * l

print(price)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
S2 = min(4*Q, 2*H, S)
D2 = min(2*S2, D)
r = N//2*D2 + (S2 if N%2 == 1 else 0)
print(r)

Solution (Python):
Q,H,S,D=map(int,input().split())
N=int(input())

C=[[0]*3 for _ in range(4)]
C[0]=[0.25,Q,4*Q]
C[1]=[0.5,H,2*H]
C[2]=[1,S,S]
C[3]=[2,D,D/2]

C.sort(key=lambda x:x[2])

if C[0][0]==2:
    if N%2!=0:
        ans=N//2*D+C[1][2]
    else:
        ans=N//2*D
else:
    ans=N*C[0][2]

print(int(ans))

Solution (Python):
a,b,c,d = map(int,input().split())
n = int(input())
aval = 4*a
bval = 2*b
cval = c
dval = d/2
if aval == min(aval,bval,cval,dval):
         print(aval*n)
elif bval == min(aval,bval,cval,dval):
         print(bval*n)
elif cval == min(aval,bval,cval,dval):
         print(cval*n)
elif dval == min(aval,bval,cval,dval) and n %2 == 0:
         print(d*(n//2))
else:
         if aval == min(aval,bval,cval):
                  print(d*(n//2) + aval)
         elif bval == min(aval,bval,cval):
                  print(d*(n//2) + bval)
         else:
                  print(d*(n//2) + cval)

Solution (Python):
Q, H, S, D = map(int, input().split())
price = { 0.25: Q, 0.5: H, 1.0: S, 2.0: D }
N = int(input())
def f(n, l):
  if l == 0.25:
    return int(n / 0.25) * price[l]
  t = int(n / l)
  return min(f(n - l * t, l / 2) + t * price[l], f(n, l / 2))
print(int(f(N, 2.0)))

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
print(min(Q*8, H*4, S*2, D) * (N//2) + min(Q*4, H*2, S) * int(N%2))

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    c1 = min(Q*4, H*2, S)
    c2 = min(c1*2, D)
    ans = 0
    ans += c2 * (N//2)
    rest = int(N%2)
    ans += c1 * rest
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    Q,H,S,D = map(int,input().split())
    N = int(input())
    L_L = min(D,S*2,H*4,Q*8)
    L = min(S,H*2,Q*4)
    if N%2 == 0:
        print(L_L*(N//2))
    else:
        print(L_L*(N//2)+L)

if __name__ == "__main__":
    main()

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

p1 = min(Q * 4, H * 2, S)
p2 = min(p1 * 2, D)

print(N % 2 * p1 + N // 2 * p2)

Solution (Python):
q,h,s,d = [int(x) for x in input().split()]
n = int(input())
print(min(d,s<<1,h<<2,q<<3)*((n<<2)>>3)+min(s,h<<1,q<<2)*(((n<<2)&((1<<3)-1))>>2)+min(h,q<<1)*(((n<<2)&((1<<2)-1))>>1)+q*((n<<2)&((1<<1)-1)))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    q,h,s,d = LI()
    d = min(d,2*s,4*h,8*q)
    s = min(s,2*h,4*q)
    h = min(h,2*q)
    n = I()
    n *= 4
    ans = d*(n>>3)
    n &= (1<<3)-1
    ans += s*(n>>2)
    n &= (1<<2)-1
    ans += h*(n>>1)
    n &= (1<<1)-1
    ans += q*n
    print(ans)
    return

def B():

    return


def C():

    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    A()

Solution (Python):
q = sorted(list(zip(map(int, input().split()), (25, 50, 100, 200))),
           key=lambda a: a[0] / a[1])
n = int(input()) * 100
total = 0
for i in range(len(q)):
    n_buy = (n // q[i][1])
    tmp = n_buy * q[i][1]
    n -= tmp
    total += n_buy * q[i][0]
print(int(total))

Solution (Python):
def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    N = 4*N
    val = [[Q, Q, 1], [H/2, H, 2], [S/4, S, 4], [D/8, D, 8]]
    val.sort(key = lambda x:x[0])
    ans = 0
    for i in range(4):
        count = N // val[i][2]
        ans += count * val[i][1]
        N = N - count * val[i][2]
    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):


import sys




tmp = input().split()
q,h,s,d = list(map(lambda a: int(a), tmp))

n= int(input())

k=min(4*q,min(2*h,s))


if(2*k<d):
	print(n*k)
else:
	tmp = n%2*k
	print((n-n%2)*d//2+tmp)

Solution (Python):
q,h,s,d=map(int,input().split())

n=int(input())*4
a2=min(q*2,h)
a4=min(q*4,h*2,s)
a8=min(q*8,h*4,s*2,d)
a=[0,a2,a4,a8]
ans=0
for i in range(3,0,-1):
    ans+=(n//2**i)*a[i]
    n%=2**i
ans+=n*q
print(ans)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
if N%2 == 0:
  print((N//2)*min(8*Q,4*H,2*S,D))
else:
  m = min(4*Q,2*H,S)
  if 2*m <= D:
    print(m*N)
  else:
    print(int(D*(N//2)+m))

Solution (Python):
Q, H, S, D = map(int,input().split())
N = int(input())

ans = 0
if N % 2 == 1:
    ans = min(4*Q,2*H,S)
ans += (N//2) * min(8*Q, 4*H, 2*S, D)

print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


q,h,s,d = LI()
n = I()
a,b,c = q*8,h*4,s*2
x,y = q*4,h*2
if n % 2:
    ans = min(a,b,c,d)*(n//2) + min(x,y,s)
else:
    ans = min(a,b,c,d)*(n//2)
print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
N=int(input())
s=min(q*4,h*2,s)
print(min(s*N,d*(N//2)+s*(N%2)))

Solution (Python):
q,h,s,d=map(int,input().split())
N=int(input())
h=min(2*q,h)
s=min(2*h,s)
ans=0
if 2*s>d:
  ans+=(N//2)*d
  if N%2!=0:
    ans+=s
else:
  ans=N*s
print(ans)

Solution (Python):

import sys, math, fractions, itertools, collections, copy, heapq


def solve(Q: int, H: int, S: int, D: int, N: int):
    H = min(H, 2*Q)
    S = min(S, 2*H)
    if 2 * S <= D:
        print(N*S)
    else:
        print(N//2 * D + (N % 2) * S)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  
    H = int(next(tokens))  
    S = int(next(tokens))  
    D = int(next(tokens))  
    N = int(next(tokens))  
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()

Solution (Python):

import sys, math, fractions, itertools, collections, copy, heapq


def solve(Q: int, H: int, S: int, D: int, N: int):
    H = min(H, 2*Q)
    S = min(S, 2*H)
    if 2 * S <= D:
        print(N*S)
    else:
        print(N//2 * D + (N % 2) * S)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  
    H = int(next(tokens))  
    S = int(next(tokens))  
    D = int(next(tokens))  
    N = int(next(tokens))  
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
if N == 1:
    print (min(4 * Q, 2 * H, S))
    exit()

if N % 2 == 0: 
    n = N // 2
    print (n * min(8 * Q, 4 * H, 2 * S, D))
else:
    n = N // 2
    print (n * min(8 * Q, 4 * H, 2 * S, D) + min(4 * Q, 2 * H, S))

Solution (Python):
import sys
input=sys.stdin.readline

Q,H,S,D = map(int, input().split())
N = int(input())

p = [Q,H,S,D]
for i in range(1,4):
    q = [p[i]]
    for j in range(0,i):
        q.append(p[j]*2**(i-j))
    p[i] = min(q)


ans = 0
N *= 4
while N>0:
    if N>=8:
        x = N//8
        ans += p[3]*x
        N-=8*x
    elif N>= 4:
        ans += p[2]
        N-=4
    elif N>= 2:
        ans += p[1]
        N-=2
    else:
        ans += p[0]
        N-=1
print(ans)

Solution (Python):

def main():
    
    Q, H, S, D = list(map(int, input().rstrip().split()))  
    N = int(input())
    X = min(Q * 4, H * 2, S)
    ans = N // 2 * min(X * 2, D) + N % 2 * X
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
A, B, C, D = [int(_) for _ in input().split()]
N = int(input())

values = [(0.25, A), (0.5, B), (1, C), (2, D)]
values.sort(key=lambda x: x[1] / x[0])

ans = 0
for l, p in values:
    if l > N: continue

    tmp = int(N // l)
    ans += tmp * p
    N -= tmp * l
print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
Q,H,S,D=q*8,h*4,s*2,d
if min(Q,H,S,D)==Q:
    print(n*4*q)
elif min(Q,H,S,D)==H:
    print(n*2*h)
elif min(Q,H,S,D)==S:
    print(n*s)
else:
    if n%2==0:
        print((n//2)*d)
    else:
        print(((n//2)*d)+min(q*4,h*2,s))

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

most_bargain = min(8 * Q, 4 * H, 2 * S, D)
if most_bargain != D:
    print((most_bargain // 2) * N)
else:
    if N % 2 == 0:
        print((N // 2) * D)
    else:
        print((N // 2) * D + min(4 * Q, 2 * H, S))

Solution (Python):
a,b,c,d,n=map(int,open(0).read().split());e=min(a*4,b*2,c);print(n//2*min(2*e,d)+n%2*e)

Solution (Python):
a, b, c, d = map(int, input().split())
N = int(input())
s = N //2
ans = 0

ans += s * min(a*8, b*4, c*2, d)

if N % 2 == 0:
    pass
else:
    ans += min(a*4, b*2, c)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

Q,H,S,D = map(int,input().split())
H = min(H,2*Q) 
S = min(S,2*H) 

N = int(input())
answer = 0
if N&1:
    answer += S
D = min(D,2*S)
answer += (N//2)*D
print(answer)

Solution (Python):



Q,H,S,D=map(int,input().split())
n=int(input())

ans=(n//2)*min(8*Q,4*H,2*S,D)+(n%2)*(min(4*Q,2*H,S))
print(ans)

Solution (Python):


Q,H,S,D=map(int,input().split())
n=int(input())

q=Q*4
h=H*2
s=S
d=D/2
ls=sorted([q,h,s,d])
if ls[0]==d and ls[1]!=d:
    if n%2:
        ans=D*(n//2)+ls[1]
    else:
        ans=D*(n//2)

else:
    ans=int(ls[0]*n)
print(ans)

Solution (Python):

q, h, s, d = map(int, input().split())
n = int(input())
arr = [8 * q, 4 * h, 2 * s, d]
x = min(arr)
if n % 2 == 0:
    print((n // 2) * x)
else:
    ans = (n // 2) * x
    ans += min([4 * q, 2 * h, s])
    print(ans)

Solution (Python):
Q,H,S,D=map(int,input().split())
N=int(input())

if D%2==1:
    f=1
else:
    f=0

if N//2==0:
    g=1
else:
    g=0

Q*=4
H*=2
S=S
D2=D/2.0
D=D

cnt=0
cost=[[Q,1],[H,1],[S,1],[D2,2]]
cost2=[[Q,1],[H,1],[S,1]]
if min(cost)[1]==2:
    if not(f==1 and g==1):
        cnt+=D*(N//2)
        N%=2

if N!=0:
    cnt+=min(cost2)[0]*N
print(int(cnt))

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
a = min(Q+Q, H)
b = min(a+a, S)
c = min(b+b, D)
print(N//2*c+b*(N%2))

Solution (Python):
import copy

Q, H, S, D = map(int,input().split())
N = int(input())
flat = [8*Q, 4*H, 2*S, D]
work = copy.deepcopy(flat)
work.sort()

rank = 1
order = [0, 0, 0, 0]
for i in range(4):
    for j in range(4):
        if work[i] == flat[j]:
            order[j] = rank
            rank += 1
if order[3] == 1: 
    second = 0
    for i in range(4):
        if order[i] == 2:
            second = i
    if N % 2 == 0:
        print(str(D*N//2))
    else:
        if second == 0:
            print(str(D*(N//2) + Q*4))
        elif second == 1:
            print(str(D*(N//2) + H*2))
        else:
            print(str(D*(N//2) + S))
else:
    buy = 0
    for i in range(4):
        if order[i] == 1:
            buy = i
    if buy == 0:
        print(str(Q*4*N))
    elif buy == 1:
        print(str(H*2*N))
    else:
        print(str(S*N))

Solution (Python):
def main():
    q,h,s,d = map(int,input().split())
    n = int(input())
    
    one = min([q*4,h*2,s])
    
    two = d

    if one*2 > two:
        print((n//2)*two + (n%2)*one)

    else:
        print(n*one)



if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
Q,H,S,D = [int(x) for x in stdin.readline().rstrip().split()]
N = int(stdin.readline().rstrip())

ans = 0
Q4 = Q * 4
H2 = H * 2
D0 = D / 2
QH = Q * 2 + H

if min(Q4,H2,S,D0,QH) == D0:
    ans = ((N // 2) * int(D0 * 2))
    ans += ((N % 2) * min(Q4,H2,S,QH))

else:
    ans = (min(Q4,H2,S,QH) * N)
print(ans)

Solution (Python):
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	p,q,r,s = map(int,input().split())
	n = int(input())
	pickable_1l = min(p*4,q*2,r,p*2+q)
	if(pickable_1l * 2 < s):
		print(n*pickable_1l)
	else:
		print(n//2*s + pickable_1l * (n%2))


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
a,b,c,d=map(int,input().split())
n=int(input())
v_1=min(a*4,b*2,c)
v_2=min(v_1*2,d)
ans=(n//2)*v_2+(n%2)*v_1
print(ans)

Solution (Python):
Q,H,S,D=map(int,input().split())
digs=sorted([(8*Q,1,Q),(4*H,2,H),(2*S,4,S),(D,8,D)])
N=4*int(input())
ans=0
for _,d,p in digs:
    ans+=p*(N//d)
    N=N%d
print(ans)

Solution (Python):
Q,H,S,D=map(int,input().split())
N=4*int(input())
digs=[(1,Q)]
if H<2*Q:
    digs.append((2,H))
if S<4*Q and S<2*H:
    digs.append((4,S))
if D<8*Q and D<4*H and D<2*S:
    digs.append((8,D))
ans=0
for d,p in reversed(digs):
    ans+=p*(N//d)
    N=N%d
print(ans)

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
print((n//2) * min(8 * q, 4 * h, 2 * s, d) + (n % 2) * min(4 * q, 2 * h, s))

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

print((N // 2) * min(8* Q, 4 * H, 2 * S, D) + (N % 2) * min(4 * Q, 2 * H, S))

Solution (Python):
from sys import stdin
Q, H, S, D = [int(_) for _ in stdin.readline().rstrip().split()]
N = int(stdin.readline().rstrip())
print((N//2)*min(8*Q, 4*H, 2*S, D)+(N%2)*min(4*Q, 2*H, S))

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

L = min(4*Q, 2*H, S)

if L < D/2:
    print(N*L)
else:
    print((N//2)*D+(N % 2)*L)

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())

if 2 * Q < H:
    H = 2 * Q
if 2 * H < S:
    S = 2 * H
if 2 * S < D:
    D = 2 * S

print(N//2 * D + N%2 * S)

Solution (Python):
q,h,s,d,n=map(int,open(0).read().split())
a=0
if d<min(s*2,h*4,q*8):
  a+=n//2*d
  n%=2
if s<min(h*2,q*4):
  a+=n*s
  n=0
if h<q*2:
  a+=n*2*h
  n=0
print(a+n*4*q)

Solution (Python):
q,h,s,d,n=map(int,open(0).read().split())
a=0
if d<min(s*2,h*4,q*8):
  a+=n//2*d
  n%=2
if s<min(h*2,q*4):
  a+=n*s
  n=0
if h<q*2:
  a+=n*2*h
  n=0
print(a+n*4*q)

Solution (Python):
cost = list(map(int, input().split()))
size = [1, 2, 4, 8]
N = int(input()) * 4

ans = 0
while N > 0:
    min_ = (N // size[0]) * cost[0]
    q = 0
    for i in range(1,4):
        tmp = (N//size[i]) * cost[i]
        if tmp < min_ and tmp != 0:
            min_ = tmp
            q = i
    ans += min_
    N = N%size[q]
print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
m=n%2
print(((n-m)//2)*min(q*8,h*4,s*2,d)+m*min(q*4,h*2,s))

Solution (Python):
q,h,c,d=map(int,input().split())
n=int(input())

o=min(4*q,2*h,c)
t=min(2*o,d)
if n%2==0:
    print(n*t//2)
else:
    print(t*(n//2)+o)

Solution (Python):
Q, H, S, D = map(int, input().split()) 
N = int(input())

com = [Q*8, H*4, S*2, D]
com.sort()
price = (N // 2) * com[0]

if N % 2 == 1:
    am = [Q*4, H*2, S]
    am.sort()
    price += am[0]

print(price)

Solution (Python):
Q,H,S,D = map(int,input().split())
N=int(input())
s = min(Q*4,H*2,S)
d = min(s*2,D)
print((N//2)*d+(N%2)*s)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
h=min(q*2,h)
s=min(s,h*2)
print(min(d*(n//2)+s*(n%2),s*n))

Solution (Python):
Q,H,S,D = map(int,input().split())
N = int(input())
D = min(D,2*S,4*H,8*Q)
S = min(S,2*H,4*Q)
H = min(2*Q,H)
ans = 0
ans += (N // 2)*D if int(N)%2 == 0 else (N // 2)*D + S
N = N - int(N)
N *= 100
ans += (N // 50)*H if N%50 == 0 else (N // 50)*H  + Q
print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
cperl=[q*8,h*4,s*2,d]
if n%2==0:
  print(int((n//2)*min(cperl)))
else:
  if min(cperl)==cperl[3]:
    print(int(cperl[3]*(n//2)+min(cperl[:3])//2))
  else:
    print(int(n*(min(cperl)//2)))

Solution (Python):
a,b,c,k = map(int,input().split())
one = min( 4*a,2*b,c)
two = min(2*one,k)
n = int(input())
ans = 0
ans += (n//2)*two
ans += (n%2)*one
print(ans)

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
a=min(s,h*2,q*4)
b=min(d,a*2)
print(n//2*b if n%2==0 else n//2*b+a)

Solution (Python):
Q,H,S,D = map(int,input().split())
N = int(input())

cost = [8*Q, 4*H, 2*S, D]
mult = [4,2,1,1/2]

b = min(cost)
idx = cost.index(b)

if idx == 3:
    if N%2 == 0:
        ans = N//2*D
    else:
        ans = N//2 * D
        ans += min(4*Q, 2*H, S)
else:
    ans = N*b//2

print(ans)

Solution (Python):
cost_list = [ int(v) for v in input().split() ]
size_list = [1,2,4,8]
n = int(input())*4
value_list = list(zip(cost_list,size_list))
value_list = sorted([ [i[0]/i[1]] + list(i) for i in value_list])


ans = 0
for i in value_list:
    a = n // i[2]
    ans += i[1] * a
    n -= a * i[2]
print(ans)

Solution (Python):
q, h, s, d = [int(i) for i in input().split()]
n = int(input())
a = [[q*8, 0.25, q], [h*4, 0.5, h], [s*2, 1, s], [d, 2, d]]
a.sort()
if a[0][1] != 2:
    print(int(n/a[0][1]*a[0][2]))
else:
    print(n//2*d+(n%2)*a[1][0]//2)