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):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


q, h, s, d = MI()
n = II()
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())

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

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

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

Solution (Python):
Q, H, S, D = list(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 = map(int, input().split())
N = int(input())

n, cost = N * 4, 0
while 0 < n:
	if 8 <= n:
		offset = n // 8
		cost += (min(D, S * 2, H * 4, Q * 8) * offset)
		n -= (8 * offset)
		continue
	if 4 <= n:
		cost += min(S, H * 2, Q * 4)
		n -= 4
		continue
	if 2 <= n:
		cost += min(H, Q * 2)
		n -= 2
		continue
	if 1 <= n:
		cost += min(Q)
		n -= 1
		continue
print(cost)

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

if S * 2 > D:
    print((N // 2) * D + (N % 2) * S)
else:
    print(N * S)

Solution (Python):
Q,H,S,D=[int(i) for i in input().split()]
N=int(input())
Price2 = [Q*8,H*4,S*2,D]
ans = 0
if N==1:
    print(min(Price2[:3])//2)
else:
    Two = N//2
    N %= 2
    print(Two*min(Price2) + N * min(Price2[:3])//2)

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

Solution (Python):

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

print(ans)

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

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

while N > 0:
    if N == 1:
        ans += min(4*Q, 2*H, S)
        break
    else:
        M = N//2
        ans += min(8*M*Q, 4*M*H, 2*M*S, M*D)
        N -= 2*M

print(ans)

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


if __name__ == "__main__":
    main()

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
liter_1 = min(4*Q, 2*H, S)
liter_2 = min(2*liter_1, D)
q, r = divmod(N, 2)
ans = q * liter_2 + r * liter_1
print(ans)

Solution (Python):
VS = [(Y, Y*(2//q), q) for Y, q in zip(map(int, input().split()), (0.25, 0.5, 1, 2))]
N = int(input())

tanka = 0
for Y, _, q in sorted(VS, key=lambda x:x[1], reverse=False):
  u = N // q
  N -= q * u
  
  tanka += Y * int(u)
  if N <= 0:
    break
 
print(tanka)

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


one_cost = min(4*Q, 2*H, S)
two_cost = min(2*one_cost, D)

if N % 2 == 0:
    print(two_cost * (N // 2))
else:
    print(two_cost * (N // 2) + one_cost)

Solution (Python):
q, h, s, d = [int(item) for item in input().split()]
n = int(input())
smallest1 = min(q*4, h*2, s)
smallest2 = min(smallest1*2, d)

print((n // 2) * smallest2 + (n % 2) * smallest1)

Solution (Python):
ans=0
q,h,s,d=map(int,input().split())
n=int(input())
l=[(q,q*8,0.25),(h,h*4,0.5),(s,s*2,1),(d,d,2)]
l.sort(key=lambda x:-x[1])
while n>0:
    c=l.pop()
    ans+=c[0]*int(n//c[2])
    n-=c[2]*int(n//c[2])
    
print(ans)

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

H = min(2 * Q, H)
S = min(2 * H, S)
D = min(2 * S, D)

m = 0
m += (N // 2) * D
N = N % 2

m += N * S

print(int(m))

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

Solution (Python):
import math
Q,H,S,D = [int(x) for x in input().split()]
N = int(input())
H = min(H,Q*2)
S = min(S,H*2)
D = min(D,S*2)
left = N
cost = 0
cost += (left//2)*D
left = left%2
cost += (left//1)*S
print(int(cost))

Solution (Python):

"""
A - Ice Tea Store
https://atcoder.jp/contests/agc019/tasks/agc019_a

"""
import sys


def solve(Q, H, S, D, N):
    
    q, r = divmod(N, 2)         
    d_prices = sorted([Q*8, H*4, S*2, D]) 
    ans = q * d_prices[0]
    s_prices = sorted([Q*4, H*2, S]) 
    ans += r * s_prices[0]
    return ans


def main(args):
    Q, H, S, D = map(int, input().split())
    N = int(input())
    ans = solve(Q, H, S, D, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
Q,H,S,D = list(map(int,input().split(" ")))
N = int(input())
min05 = min(Q*2,H)
min1 = min(min05*2 ,S)
min2 = min(min1 * 2 , D)

if N %2 == 0:
    print(N//2 * min2)

else:
    print((N-1)//2 * min2 + min1 )

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

if d < one*2:
    print(d*(n//2)+one*(n%2))
else:
    print(one*n)

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

def single():
    return min([S,H*2,Q*4])

def double():
    return min([single()*2,D])

print((N//2)*double()+(N%2)*single())

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

Solution (Python):
Q, H, S, D = [int(i) for i in 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 = (int(i) for i in input().split())
N = int(input())

Qper025L = Q
Hper025L = H / 2
Sper025L = S / 4
Dper025L = D / 8

teainfo = [["Q",Qper025L,Q,0.25],["H",Hper025L,H,0.50],["S",Sper025L,S,1],["D",Dper025L,D,2]]

sortedtea = sorted(teainfo, key = lambda x:(x[1],x[2]), reverse = False)

price = 0

for i in range(4):
    if sortedtea[i][3] <= N:
        numbottles = int(N / sortedtea[i][3])
        N -= sortedtea[i][3] * numbottles
        price += sortedtea[i][2] * numbottles

print(int(price))

Solution (Python):
from math import ceil,floor
Q,H,S,D=map(int,input().split())
N=int(input())
x=min(4*Q,2*H,S)
if N%2==1:
    print(min(N*x ,floor(N/2)*D + x))
else:
    print(min(N*x ,(N//2)*D))

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

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

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

a1 = min(4 * q, 2 * h, s)
a2 = min(d, 2 * a1)

print((n % 2) * a1 + n // 2 * a2)

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

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

Solution (Python):
q,h,s,d=map(int,input().split())
n=int(input())
q1,h1=q*4,h*2
q2,h2,s2=q*8,h*4,s*2
min1=min(q1,h1,s)
min2=min(q2,h2,s2,d)
mintotal=min(min1*2,min2)
if n%2==0:
  ans=n//2*mintotal
else:
  ans=n//2*mintotal+min1
print(ans)

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

H = min(H, 2*Q)
S = min(S, 2*H)
D = min(D, 2*S)

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

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())
ans = 0
q2 = 8*q
h2 = 4*h
s2 = 2*s
b = min(q2,h2,s2,d)
if n >= 2:
    ans += b*(n//2)
    n = n-2*(n//2)
if n == 0:
    print(ans)
else:
    a = 4*q
    b = 2*q +h
    c = 2*h
    print(ans+min(a,b,c,s))

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

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

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

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

cands = [(0, Q*8), (1, H*4), (2, S*2), (3, D)]
cands = sorted(cands, key=lambda x: (x[1], x[0]))
if cands[0][0] == 3:
    if N % 2 == 1:
        dcost = N // 2 * D
        if cands[1][0] == 2:
            print(dcost + S)
        elif cands[1][0] == 1:
            print(dcost + 2 * H)
        else:
            print(dcost + 4 * Q)
    else:
        print(N // 2 * D)
elif cands[0][0] == 2:
    print(N * S)
elif cands[0][0] == 1:
    print(N * 2 * H)
elif cands[0][0] == 0:
    print(N * 4 * Q)

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

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

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

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

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

ans = 0
if n >= 2:
  ans += ((n // 2) * min(8*q, 4*h, 2*s, d))
if n % 2 == 1:
  ans += min(4*q, 2*h, s)
print(int(ans))

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

efficient_num,efficient_cost = 0,8*Q
if(efficient_cost > 4*H): efficient_num,efficient_cost = 1,4*H
if(efficient_cost > 2*S): efficient_num,efficient_cost = 2,2*S
if(efficient_cost > D): efficient_num,efficient_cost = 3,D


min_cost = 0

if(N%2 == 0):
 if(efficient_num == 0): min_cost = int(N/0.25)*Q
 elif(efficient_num == 1): min_cost = int(N/0.50)*H
 elif(efficient_num == 2): min_cost = N*S
 elif(efficient_num == 3): min_cost = (N//2)*D
 

else:
 N = 2*(N//2)
 if(efficient_num == 0): min_cost = int(N/0.25)*Q
 elif(efficient_num == 1): min_cost = int(N/0.50)*H
 elif(efficient_num == 2): min_cost = N*S
 elif(efficient_num == 3): min_cost = (N//2)*D
 
 
 efficient_num,efficient_cost = 0,8*Q
 if(efficient_cost > 4*H): efficient_num,efficient_cost = 1,4*H
 if(efficient_cost > 2*S): efficient_num,efficient_cost = 2,2*S
  
 if(efficient_num == 0): min_cost += int(1/0.25)*Q
 elif(efficient_num == 1): min_cost += int(1/0.50)*H
 elif(efficient_num == 2): min_cost += 1*S
    
print(min_cost)

Solution (Python):
import math as ma
l = list(map(int,input().split()))
N = int(input())
N *= 4
dp = [0 for i in range(9)]
for i in range(1,9):
    dp[i] = min([dp[i-2**j]+l[j] for j in range(min(4,int(ma.log2(i)+1)))])
ans = float('inf')
for i in range(1,9):
    ans = min(ans,N//i*dp[i] + dp[N-N//i*i])
print(ans)

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

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

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

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

Solution (Python):
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)

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

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

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

Solution (Python):
Q, H, S, D = map(int, input().split())
N = int(input())
q, h, s, d = 4 * Q, 2 * H, S, D / 2
if d == min(q, h, s, d) and N >= 2:
    res = D * (N // 2) + (N % 2) * min(q, h, s)
else:
    res = N * min(q, h, s)
print(res)

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

H = min(H, 2 * Q)
S = min(S, 2 * H)
D = min(D, 2 * S)

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

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



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

if D >= 2*S:
    ans = N * S
else:
    ans = N//2 * D + N%2 * S

print(ans)

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



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

if D >= 2*S:
    ans = N * S
else:
    ans = N//2 * D + N%2 * S

print(ans)

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

Solution (Python):


import itertools
import collections
import bisect
import sys
input = sys.stdin.readline

def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    half = min(Q * 2, H)
    one = min(half * 2, S)
    two = min(one * 2, D)
    print(two * (N // 2) + one * (N % 2))

if __name__ == '__main__':
    main()

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

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

Solution (Python):
q,h,s,d = map(int,input().split())
n = int(input())
a = [q*8,h*4,s*2,d]
min_s = min(a[:3]) // 2
min_d = min(a)
b,c = divmod(n,2)
print(b*min_d + c * min_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):
Q, H, S, D = map(int, input().split()) 
N = int(input()) 
min1 = min(2 * Q, H)
min2 = min(2 * min1, S)
min3 = min(2 * min2, D)
print(N // 2 * min3 + N % 2 * min2)

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

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

a = min(8*Q,4*H,2*S,D)
ans = 0

ans += a * (N//2)
if N % 2 :
    ans += min(4*Q,2*H,S)
print(ans)

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

mi = min(q*4, h*2, s)
if n % 2 == 0:
    mi = min(mi*2, d)
    print(n//2 * mi)
else:
    ans = 0
    ans += mi
    n -= 1
    mi = min(mi*2, d)
    print(n//2 * mi + ans)

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

h = min(H,2*Q)
s = min(S,2*h)
d = min(D,2*s)
a,b = divmod(N,2)
print(a*d + b*s)

Solution (Python):
QHSD = [int(i) for i in input().split()]
N = int(input())

ratio = [0]*4

ratio[0] = QHSD[0]*4
ratio[1] = QHSD[1]*2
ratio[2] = QHSD[2]
ratio[3] = QHSD[3]/2

res = 0

m_index = ratio.index(min(ratio))

if m_index == 3:
    res += int(N/2) * QHSD[3]
    N -= int(N/2) * 2


m_index = ratio[:3].index(min(ratio[:3]))

if m_index == 0:
    res += int(N/0.25) * QHSD[0]
elif m_index == 1:
    res += int(N/0.5) * QHSD[1]
elif m_index == 2:
    res += N * QHSD[2]


print(res)

Solution (Python):
  
def solve():
  q,h,s,d= (int(i) for i in input().split())
  n = int(input())
  Ltanka = [4*q,2*h,s]
  L2tanka = [8*q,4*h,2*s,d]
  ans = 0
  while n != 0:
   if n == 1:
    ans += min(Ltanka)
    n-= 1
   else:
    times =  n//2
    ans += times*min(L2tanka)
    n -= times *2
  return ans
  
if __name__ == '__main__':
  print(solve())

Solution (Python):
A = list(map(int, input().split()))
n = int(input())
B = [0.25, 0.5, 1, 2]

C = []
for a, b in zip(A, B):
    c = a / b
    C.append([a, b, c])
    
C.sort(key = lambda x: x[2])

ans = 0
for i in range(len(C)):
    x = n // C[i][1]
    ans += int(x * C[i][0])
    n -= x * C[i][1]
    
print(ans)

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

a = (n // 2 * d) + n % 2 * int(min(s, h // 0.5, q // 0.25))
b = n * int(min(s, h // 0.5, q // 0.25))
ans = min(a, b)
print(int(ans))

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

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

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
q1 = q * 4
h1 = h * 2
ans = 0
if n >= 2:
    buy = min([q1 * 2, h1 * 2, s * 2, d]) * (n // 2)
    n -= n // 2 * 2
    ans += buy
if n > 0:
    ans += min([q1, h1, s])
print(ans)

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

one = min(Q * 4, H * 2)
one = min(one, S)
two = min(2 * one, D)

if one * 2 < two:
    print(one * N)

else:
    tmp = N // 2
    print(tmp * two + N%2 * one)

Solution (Python):
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,D = IL()
N = I()*1000

a = A/250
b = B/500
c = C/1000
d = D/2000
score = [a,b,c,d]
val = {a:(A,250),b:(B,500),c:(C,1000),d:(D,2000)}

score.sort()

ans = 0
for i in score:
    tmp = N//val[i][1]
    N -= tmp*val[i][1]
    ans += tmp*val[i][0]
print(ans)

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

Solution (Python):
val = [int(i) for i in input().split()]
N = int(input())*4

li = [1,2,4,8]

m = [0]*4
for i in range(4):
    m[i] = val[i]*(2**(4-i-1))

ans = 0
while N != 0:
    j = m.index(min(m))
    ans += N//li[j]*val[j]
    N = N%li[j]
    m.pop(j)
    li.pop(j)
    val.pop(j)

print(ans)

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

q_2l = q*8
h_2l = h*4
s_2l = s*2
ans = (n - n%2) //2 * min(q_2l, h_2l, s_2l, d) 
ans += (n % 2) * min(q_2l, h_2l, s_2l) // 2 
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())
a = [q,h,s,d]
b = [4*q,2*h,s]
c = b.index(min(b))

if b[c]*2 > d:
    ans = n//2 * d
    if n % 2 == 1:
        ans += b[c]
else:
    ans = n*b[c]
    
print(ans)

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

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)

print(two*(N//2)+one*(N%2))

Solution (Python):
def solve(Q, H, S, D, N):
    return min(
        N * Q * 4,
        N * H * 2,
        N * S,
        (N // 2) * D + min(S * (N % 2), H * 2 * (N % 2), Q * 4 * (N % 2))
    )

if __name__ == "__main__":
    Q, H, S, D = tuple(map(int, input().split(" ")))
    N = int(input())
    print(solve(Q, H, S, D, N))

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

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

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

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
q1 = q / 0.25
h1 = h / 0.5
s1 = s / 1
d1 = d / 2
minx = min(q1, h1, s1, d1)
a = [[q1, 0.25], [h1, 0.5], [s1, 1], [d1, 2]]
a.sort()
if n % 2 != 0 and a[0][1] == 2:
    print(int((n - 1) // 2 * d) + int(a[1][0]))
else:
    if minx == d1:
        print(int(d * n // 2))
    else:
        print(int(minx * n))

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

ans = (N//2)*maxVal
if N % 2 == 1:
    ans += min(4*Q, 2*H, S)
print(int(ans))

Solution (Python):
ar = list(map(int,input().split(" ")))
br = [ar[0] * 8,ar[1] * 4,ar[2] * 2,ar[3]]
a = int(input())
ar[0] *= 4
ar[1] *= 2
del ar[3]
count = 0
if a >= 2:
    count += min(br) * (a // 2)
    if a % 2 == 1:
        count += min(ar)
else:
    count += min(ar)
print(count)

Solution (Python):


"""
・速攻自力AC
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

q, h, s, d = MAP()
n = INT()

best1L = min(q*4, h*2, s)
best2L = min(d, best1L*2)

if n % 2 == 0:
    print(best2L * (n//2))
else:
    print(best2L * (n//2) + best1L)

Solution (Python):
q,h,s,d = map(int,input().split())
N = int(input())
qp,hp,dp = q*4,h*2,d//2
i = 0
ans = 0
if dp<hp and dp<qp and dp<s:
    ans = d*(N//2)
    N %= 2
ans += min(s,min(hp,qp))*N
print(int(ans))

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


















print((N//2)*min(8*qhsd[0],4*qhsd[1],2*qhsd[2],1*qhsd[3])+(N%2)*min(4*qhsd[0],2*qhsd[1],1*qhsd[2]))

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

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

Solution (Python):



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

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

    print(int(ans))


if __name__ == '__main__':
    main()

Solution (Python):
qhsd = list(map(int, input().split()))
n = int(input()) * 4

m_qhsd = [[qhsd[3], 3], [qhsd[2] * 2, 2], [qhsd[1] * 4, 1], [qhsd[0] * 8, 0]]
qs = [1, 2, 4, 8]
m_qhsd.sort()
ans = 0
while n != 0:
    tmp = m_qhsd.pop(0)
    ans += n // qs[tmp[1]] * qhsd[tmp[1]]
    n %= qs[tmp[1]]
print(ans)

Solution (Python):
a=list(map(int,input().split()))
n=4*int(input())
for i in range(4):
    a[i]=a[i]*(2**(3-i))
h=a[:]
h.sort()
c=0
for i in range(4):
    p=a.index(h[i])
    s=h[i]//(2**(3-p))
    d=n//(8//(2**(3-p)))
    c+=s*d
    n-=d*int(8//(2**(3-p)))
print(c)

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

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

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


q, h, s, d = LI()
n = I()

min_1 = min(4 * q, h * 2, s)
min_2 = min(2 * min_1, d)

print(n // 2 * min_2 + (n % 2) * min_1)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

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



amount = [4 * x for x in LI()]
n = I() * 4

performance = [(amount[i] // (2 ** i), i) for i in range(4)]
performance.sort()

bought_tea, fee = 0, 0
for i in range(4):
    tea = performance[i][1]
    litre = 2 ** tea
    q = (n - bought_tea) // litre
    bought_tea += q * litre
    fee += q * amount[tea]

print(fee // 4)

Solution (Python):
tea = list(map(int,input().split()))
tea[0] *= 4
tea[1] *= 2
N = int(input())
mintea = 0
double = tea[3]
single = min(tea[0:3])
if N == 1:
    print(single)
else:
    print(min(N//2*double + N%2*single,N*single))

Solution (Python):
a1,a2,a4,a8 = map(int, input().split())
n = int(input())
MIN_2 = min(a1*8,a2*4,a4*2,a8)
MIN_1 = min(a1*4,a2*2,a4)
a = (n // 2) 
b = (n - a*2) // 1
print(a*MIN_2+b*MIN_1)

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

one_l = min([4 * Q, 2 * Q + H, H * 2, S])
two_l = min([one_l * 2, D])

if N % 2 == 0:
    print(two_l * (N // 2))
else:
    print(two_l * (N // 2) + one_l)

Solution (Python):
Q,H,S,D=[int(_) for _ in input().split()]

Dmin = min(D,2*S,4*H,8*Q)
Smin = min(S,2*H,4*Q)
N = int(input())
print((N // 2)*Dmin + (N % 2) *Smin)

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

compare2 = [Q*8, H*4, S*2, D]
Q2, H2, S2, D2 = compare2

compare3 = [Q*8, H*4, S*2]
Q3, H3, S3 = compare3

ans = 0
if D2 == min(compare2):
    ans = (N // 2) * D
    N %= 2

if Q3 == min(compare3):
    ans += N * Q * 4
elif H3 == min(compare3):
    ans += N * H * 2
elif S3 == min(compare3):
    ans += N * S

print(ans)

Solution (Python):
S,M,L,B=map(int,input().split())

N=int(input())

if min(8*S,4*M,2*L,B)==8*S:
    print(4*S*N)
elif min(8*S,4*M,2*L,B)==4*M:
    print(2*M*N)
elif min(8*S,4*M,2*L,B)==2*L:
    print(L*N)
elif min(8*S,4*M,2*L,B)==B:
    if N%2==0:
        print(B*N//2)
    else:
        if min(8*S,4*M,2*L)==8*S:
            print(B*(N//2)+4*S)
        elif min(8*S,4*M,2*L)==4*M:
            print(B*(N//2)+2*M)
        elif min(8*S,4*M,2*L)==2*L:
            print(B*(N//2)+L)

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())
plice_dict = {0.25: Q, 0.5: min(2*Q, H), 1: min(4*Q, 2*H, S), 2: min(8*Q, 4*H, 2*S, D)}
result = 0

while N != 0:
    if N > 2:
        result += plice_dict[2] * (N - 2) // 2 if (N - 2) % 2 == 0 else plice_dict[2] * (N - 3) // 2 + plice_dict[1]
        N = 2
    elif N == 2:
        result += plice_dict[2]
        N -= 2
    elif N >= 1:
        result += plice_dict[1]
        N -= 1
    elif N >= 0.5:
        result += plice_dict[0.5]
        N -= 0.5
    else:
        result += plice_dict[0.25]
        N -= 0.25

print(result)

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

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

Solution (Python):
q,h,s,d=map(int,input().split())
N=int(input())
D=sorted([q*8,h*4,s*2,d])
S=sorted([q*4,h*2,s])
print((N//2)*D[0]+(N-(N//2)*2)*S[0])

Solution (Python):
q,h,s,d=map(int,input().split())
N=int(input())
D=[q*8,h*4,s*2,d]
D.sort()
a=D[0]
S=[q*4,h*2,s]
S.sort()
b=S[0]
print((N//2)*a+(N-(N//2)*2)*b)

Solution (Python):
P=[int(i) for i in input().split()]
V=[250, 500, 1000, 2000]
N=int(input())*1000

for i in range(1,4):
    P[i] = min(P[i-1]*2,P[i])

ans = 0
for i in range(3,-1,-1):
    ans += N //V[i] *P[i]
    N = N %V[i]

print(ans)

Solution (Python):
Q, H, S, D = [int(_) for _ in input().split()]
N = int(input())

p1 = min(4 * Q, 2 * H, S)
p2 = min(2 * S, D)
print(min([p2 * (N // 2) + p1 * (N % 2), p1 * N]))

Solution (Python):
import math

q, h, s, d = [int(i) for i in input().split()]
n = int(input())
size = [0.25, 0.5, 1., 2.]
money = [[0.25 / q, q, 0.25], [0.5 / h, h, 0.5],
         [1 / s, s, 1.], [2 / d, d, 2.]]

money = list(reversed(sorted(money)))

totalMoney = 0
while True:
    totalMoney += int(n / money[0][2]) * money[0][1]
    
    n %= money[0][2]
    
    if n == 0:
        print(totalMoney)
        exit()
    del money[0]

"""
leftFlag = True
while True:
    
    totalMoney += int(n/money[0][2])*money[0][1]
    print("add:{} {}cup {}yen".format(int(n/money[0][2])*money[0][1], int(n/money[0][2]), money[0][1]))
    n %= money[0][2]
    print("totalmoney:{}".format(totalMoney))
    if n == 0:
        print(totalMoney)
        exit()
    
    over = [money[0][1], money[0][2]]
    moreGoodExist = False
    for i in range(1, len(money)):
        if math.ceil(n/money[i][2])*money[i][1] < over[0]:
            over =[math.ceil(n/money[i][2])*money[i][1], money[i][2]]
            moreGoodExist = True
    if moreGoodExist:
        del money[0]
    else:
        print(totalMoney + over[0])
        exit()
"""

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

Solution (Python):
q=[int(i) for i in input().split()]
n=int(input())*4
ans=max(q)*n*4
for i in range(4):
    for j in range(4):
        if i==j and i<3:
            ans=min(ans,[q[0]*n,q[1]*n//2,q[2]*n//4][i])
        elif i==j==3 and n%8==0:
            ans=min(ans,q[3]*n//8)
        elif i==3 and n%8 and j<3:
            t=[q[0]*4,q[1]*2,q[2]][j]
            ans=min(ans,q[3]*(n//8)+t)
print(ans)