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 operator import itemgetter
 
a=list(map(int,input().split()))
n=4*int(input())
p=[]
for i in range(4):
    p.append([2**i,a[i]*4,(a[i]*4)/2**i])
 
 
p=sorted(p,key=itemgetter(2))
 
ans=0
 
for i in range(4):
    t=n//p[i][0]
    ans += t*p[i][1]
    n -= t*p[i][0]
 
print(ans//4)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    ans = INF
    ans = min(ans, N * 4 * Q)
    ans = min(ans, N * 2 * H)
    ans = min(ans, N * 1 * S)
    d = N // 2
    if N % 2 == 0:
        ans = min(ans, d * D)
    else:
        ans = min(ans, d * D + Q * 4)
        ans = min(ans, d * D + H * 2)
        ans = min(ans, d * D + S)

    print(ans)


if __name__ == '__main__':
    main()

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(S*N)
else:
    ans=0;
    if N%2==1:
        ans+=S
    
    ans+=(N//2)*D
    print(ans)

Solution (Python):
input1 = input("").split(" ")
Q = int(input1[0])
H = int(input1[1])
S = int(input1[2])
D = int(input1[3])
N = int(input(""))

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

Solution (Python):
input1 = input("").split(" ")
Q = int(input1[0])
H = int(input1[1])
S = int(input1[2])
D = int(input1[3])
N = int(input(""))

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

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

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

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
print(int(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())
s = min(s, 2*min(h, 2*q))
if 2*s >= d:
    print(d*(n//2)+s*(n%2))
else:
    print(s*n)

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

if not(1<=Q<=10**8 and 1<=H<=10**8 and 1<=S<=10**8 and 1<=D<=10**8):
	print("input error1")

QQ=Q*4
HH=H*2

QQQ=8*Q
HHH=4*H
SSS=2*S
N=int(input())

if not(1<=N<=10**9):
	print("input error2")

if N==1:
	sum=min(QQ,HH,S)
else:
	sum+=(N//2)*min(QQQ,HHH,SSS,D)
	if N%2==1:
		sum+=min(QQ,HH,S)

print(sum)

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

q=Q
h=min(2*Q,H)
s=min(4*Q,2*H,S)
d=min(8*Q,4*H,2*S,D)

fee=int(N/2)*d

N-=int(N/2)*2

while N>=1:
    fee+=s
    N-=1

while N>=0.5:
    fee+=h
    N-=0.5

while N>0:
    fee+=q
    N-=0.25

print(fee)

Solution (Python):





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

    
    QN = 4*Q
    HN = 2*H
    SN = S
    DN = D/2.0

    
    cost = 0
    if min(QN, HN, SN, DN) == DN:
        cost += N//2 * D
        cost += N%2  * min(QN, HN, SN)
    else:
        cost += N * min(QN, HN, SN)

    print(cost)

if __name__ == "__main__": main()

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
rate = {0.25:q/0.25, 0.5:h/0.5, 1:s, 2:d/2.0}
rate = sorted(rate.items(), key=lambda x:x[1])
if rate[0][0] == 2 :
    ans = n//2 * d
    ans += n%2 * int(rate[1][1])  
else :
    ans = n * int(rate[0][1])

print(ans)

Solution (Python):
import sys




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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    q, h, s, d = read_int_list()
    n = read_int()
    a, b = divmod(n, 2)
    res = min([a * d + b * s,
               a * d + 2 * b * h,
               a * d + 4 * b * q,
               n * s,
               2 * n * h,
               4 * n * q])
    print(res)


main()

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

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

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

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)

res = 0

if S <= D/2:
    res = N * S
else:
    res = ((N // 2) * D) + ((N % 2) * S)

print(res)

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

q = Q
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())

q = Q

if 2*q < H:
    h = 2*q
else:
    h = H
    
if 2*h < S:
    s = 2*h
else:
    s = S

if 2*s < D:
    d = 2*s
else:
    d = D
    
print((N//2)*d + N%2*s)

Solution (Python):
val = list(map(int, input().split()))
N = int(input())
price = [v / (2 ** i)  for i, v in enumerate(val)]
sortedIndex = []
sortedPrice = sorted(price)
price2 = price.copy()
for p in sortedPrice:
    sortedIndex.append(price2.index(p))
    price2[price2.index(p)] = -1

temp = 0
ans = 0
for i in sortedIndex:
    size  = (0.25 * (2 ** i))
    times = int(N / size)
    
    N -= size * times
    ans += val[i] * times







print (ans)

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

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

l = min(q, h, s)
if l < d // 2:
    print(n * l)
else:
    if n % 2 == 0:
        print(d * n // 2)
    else:
        print(d * (n // 2) + l)

Solution (Python):

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

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

pricesfor2 = [q * 8, h * 4, s * 2, d]
pricesfor2 = sorted(pricesfor2)

nep = n % 2 == 1

n //= 2

res = n * pricesfor2[0]

if(nep):
    res += min(q * 4, min(h * 2, s))

print(res)

Solution (Python):
V = [int(i) for i in input().split()]
N = int(input())
V2 = [V[i]*(8//(2**i)) for i in range(4)]
V1 = [V2[i]//2 for i in range(3)]
ans = N//2*min(V2) + (N%2)*min(V1)
print(ans)

Solution (Python):
from operator import itemgetter, attrgetter
import sys

a = [] 
b = [] 
for line in sys.stdin:
    a.append(line)


N = float(a[1]) 

b = list(map(int, list(a[0].strip().split()))) 
Q = b[0]
H = b[1]
S = b[2]
D = b[3]

list_tuples_origin = [
	(1, Q, 8 * Q),
	(2, H, 4 * H),
	(4, S, 2 * S),
	(8, D, D),
]

list_tuples = sorted(list_tuples_origin, key=lambda list: list[2])

value = 0

M = int(4 * N)

while True:
	
	if M == 0:
		break
	s = list_tuples[0][0]
	v = list_tuples[0][1]

	sho = M // s
	amari = M % s
	M = amari
	value += sho * v

	del list_tuples[0]
print(value)

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

Solution (Python):


q,h,s,d=map(int,raw_input().split())
n=int(raw_input())
res=0
if n%2:
 res=min(q*8,h*4,s*2,d)*(n-1)/2+min(q*4,h*2,s)
else:
 res=min(q*8,h*4,s*2,d)*n/2
print res

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

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

print n / 2 * two + n % 2 * one

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

Solution (Python):
if __name__ == '__main__':
    quarter, half, single, double = list(map(int, input().split()))
    N = int(input())
    new_single = min(4 * quarter, 2 * half, single)
    new_double = min(2 * new_single, double)

    if N % 2 == 1:
        print(new_double * (N // 2) + new_single)
    else:
        print(new_double * (N // 2))

Solution (Python):

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

Solution (Python):
n025, n05, n1, n2 = map(int, raw_input().split())
n = input()
ans = 0

if n >= 2:
    arr = []
    arr.append(n025 * 8)
    arr.append(n05 * 4)
    arr.append(n1 * 2)
    arr.append(n2)
    ans += min(arr) * (n / 2)

arr = []
arr.append(n025 * 4)
arr.append(n05 * 2)
arr.append(n1)
ans += min(arr) * (n % 2)

print ans

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

Solution (Python):
from operator import itemgetter

a=list(map(int,input().split()))
n=4*int(input())
p=[]
for i in range(4):
    p.append([2**i,a[i]*4,(a[i]*4)/2**i])


p=sorted(p,key=itemgetter(2))

ans=0

for i in range(4):
    t=n//p[i][0]
    ans += t*p[i][1]
    n -= t*p[i][0]

print(ans//4)

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

    tea1l = min(Q * 4, H * 2, S)
    price = min(D * (N // 2) + tea1l * (N % 2), N * tea1l)

    print(price)

main()

Solution (Python):


Q, H, S, D = list(map(int, input().split()))
N = int(input())
n = N * 4
ans = 0
l = sorted([(Q, 1), (H, 2), (S, 4), (D, 8)], key = lambda x : x[0]/x[1])
for i, j in l:
    if j <= n:
        a = n // j
        n %= j
        ans += a * i
print(ans)

Solution (Python):
prices = [int(x) for x in input().split()]
sizes = [2000, 1000, 500, 250]
N = int(input()) * 1000
totalPrice = 0
remainSize = N
ratios = []

for i in range(len(prices)-1):
	if(prices[i]*2 < prices[i+1]):
		prices[i+1] = prices[i]*2

prices.reverse()

for i in range(len(prices)):
	totalPrice += remainSize//sizes[i] * prices[i]
	remainSize = remainSize%sizes[i]

print(totalPrice)

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

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

if n % 2 == 0:
    print(min(x * n, n // 2 * d))
elif 2 * x < d:
    print(x * n)
else:
    print(d * (n // 2) + x)

Solution (Python):
import sys
from collections import deque
import copy
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def calc_min_yen(Q, H, S, D, N):
    Q_ = Q * 4
    H_ = H * 2
    min_yen_1l = min([Q_, H_, S])
    if N > 2:
        use_2l = (N/2) * D  + N % 2 * min_yen_1l
    else:
        use_2l =  2**63-1
    return min(use_2l , N * min_yen_1l)


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);

    input_raw = read_func().strip().split()
    [Q, H, S, D] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3])]
    input_raw = read_func().strip().split()
    [N] =[int(input_raw[0])]

    print calc_min_yen(Q, H, S, D, N)

if __name__ == '__main__':
    main()

Solution (Python):
import math
tmp=map(int, raw_input().split(" "))
num=int(raw_input())
en=0
arr=[]
k=1
for i in tmp:
    arr.append(float(i)/k)
    k=k*2



n=num
while True:
    if n >= 2:
        target=arr.index(min(arr))
    else:
        target=arr[0:3].index(min(arr[0:3]))
    
    
    
    

    
    if target==3:
        en+=n/2*tmp[target]
        n=n%2

    elif target==2:
        en+=n*tmp[target]
        break
        
    elif target==1:
        en+=n*2*tmp[target]
        break
        
    elif target==0:
        en+=n*4*tmp[target]
        
        break
    
    
    if n==0:
        break
print int(en)

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

c = D,S,H,Q
v = 2,1,0.5,0.25
cosp =  [ D*1, S*2, H*4, Q*8 ]
ans = 0

for _ in range(3):
    x = cosp.index(min(cosp))
    a = v[x]
    b = int(N//a)
    if b == 0:
        cosp[x] = 10**9
        continue
    N = N - a*b
    ans = ans + b*c[x]
    if N == 0:
        break

print(ans)

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

needtobuy_l = N
needtobuy_m = 0
per_2l_price = [D,
                S*2, S+H*2, S+H+Q*2,
                H*4, H*3+Q*2, H*2+Q*4, H+Q*6,
                Q*8]
per_1l_price = [S,
                H*2, H+Q*2,
                Q*4]

if needtobuy_l % 2 == 0:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
else:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
    mincost = min(per_1l_price)
    needtobuy_m += mincost * 1

print(needtobuy_m)

Solution (Python):

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

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

N = int(input())
ans = 0

Q *= 4
H *= 2
twiceQ = Q * 2
twiceH = H * 2
twiceS = S * 2

a = N % 2
if a == 0:
    num = N // 2
    ans += num * min(twiceQ, twiceH, twiceS, D)
else:
    num = (N-1) // 2
    ans += num * min(twiceQ, twiceH, twiceS, D)
    ans += min(Q, H, S)

print(ans)

Solution (Python):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

q, h, s, d = read_line(int, int, int, int)
n, = read_line(int)






menu = sorted({0.25: (q, q * 4), 0.5: (h, h * 2), 1: (s, s), 2: (d, d * 0.5)}.items(), key = lambda x: x[1][1])



charge = 0
while True:
    for size, (price, _) in menu:
        if n >= size:
            count = int(n // size)
            charge += count * price
            n -= size * count
        if n == 0:
            print(int(charge))
            exit()

Solution (Python):

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

import numpy as np

s = [1,2,4,8]
p = [Q,H,S,D]
cp = np.array([p[i]/s[i] for i in range(4)]).argsort()


n = N
c = 0

for i in cp:
    ni = n//s[i]
    
    n -= s[i] * ni
    c += p[i] * ni
print(c)

Solution (Python):
a,b,c,d=[int(i) for i in input().split()]
M=[4*a,2*b,c,d/2]
N=int(input())

if M[0]==min(M):
    print(N*M[0])
elif M[1]==min(M):
    print(N*M[1])
elif M[2]==min(M):
    print(N*M[2])
else:
    if N%2==0:
        print(int(N//2*int(M[3]*2)))
    else:
        if M[0]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[0])
        elif M[1]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[1])
        elif M[2]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[2])

Solution (Python):

def inpl(): return tuple(map(int, input().split()))

volume = [1, 2, 4, 8]
value = {k:v for k, v in zip(volume, inpl())}
cosp = {k:v/k for k, v in value.items()}
N = int(input())
N = N*4
res = 0

for k, _ in sorted(cosp.items(), key=lambda x: x[1]):
    res += (N // k)*value[k]
    N = N % k
print(int(res))

Solution (Python):
from sys import stdin
a = map(int,stdin.readline().split())
n = int(stdin.readline())
mul = [1,2,4,8]
n = 4*n
b = []
for i in xrange(4):
    b.append( ((8/mul[i]) *a[i], a[i], mul[i])  )
b.sort()
ans = 0
for x,y,z in b:
    co = n/z
    ans += co * y
    n-= co * z
    
print ans

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

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

q = 4 * Q * N
h = 2 * H * N
s = S * N

if N == 1:
    d = float('inf')
else:
    d = (N // 2 * D)
    if N % 2 == 1:
        d+=min(4*Q,2*H,S)
print(min(q,h,s,d))

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
l = [q,h,s,d]
up = sorted([(q, 1, 0), (h/2, 2,1), (s/4, 4, 2), (d/8, 8, 3)])

nq = n * 4
price = 0
for i, e in enumerate(up):
    if nq >= e[1]:
        nn, nq = divmod(nq, e[1])
        price += l[e[2]] * nn
print(int(price))

Solution (Python):
q, h, s, d = list(map(int, input().split())) 
N = bin(4*int(input()))[2:]
keta0 = int(N[-1])
keta1 = 0
keta2 = 0
keta3 = 0

if len(N) >1:
    keta1 = int(N[-2])
if len(N) >2:
    keta2 = int(N[-3])
if len(N) >3:
    for i in range(len(N) -3):
        keta3 += int(N[-(i+4)])*2**i
keta = [keta0, keta1, keta2, keta3]

a = [[q*8 ,q, 0], [h*4, h, 1], [s*2,s, 2], [d,d, 3]]
a.sort(key=lambda x:x[0])
ans = 0
for i in a:
    for j in range(i[2],4):
        ans += i[1]*keta[j]*2**(j-i[2])
        keta[j] = 0
print(ans)

Solution (Python):
Q, H, S, D = [int(i) for i in input().split()]                                                       
N = int(input())                                                                                     
                                                                                                     
price = [Q, H, S, D]                                                                                 
vol = [0.25, 0.5, 1, 2]                                                                              
unit = [Q*4, H*2, S, D//2]                                                                           
                                                                                                     
p = 0                                                                                                
idx = 4                                                                                              
while True:                                                                                          
    idx = unit.index(min(unit[:idx]))                                                                
                                                                                                     
    p += int(N / vol[idx]) * price[idx]                                                              
    N -= vol[idx]*int(N / vol[idx])                                                                  
                                                                                                     
    if N == 0:                                                                                       
        break;  

print(int(p))

Solution (Python):

def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    prices = get_ln_int_inputs()
    N = get_ln_int_inputs()[0]
    M = N * 4

    prices_per_8litre = [prices[i] * (1 << (3 - i)) for i in range(4)]
    price_rank = [prices_per_8litre.index(price_per_8l) for price_per_8l in sorted(prices_per_8litre)]

    result = [0, 0, 0, 0]

    idx = 0
    if price_rank[idx] == 3:
        result[3] += M // 8
        M %= 8
        idx += 1
    
    cp = price_rank[idx]
    result[cp] += M // (1 << cp)

    print(sum(prices[i] * result[i] for i in range(4)))
    return


main()

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

A = [Q, H, S, D]
B = [0.25, 0.5, 1, 2]
M = [Q*4, H*2, S, D/2]

result = 0
for i in range(4):
    m = min(M)
    j = M.index(m)
    M.remove(m)
    b = B[j]
    n = N%B[j]
    if b == 0.25:
        result += N*4*A[j]
    elif b == 0.5:
        result += N*2*A[j]
    else:
        result += N//B[j]*A[j]
    if n == 0:
        break
    N = n

print(result)

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

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

if n % 2 == 0:
    print(min(x * n, n // 2 * d))
elif 2 * x < d:
    print(x * n)
else:
    print(d * (n // 2) + x)

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

x2 = min([q*8, h*4, s*2, d])
x1 = min([q*4, h*2, s])
ret = (n // 2) * x2
n %= 2
ret += (n) * x1
print(int(ret))

Solution (Python):




import numpy as np

qhsd = raw_input()
qhsd = qhsd.split()
qhsd = map(int,qhsd)

n = raw_input()
n = int(n)

a = np.zeros(4,dtype = np.int64)
a[0] = qhsd[0]*8
a[1] = qhsd[1]*4
a[2] = qhsd[2]*2
a[3] = qhsd[3]

b = np.zeros(4,dtype = np.int64)
for i in range(4):
    b[i] = np.argmin(a)
    a[np.argmin(a)] = max(a)+1

l = [0.25,0.5,1,2]

new_qhsd = [qhsd[0]*4,qhsd[1]*2,qhsd[2],qhsd[3]]
new_l = [1,1,1,2]

ans = 0

for i in b:
    x = n / new_l[i]
    n = n % new_l[i]
    ans += new_qhsd[i] * x
    

print ans

Solution (Python):
a=map(int,raw_input().split())
n=int(raw_input())
b=[4,2,1,0.5]
c = zip(a,b)
c = sorted(c,key=lambda x : x[0]*x[1])
res = 0
if c[0][1] < 0.7 :
    res = (n//2)*c[0][0] + ((n%2)*c[1][1])*c[1][0]
else :
    res = n*c[0][1]*c[0][0]
print res

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

L2=x[3]
L1=x[2]
L05=x[1]
L025=x[0]
lowestL1=min(L1,L05*2,L05+L025*2,L025*4)

if (lowestL1*2<L2):
    print('{0}'.format(N*lowestL1))
    quit()

n=int(N/2)
print('{0}'.format(n*L2+(N%2)*lowestL1))


quit()

Solution (Python):
if __name__ == '__main__':
    Q, H, S, D = map(int, input().split())
    N = int(input())
    
    
    
    sizes = {'Q' : int(Q * 4.0), 'H' : int(H * 2.0), 'S' : S, 'D' : int(D * 0.5)}
    sizes = sorted(sizes.items(), key=lambda x: x[1])
    sum_price = 0
    while N > 0:
        for size in sizes:
            if size[0] != 'D':
                sum_price += size[1] * N
                N = 0
            else:
                num = int(N / 2)
                N -= 2 * num
                sum_price += D * num
    print(sum_price)

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

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

d_num, s_num = n//2, n%2
cost = d_num*d + s_num*s
print(cost)

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

LITTER = [0.25, 0.5, 1, 2]
cost = [Q, H, S, D]


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

result = 0
bought = 0
for i in reversed(range(4)):
    quantity = int((N - bought) / LITTER[i])
    bought += quantity * LITTER[i]
    result += quantity * cost[i]

print(int(result))

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)*(n%2))

Solution (Python):


def main():
    price = list(map(int, input().split()))
    a = [None]*4
    for i in range(4):
        a[i] = (2**i, price[i]*4/2**i, price[i])
    n = int(input())*4
    a = sorted(a, key=lambda x:x[1])
    res = 0
    
    for q, c, p in a:
        res+=(n//q)*p
        n = n%q
    print(int(res))


if __name__ == '__main__':
    main()

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)*(n%2))

Solution (Python):

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


def read():
    Q, H, S, D = ILI()
    N = II()
    return (Q, H, S, D, N)


def solve(Q, H, S, D, N):
    l_all = []
    l_all.append((Q * 8, "q"))
    l_all.append((H * 4, "h"))
    l_all.append((S * 2, "s"))
    l_all.append((D, "d"))
    l_all.sort(key= lambda x: x[0])
    if N % 2 == 0:
        ans = (N // 2) * l_all[0][0]
    else:
        ans = (N // 2) * l_all[0][0]
        if l_all[0][1] != "d":
            ans += l_all[0][0] // 2
        else:
            ans += l_all[1][0] // 2
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

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

cost = 0
div2 = n // 2

a = min(q * 8, h * 4, s * 2, d)

n -= div2 * 2
cost += div2 * a

if n == 1:
    a = min(q * 4, h * 2, s)

    cost += a

print(int(cost))

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

values = [(Q * 8, Q, 0.25), (H * 4, H, 0.5), (S * 2, S, 1), (D, D, 2)]
values.sort()

sum_v = 0
sum_cost = 0
idx = 0
while sum_v < N and idx < 4:
    v = values[idx][2]
    n = (N - sum_v) // v
    sum_v += n * v
    sum_cost += int(values[idx][1] * n)
    idx += 1

print(sum_cost)

Solution (Python):
import sys




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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    q, h, s, d = read_int_list()
    n = read_int()
    res = 0
    a = n % 2
    res += min([s * a, h * 2 * a, q * 4 * a])
    a = n - a
    res += min([d * a // 2, s * a, h * 2 * a, q * 4 * a])
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

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

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

ans = 0
t = Q*4
if t>H*2:
    t = H*2
if t>S:
    t = S
if t*2>D:
    ans = (N//2)*D
    N = N%2
ans += t*N
    
print(ans)

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

N = N*4

price = [Q,H,S,D]
quas = [1, 2, 4, 8]

che = [(Q*8, 0), (H*4, 1), (S*2, 2), (D, 3)]
che.sort()

ans = 0
for (hoge, ind) in che:
	qua = quas[ind]
	now = price[ind]

	ans += (N // qua) * now
	N %= qua

print(ans)

Solution (Python):
P = list(map(int,input().split()))
V = [1,2,4,8]

n = 4*int(input())



VP = []
bv, bp = 0,1
for v,p in zip(V,P):
  if bv*p < v*bp:
    VP.append((v,p))
    bv,bp = v,p

result = 0
for v,p in reversed(VP):
  result += (n//v)*p
  n %= v

print(result)

Solution (Python):
if __name__ == "__main__":
    Q,H,S,D = map(int, input().split())
    N = int(input())
    result = 2 ** 100

    TQ = N * 4 * Q
    result = min(result, TQ)

    TH = N * 2 * H
    result = min(result, TH)

    TS = N * S
    result = min(result, TS)

    if (N >= 2):
        tmp_N = N
        res = tmp_N // 2 * D
        tmp_N -=  tmp_N // 2 * 2

        TQ = tmp_N * 4 * Q
        result = min(result, TQ + res)
        TH = tmp_N * 2* H
        result = min(result, TH + res)
        TS = tmp_N * S
        result = min(result, TS + res)

    print (result)

Solution (Python):
P = map(int, raw_input().split())
N = int (raw_input())*4
for i in range(1,4):
    if P[i] > P[i-1]*2:
        P[i]=P[i-1]*2
ans=0
t=8
for i in range(1,5):
    ans += N/t*P[-i]
    N %= t
    t/=2
print ans

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

Solution (Python):
x1, x2, x3, x4 = map(int, raw_input().split())
n = int(raw_input())
ans = 0
if x1 + x1 < x2:
	x2 = x1 + x1
if x2 + x2 < x3:
	x3 = x2 + x2
if x3 + x3 < x4:
	x4 = x3 + x3
n = n * 4
k = n // 8
ans += k * x4
n = n - k * 8
k = n // 4
ans += k * x3
n -= k * 4
k = n // 2
ans += k * x2
n -= k * 2
ans += k * x1
print ans

Solution (Python):
from fractions import Fraction

a, b, c, d = map(int, raw_input().split())
N = input()

A = a / Fraction(1, 4)
B = b / Fraction(1, 2)
C = c / Fraction(1, 1)
D = d / Fraction(2, 1)
ans = 0

if D < A and D < B and D < C:
    ans += N / 2 * d
    ans += min(A, B, C) * (N % 2)
else:
    ans += min(A, B, C) * N

print int(ans)

Solution (Python):
import sys

cin = sys.stdin


def line2N():
    return map(int, cin.readline().split())

A = list(line2N())
N, = line2N()
B = list(A)
B[0] *= 4
B[1] *= 2
B[3] /= 2

idx = 0
bMin = B[0]
for i in range(1,3):
    if B[i]<B[idx]:
        idx = i
        bMin = B[i]

cnt = 0
if B[3]==min(B):
    cnt += N//2*A[3]
    N %= 2
    cnt += N*B[idx]
else:
    cnt += N*B[idx]

print(cnt)

Solution (Python):


def main():
    q, h, s, d = (int(x) for x in input().split())
    n = int(input())

    one_l = min(q * 4, h * 2, s)
    two_l = d

    if two_l / 2 < one_l:
        cost = (n // 2) * two_l + (n % 2) * one_l
    else:
        cost = n * one_l

    print(cost)


if __name__ == "__main__":
    main()

Solution (Python):
arr =[int(x) for x in raw_input().split()]
n = int(raw_input())
ans = 0
for i in xrange(4):
	arr[i] = 2**(3-i)*arr[i]
while(True):
	if(n>=2):
		ans += (n/2)*min(arr)
		n -= (n/2)*2
	elif(n==1):
		for i in xrange(4):
			arr[i] = arr[i]/2
		ans += min(arr[0:3])
		n-=1
	else:
		break
print ans

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

q, h, s, d = rli()
n = ri()

m1 = min([q*4, h*2, s])

if(n == 1):
    print(m1)
else:
    m2 = min(m1*2, d)
    print(m2*(n//2) + m1*(n%2))

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
pq = q*8
ph = h*4
ps = s*2
pd = d
if pq < ph and pq < ps and pq < pd:
    print(n*q*4)
elif ph < ps and ph < pd:
    print(n*h*2)
elif ps < pd:
    print(n*s)
elif n%2 == 0:
    print((n>>1) * d)
elif pq < ph and pq < ps:
    print((n>>1)*d + q*4)
elif ph < ps:
    print((n>>1)*d + h*2)
else:
    print((n>>1)*d + s)

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

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

ans = n // 2 * d
if n % 2 == 1:
    ans += s

print(ans)

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

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

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

Solution (Python):
quat, half, one, two = (int(x) for x in input().split())
n = int(input())

if 4 * quat < one:
    one = 4 * quat
if 2 * half < one:
    one = 2 * half
if 2 * one < two:
    print(one * n)
else:
    print(two * (n // 2) + one * (n % 2))

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)

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

Solution (Python):
q, h, s, d = map(int, input().split())
n = int(input())
ans = []
ans.append((n//0.25)*q)
ans.append((n//0.5)*h)
ans.append((n//1)*s)
if n % 2 != 0:
    ans.append((n//2)*d+min(q*4, h*2, s))
else:
    ans.append((n//2)*d)
print(int(min(ans)))