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



Sample input:
20 30 70 90
3


Sample output:
150

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
n = int(input())
INF = float("inf")
cost_1,cost_2 = INF,INF
for i in range(5):
	for j in range(3):
		for k in range(2):
			if 0.25*i + 0.5*j + 1*k == 1:
				cost_1 = min(cost_1,a*i+b*j+c*k)

for i in range(8):
	for j in range(5):
		for k in range(3):
			for l in range(2):
				if 0.25*i + 0.5*j + 1*k + 2*l == 2:
					cost_2 = min(cost_2, a*i+b*j+c*k+d*l)
ans = 0
if cost_2 <= cost_1 * 2:
	x,y = divmod(n,2)
	ans = x*cost_2 + y*cost_1
else:
	ans = n * cost_1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

PS = [[Q * 8, 0.25], [H * 4, 0.5], [S * 2, 1], [D, 2]]

PS.sort(key=lambda x: x[0])


R = N
ans = 0
for i in range (4):
    if R == 0:
        break
    elif R >= PS[i][1]:
        ans += int(PS[i][0] * PS[i][1] // 2 * (R // PS[i][1]))
        R = R % PS[i][1]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    q, h, s, d = LI()
    n = II()
    q4 = q * 4
    h2 = h * 2
    l1 = min(q4, h2, s)
    l2 = min(l1 * 2, d)
    print((n >> 1) * l2 + (n & 1) * l1)
    
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	Q, H, S, D = MAP()
	N = INT()

	# 単価、価格、容量
	A = [[Q/0.25, Q, 0.25], [H/0.5, H, 0.5], [S/1.0, S, 1.0], [D/2.0, D, 2.0]]
	A.sort()
	# print(A)

	ans = 0
	for a in A:
		cost, price, amt = a
		if N >= amt:
			ans += int(N//amt) * price
			N -= int(N//amt) * amt
		# print(N, ans, amt, N//amt)
	
	print(int(ans))
	
	

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(q: int, h: int, s: int, d: int, n: int):
    print((n // 2) * min(q * 8, h * 4, s * 2, d) + (n % 2) * min(q * 4, h * 2, s))


if __name__ == "__main__":
    q, h, s, d = map(int, input().split())
    n = int(input())

    main(q, h, s, d, n)

Submission status: Accepted

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

#Q,H,Sの中ででいちばん得になるサイズのリットル単価をrとする
r=min(Q*4,H*2,S)

#rはDより得か？
if r*2<D:
    print(N*r)
else:
    print((N//2)*D + (N%2)*r)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
Q, H, S, D = map(int, input().split())
N = int(input())
res = 0
for x in range(1, 3):
  q = Q * (8 // x)
  h = H * (4 // x)
  s = S * (2 // x)
  d = D
  if x == 1: res += (N // 2) * min(q, h, s, d)
  if x == 2: res += N * min(q, h, s)
  N = N % 2
print(res)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

if H > Q+Q:
    H = Q+Q
if S > H+H:
    S = H+H
if D > S+S:
    D = S+S

q,r = divmod(N,2)
answer = q * D + r * S
print(answer)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
Q, H, S, D = map(int, input().split(' '))
N = int(input())

p3 = min([4 * Q, 2 * H, S])
p4 = min([2 * p3, D])


n4 = N // 2
n3 = N - n4 * 2

ans =  p3 * n3 + p4 * n4


print(int(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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)

    if(n&1):
        print(d*(n//2)+s)
    else:
        print(d*(n//2))
resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(Q: int, H: int, S: int, D: int, N: int):
    h1 = min(2*Q, H)
    h1 = min(h1*2, S)
    d1 = D

    ans = 0
    if 2*h1 < d1:
        print(N*h1)
    else:
        if N%2 == 0:
            print((N//2)*d1)
        else:
            print((N//2)*d1 + h1)
    
    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))  # type: int
    H = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ret = 0
for i in range(4) :
  ret += (N // order[i][1]) * order[i][0]
  N %= order[i][1]
  
print(ret)

Submission status: Accepted

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 32

Q, H, S, D = map(int, input().split())
q = Decimal(Q * 4)
h = Decimal(H * 2)
s = Decimal(S)
d = Decimal(D / 2)

arr = [(q, Q, Decimal(0.25)), (h, H, Decimal(0.5)), (s, S, Decimal(1.0)), (d, D, Decimal(2.0))]
arr.sort()

N = int(input())

ans = 0
while N > 0:
    for _, cost, quantity in arr:
        if N >= quantity:
            ans += (N // quantity) * cost
            N -= (N // quantity) * quantity
print(int(ans))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces


Q, H, S, D = rl()
N = ri()
if 2 * Q < H:
    H = 2 * Q
if 2 * H < S:
    S = 2 * H
if 2 * S < D:
    D = 2 * S
answer = N // 2 * D + N % 2 * S
print(answer)
#30

Submission status: Accepted

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

d1 = min([8*q,4*h,2*s,d])
s1 = min([4*q,2*h,s])

ans = 0
if n >= 2:
    ans += n//2*d1
    n = n%2
    if n == 1:
        ans += s1
elif n == 1:
    ans = s1
    
print(ans)

Submission status: Accepted

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

L2 = [8*q,4*h,2*s,d]
L2.sort()
L1 = [4*q,2*h,s]
L1.sort()
L5 = [2*q,h]
L5.sort()
L25 = [q]

ans = 0
if n >= 2:
    ans += n//2*L2[0]
    n = n%2
    if n == 1:
        ans += L1[0]
elif n == 1:
    ans = L1[0]
elif n == 0:
    ans = 0
    
print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    ls = list(map(int, readline().split()))
    n = int(readline())
    ls[1] = min(ls[1], ls[0] * 2)
    ls[2] = min(ls[2], ls[1] * 2)
    ls[3] = min(ls[3], ls[2] * 2)
    t = 0
    for i in range(3, -1, -1):
        if i == 3:
            t += n // 2 * ls[i]
            n -= n // 2 * 2
        elif i == 2:
            t += n // 1 * ls[i]
            n -= n // 1 * 1
        elif i == 1:
            t += n / 0.5 * ls[i]
            n -= n // 0.5 * 0.5
        else:
            t += n // 0.25 * ls[i]
            n -= n // 0.25 * 0.25
        if n == 0:
            break
    print(int(t))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from sys import stdin

q,h,s,d = [int(x) for x in stdin.readline().rstrip().split()]
n = int(stdin.readline().rstrip())

li = [q*4,h*2,s,d/2]

if min(li) == q*4:
    print(n*q*4)
elif min(li) == h*2:
    print(n*h*2)
elif min(li) == s:
    print(n*s)
else:
    if n%2 == 1:
        li.pop()
        li.sort()
        print(n//2*d+li[0])
    else:
        print(n//2*d)

Submission status: Accepted

Solution code:
yen = list(map(int,input().split()))
N = int(input())
lista = [4*yen[0], 2*yen[1], yen[2]]

yen1 = min(lista)
if 2*yen1 <= yen[3]:
    print(N*yen1)
else:
    if N%2 == 0:
        print(int((N//2)*yen[3]))
    else:
        print(int( (N//2)*yen[3] + yen1))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    Q, H, S, D = LI()
    N = I()
    economical2 = min(Q*8, H*4, S*2, D)
    economical1 = min(Q*4, H*2, S)
    ans = (N//2)*economical2 + (N%2)*economical1
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    Q, H, S, D = mi()
    N = ii()
    N *= 4
    dp = [10**10] * 9
    dp[0] = 0
    for i in range(1, 9):
        dp[i] = min(dp[i - 1] + Q, dp[i])
    for i in range(2, 9):
        dp[i] = min(dp[i - 2] + H, dp[i])
    for i in range(4, 9):
        dp[i] = min(dp[i - 4] + S, dp[i])
    for i in range(8, 9):
        dp[i] = min(dp[i - 8] + D, dp[i])
    # print(dp)
    m = min(8 * Q, 4 * H, 2 * S, D)
    print(m * (N // 8) + dp[N % 8])
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 )

Submission status: Accepted

Solution code:
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=0

ans+=N//2*D
N%=2
N*=2
ans+=N//2*S
N%=2
N*=2
ans+=N//2*H
N%=2
N*=2
ans+=N//2*Q

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

N = int(input())
answer = 0

if N&1:
  answer += S

answer += (N//2)*D
print(answer)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs,copy
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

c = l()

n = onem()

cc = []

for i in range(4):
    cc.append([c[i],i])

cc[-1][0] /= 2

cc[0][0] *= 4
cc[1][0] *= 2



cc.sort()

su = 0

i = 0
while n:
    kkk = cc[i][1]
    if kkk == 0:
        su += 4 * c[kkk] * n
        n = 0
    elif kkk == 1:
        su += 2 * c[kkk] * n 
        n = 0
    elif kkk == 2:
        su += c[kkk]*n
        n = 0
    else:
        su += c[kkk] * (n//2)
        n %= 2
    i += 1
print(su)

Submission status: Accepted

Solution code:

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

N = int(input())

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

ans += N * min(S , H * 2,Q * 4)

print (ans)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input()) * 4
L = sorted([ [8*q, q, 1], [4*h, h, 2], [2*s, s, 4], [d, d, 8] ])
A = [ i[1:] for i in L ]
ans = 0
for p, a in A:
  ans += (n//a) * p
  n %= a
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    q, h, s, d = list(map(int, readline().split()))
    n = int(readline())
    h = min(h, q * 2)
    s = min(s, h * 2, q * 4)
    d = min(d, s * 2, h * 4, q * 8)
    cnt = 0
    cnt += n // 2 * d
    n -= n // 2 * 2
    cnt += n // 1 * s
    n -= n // 1
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
ps = []
l = 0.25
for p in map(int,input().split()):
  ps.append([p/l, l, p])
  l *= 2
ps.sort()

n = int(input())
ans = 0
for unitp, l, p in ps:
  num = int(n//l)
  ans += num*p
  n -= int(num*l)
  
print(ans)

Submission status: Accepted

Solution code:
# from operator import itemgetter
# import math
q, h, s, d = map(int, input().split())
n = int(input())

ans = 0

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

if n == 1:
        # print("case1")
        ans = s
elif n%2 == 0:
        # print("case2")
        ans = n//2 * d
elif n%2 != 0:
        # print("case3")
        ans = (n-1)//2 * d + s
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

Q, H, S, D = list(map(int, sys.stdin.buffer.readline().split()))
N = int(sys.stdin.buffer.readline())

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# AGC019
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
# print(a,b)
if n%2==0:
    print(min(b*(n//2),a*n))
else:
    print(min(b*(n//2)+a,a*n))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())*4
#小数点の挙動がよくわからなかったため，全部4倍して0.25を基準としたらうまく行った
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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]

# main()
print(main())

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

# Q : 1
# H : 2
# S : 4
# D : 8
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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

#1 2 4 8
n *= 4

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

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

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

ans += n

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
inp = list(map(int,input().split()))
q = inp[0] #0.25
h = inp[1] #0.5
s = inp[2] #1
d = inp[3] #2
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))