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: Wrong Answer

Solution code:
"""
    Author        : Arif Ahmad
    Date          :
    Algo          :
    Difficulty    :
"""
from sys import stdin, stdout
from fractions import gcd


def main():
    q, h, s, d = [int(_) for _ in stdin.readline().strip().split()]
    n = int(stdin.readline().strip())

    val = ((8 * q, .25, q), (4 * h, .5, h), (2 * s, 1, s), (d, 2, d))
    val = sorted(val)
    # print(val)

    ans = 0

    for i in range(4):
        x = n // val[i][1]
        #print('n:', n, 'x:', x)
        ans += (x * val[i][2])
        n -= (x * val[i][1])

    stdout.write(str(int(ans)) + '\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
Q,H,S,D = map(int,input().split(" "))
N = float(input())
qp,N = int(N / 2),N - int(N / 2)
hp,N = int(N / 1),N - int(N / 1)
sp,N = int(N / 0.5),N - int(N / 0.5)
dp,N = int(N / 0.25),N - int(N / 0.25)

print(qp * Q + hp * H + sp * S + dp * D)

Submission status: Wrong Answer

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
cnt = 0
for x in sorted([(Q, Q, 0.25), (H/2, H, 0.5), (S/4, S, 1.0), (D/8, D, 2.0)]):
    cnt += (N // x[2]) * x[1]
    N %= x[2]

print(int(cnt))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


v = [q, h, s, d]
l = [0.25, 0.5, 1, 2]
s2 = sorted([8 * q, 4 * h, 2 * s, d])
s1 = sorted([4 * q, 2 * h, s])
sh = sorted([2 * q, h])
shh = sorted([q])

s = [s2[0], s1[0], sh[0], shh[0]]
l = sorted(l, reverse=True)
cnt = 0
for i, _v in enumerate(s):
    nd = n // l[i]
    n %= l[i]
    cnt += nd*_v
print(int(cnt))

Submission status: Wrong Answer

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


v = [q, h, s, d]
l = [0.25, 0.5, 1, 2]
s2 = (sorted(enumerate([8 * q, 4 * h, 2 * s, d]), key=lambda x: x[1]))
s1 = (sorted(enumerate([4 * q, 2 * h, s]), key=lambda x: x[1]))
sh = (sorted(enumerate([2 * q, h]), key=lambda x: x[1]))
shh = (sorted(enumerate([q]), key=lambda x: x[1]))

s = [s2[0], s1[0], sh[0], shh[0]]
l = sorted(l, reverse=True)
cnt = 0
for i, _v in enumerate(s):
    nd = n // l[i]
    n %= l[i]
    cnt += nd*_v[1]
print(int(cnt))

Submission status: Wrong Answer

Solution code:
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)
    print (size, times)
    N -= size * times
    ans += val[i] * times
# for i in sortedIndex:
#     while N > temp:
#         if(N < temp + 0.25 * (2 ** i)):
#             break
#         temp += 0.25 * (2 ** i)
#         ans += val[i]

print (ans)

Submission status: Wrong Answer

Solution code:
Q, H, S, D = map(int,input().split())
N = int(input( ) )
per_yen2=sorted([4*Q, 2*H, S,D//2 ] )
per_yen1 = sorted( [4*Q, 2*H, S ] )
if N%2==0:
  print(N*per_yen2[0])
else:
    print((N-1)*per_yen2[0]+per_yen1[0])

Submission status: Wrong Answer

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

prices = [q * 4, h * 2, s, d/2]
prices = sorted(prices)

nep = n % 2 == 1

n -= n % 2
res = n * prices[0]

prices = [q * 4, h * 2, s]
prices = sorted(prices)

if(nep):
    res += prices[0]

print(int(res))

Submission status: Wrong Answer

Solution code:
#AGC019A

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

Submission status: Wrong Answer

Solution code:
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 * single, double)

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

Submission status: Wrong Answer

Solution code:
prices = list(map(int, input().split()))
n = int(input())
sizes = [0.25,0.5,1,2]
tanka = []
for i in range(4):
    t = prices[i]/sizes[i]
    tanka.append(t)
additional_size = 1
money = 0
while additional_size > 0:
    s = tanka.index(min(tanka))
    needed_size =  n//sizes[s]
    additional_size = n%sizes[s]
    money += needed_size * prices[s]
    n = n - sizes[s] * needed_size
    del prices[s]
    del sizes[s]
    del tanka[s]
print(int(money))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

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)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

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])
while n:
    for i, j in l:
        if j <= n:
            a = n // j
            n %= j
            ans += a * i
print(ans)

Submission status: Wrong Answer

Solution code:
a=input()
l=len(a)
b=1+(l*(l-1)//2)
for i in range(97,123):
    c=a.count(chr(i))
    d=(c*(c-1))//2
    b-=d
print(b)

Submission status: Wrong Answer

Solution code:
def sym(s):                                                                                                                                                                                                 
    even = True if len(s)%2 == 0 else False                                                                                                                                                                 
                                                                                                                                                                                                            
    if len(s) < 4:                                                                                                                                                                                          
        if even:                                                                                                                                                                                            
            f = s[:len(s)//2]                                                                                                                                                                               
            l = s[len(s)//2:]                                                                                                                                                                               
                                                                                                                                                                                                            
            return f == l[::-1]                                                                                                                                                                             
                                                                                                                                                                                                            
        else:                                                                                                                                                                                               
            f = s[:len(s)//2]                                                                                                                                                                               
            l = s[len(s)//2 + 1:]                                                                                                                                                                           
                                                                                                                                                                                                            
            return f == l[::-1]                                                                                                                                                                             
    else:                                                                                                                                                                                                   
        if s[0] != s[-1]:                                                                                                                                                                                   
            return False                                                                                                                                                                                    
        else:                                                                                                                                                                                               
            return True                                                                                                                                                                                     
                                                                                                                                                                                                            
                                                                                                                                                                                                            
A = input()                                                                                                                                                                                                 
L = len(A)                                                                                                                                                                                                  
                                                                                                                                                                                                            
r = range(L)                                                                                                                                                                                                
                                                                                                                                                                                                            
count = 1                                                                                                                                                                                                   
                                                                                                                                                                                                            
                                                                                                                                                                                                            
a = [sum([1 if not sym(A[i:j+1]) else 0 for j in r[i+1:]]) for i in r[:L-1]]                                                                                                                                
#for i in r[:L-1]:                                                                                                                                                                                          
#    for j in r[i+1:]:                                                                                                                                                                                      
#        s = A[i:j+1]                                                                                                                                                                                       
#        if not sym(s):                                                                                                                                                                                     
#            count += 1                                                                                                                                                                                     
                                                                                                                                                                                                            
#print(count)                                                                                                                                                                                               
print(sum(a)+1)

Submission status: Wrong Answer

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
n = n * 1000
a = 2000
b = 1000
c = 500
d2 = 250

tmp = int(n % a)
ans = int(n / a) * d

if tmp > 0:
    ans1 = int(tmp/b) * s
    ans += int(tmp/b) * s
    tmp = int(tmp % b)

if tmp > 0:
    ans2 = int(tmp / c) * h
    tmp += int(tmp % c) * h
    tmp = int(tmp %c)

if tmp > 0:
    ans3 = int(tmp / d2) * q
    ans += int(tmp/d2) * q
    tmp = int(tmp % d2)
    tmp = int(tmp % d2)


print(ans)

Submission status: Wrong Answer

Solution code:
value_list = list(map(int, input().split()))
N = int(input())

size_list = [2, 1, 0.5, 0.25]

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

value_list.reverse()

d = N
m = 0

total = 0

for i in range(len(size_list)):
    temp_d = d // size_list[i]
    temp_m = d % size_list[i]
    total += temp_d * value_list[i]
    d = temp_m

print(int(total))

Submission status: Wrong Answer

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
n = n * 1000
a = 2000
b = 1000
c = 500
d2 = 250

tmp = int(n % a)
ans = int(n / a) * d
print("1 + " + str(ans))

if tmp > 0:
    ans1 = int(tmp/b) * s
    ans += int(tmp/b) * s
    tmp = int(tmp % b)
    print("1 " + str(ans1))
    print("1 + " + str(ans))

if tmp > 0:
    ans2 = int(tmp / c) * h
    tmp += int(tmp % c) * h
    tmp = int(tmp %c)
    print("2 " + str(ans2))
    print("2 + " + str(ans))

if tmp > 0:
    ans3 = int(tmp / d2) * q
    ans += int(tmp/d2) * q
    tmp = int(tmp % d2)
    tmp = int(tmp % d2)
    print("3 " + str(ans3))
    print("3 + " + str(ans))

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  s = input().rstrip().split(' ')
  one_l = [int(s[0])*4, int(s[1])*2, int(s[2])]
  twe_l = int(s[3])
  N = int(input())
  if N % 2 == 0:
    if min(one_l)*2 > twe_l:
      print(twe_l * (N / 2))
    else:
      print(min(one_l) * N)
  else:
    if N == 1:
      print(min(one_l))
      exit()
    if min(one_l)*2 > twe_l:
      print(twe_l + min(one_l) * (N-2))
    else:
      print(min(one_l) * N)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  s = input().rstrip().split(' ')
  one_l = [int(s[0])*4, int(s[1])*2, int(s[2])]
  twe_l = int(s[3])
  N = int(input())
  if N % 2 == 0:
    if min(one_l) > twe_l:
      print(twe_l * (N / 2))
    else:
      print(min(one_l) * N)
  else:
    if N == 1:
      print(min(one_l))
      exit()
    if min(one_l)*2 > twe_l:
      print(twe_l + min(one_l) * (N-2))
    else:
      print(min(one_l) * N)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=long(raw_input())
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
        k=long(n/l[i][1])
        ans+=(l[i][0]*k*l[i][1])/2
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = raw_input().split()
n=input()
a=a*4
b=b*2
x=int(d)

if x==d:
	if n%2==0:
		n=n/2
		c+=n*x
	else:
		n=n/2
		c+=n*x
		
		c+=x
print c

Submission status: Wrong Answer

Solution code:
def one_row():
	res = tuple(map(int, input().split()))
	return res
def multi_rows(n):
	return [one_line() for _ in range(n)]

def a():
	print('hi')
	res =	multi_lines(1)
	print(res)
	
def a():
	import numpy as np
	q, h, s, d = one_row()
	l = [.25, .5, 1, 2]
	p = [q, h, s, d]
	n = int(input())
	price = [q*8, h*4, s*2, d]
	order = np.argsort(price)
	total = 0
	for i in order:
		times = n // l[i]
		total += times * p[i]
		n -= times * l[i]
	print(int(total))
	
a()

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  s = input().rstrip().split(' ')
  one_l = [int(s[0])*4, int(s[1])*2, int(s[2])]
  twe_l = int(s[3])
  N = int(input())
  if N % 2 == 0:
    if min(one_l) > twe_l:
      print(twe_l/2 * N)
    else:
      print(min(one_l) * N)
  else:
    if N == 1:
      print(min(one_l))
      exit()
    if min(one_l)*2 > twe_l:
      print(twe_l + min(one_l) * (N-2))
    else:
      print(min(one_l) * N)

Submission status: Wrong Answer

Solution code:
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)

for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] == a[j]:
            total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
value_list = list(map(int, input().split()))
N = int(input())

size_list = [2, 1, 0.5, 0.25]

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

value_list.reverse()

d = N
m = 0

total = 0

for i in range(len(size_list)):
    temp_d, temp_m = divmod(d, size_list[i])
    total += temp_d * value_list[i]
    d = temp_m

print(int(total))

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=long(raw_input())
q1=q/0.25
h1=h/0.5
s1=s/1
d1=d/2
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
        k=long(n/l[i][1])
        ans+=(l[i][0]*k*l[i][1])
        n-=(k*l[i][1])
        if n<=0:
            break
print long(ans)

Submission status: Wrong Answer

Solution code:
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)

for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] == a[j]:
            total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
A = list(input())
N = len(A)
uq_list = []
halfN = N // 2

count = 1
for i in range(0, N):
    tempstr = A[i]
    for j in range(i+1, N):
        if A[j] != tempstr:
            count += 1

print(count)

Submission status: Wrong Answer

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

P = 0

for q in range(0,4 * N):
    for h in range(0, 4 * N- q):
        for s in range(0, 4 * N - q - 2 *  h):
            for d in range(0,4 * N - q - 2 *  h - 4 * s):

                if 4 * N == q + 2 * h + 4 * s + 8 * d and P ==0:
                    P = Q * q + H * h + S * s + D * d

                elif 4 * N == q + 2 * h + 4 * s + 8 * d:
                    tmp = Q * q + H * h + S * s + D * d

                    if 0 < tmp < P:
                        P = tmp

            continue
print(P)

Submission status: Wrong Answer

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

#print arr.index(min(arr))

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

    #print "target",target
    if target==3:
        en+=n/2*tmp[target]
        n=float(n)%2
    elif target==2:
        en+=float(n)/1.00*tmp[target]
        break
        #n=float(n)%1
    elif target==1:
        en+=float(n)/0.50*tmp[target]
        break
        #n=float(n)%0.5
    elif target==0:
        en+=float(n)/0.25*tmp[target]
        #n=float(n)%0.25
        break
    #print n
    #print en,"en"
    if n==0:
        break
print int(en)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=long(raw_input())
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,1],[h1,2],[s1,4],[d1,8]]
l.sort()
ans=0
for i in range(4):
        k=long(4*n/l[i][1])
        ans+=l[i][0]*k*l[i][1]/8
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans)

Submission status: Wrong Answer

Solution code:
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=long(raw_input())
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
        k=long(n/l[i][1])
        ans+=l[i][0]*k*l[i][1]/2
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=input()
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
        k=long(n/l[i][1])
        ans+=l[i][0]*k*l[i][1]
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans/2)

Submission status: Wrong Answer

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

#print arr.index(min(arr))

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

    #print "target",target
    if target==3:
        en+=math.floor(float(n)/2.00)*tmp[target]
        n=float(n)%2
    elif target==2:
        en+=float(n)/1.00*tmp[target]
        break
        #n=float(n)%1
    elif target==1:
        en+=float(n)/0.50*tmp[target]
        break
        #n=float(n)%0.5
    elif target==0:
        en+=float(n)/0.25*tmp[target]
        #n=float(n)%0.25
        break
    #print n
    #print en,"en"
    if n==0:
        break
print int(en)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=input()
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
        k=int(n/l[i][1])
        ans+=l[i][0]*k*l[i][1]
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans/2)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(long,raw_input().split())
n=input()
q1=q*8
h1=h*4
s1=s*2
d1=d
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
    if l[i][1]>n:
        continue
    else:
        k=int(n/l[i][1])
        ans+=l[i][0]*k*l[i][1]
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans/2)

Submission status: Wrong Answer

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

print(per_2l_price)
print(per_1l_price)
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)

Submission status: Wrong Answer

Solution code:
q,h,s,d=map(int,raw_input().split())
n=input()
q1=q/0.25
h1=h/0.5
s1=s
d1=d/2.0
l=[[q1,0.25],[h1,0.5],[s1,1.0],[d1,2.0]]
l.sort()
ans=0
for i in range(4):
    if l[i][1]>n:
        continue
    else:
        k=int(n/l[i][1])
        ans+=l[i][0]*k*l[i][1]
        n-=k*l[i][1]
        if n<=0:
            break
print long(ans)

Submission status: Wrong Answer

Solution code:
s = input()

count = 1

for i in range(1, len(s)):
    ss = s[0:i]
    # print(ss, s[i])

    n = len(ss) - ss.count(s[i])
    count += n
    # print(n, count)
print(count)

Submission status: Wrong Answer

Solution code:

def f(n):
    if n in dp:
        return dp[n]
    if n<0:
        return -1

    #print(dp)
    minv=10**9
    minq=-1
    for i,sq in enumerate(q):
        tmp=n-sq
        #print(sq,tmp)
        s=f(tmp)
        #print(s)
        if s>=0:
            if minv>s+a[i]:
                minv=s+a[i]
                minq=sq

    if minq>0:
        dp[n]=minv
        return minv
    else:
        return -1

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



import numpy as np
q=[0.25,0.5,1,2]
#a=[20,30,70,90]
a=spaceinput()
N=int(input())

cp=np.array(a)/q
mi=np.argmin(cp)


dp={}
dp[q[0]]=a[0]
dp[0]=0

'''
k=1
while True:
    tmp=a[k]*k
    if tmp>N:
        break
    dp[k*q[k]]=tmp

    k+=1
'''


f(min(70,N))
minv=10**40
for k in dp:
    if k==0:
        continue
    s=N/np.float(k)

    if (s)%1.0==0:
        tmp=dp[k]*s
        if minv>tmp:
            minv=tmp


print(int(minv))

Submission status: Wrong Answer

Solution code:
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(5):
    x = cosp.index(min(cosp))
    a = v[x]
    b = int(N//a)
    if b == 0:
        cosp[x] = 10**8 + 10
        continue
    N = N - a*b
    ans = ans + b*c[x]
    if N <= 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def f(n):
    if n in dp:
        return dp[n]
    if n<0:
        return -1

    #print(dp)
    minv=10**9
    minq=-1
    for i,sq in enumerate(q):
        tmp=n-sq
        #print(sq,tmp)
        s=f(tmp)
        #print(s)
        if s>=0:
            if minv>s+a[i]:
                minv=s+a[i]
                minq=sq

    if minq>0:
        dp[n]=minv
        return minv
    else:
        return -1

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



import numpy as np
q=[0.25,0.5,1,2]
#a=[20,30,70,90]
a=spaceinput()
N=int(input())

cp=np.array(a)/q
mi=np.argmin(cp)


dp={}
dp[q[0]]=a[0]
dp[0]=0

'''
k=1
while True:
    tmp=a[k]*k
    if tmp>N:
        break
    dp[k*q[k]]=tmp

    k+=1
'''


f(min(80,N))
minv=10**40
for k in dp:
    if k==0:
        continue
    s=N/np.float(k)

    if (s)%1.0==0:
        tmp=dp[k]*s
        if minv>tmp:
            minv=tmp


print(int(minv))

Submission status: Wrong Answer

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

per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0


mincost = min(per_2l_price)
needtobuy_m += mincost * (needtobuy_l // 2.0)
needtobuy_l = needtobuy_l - 2.0 * (N // 2.0)
mincost = min(per_1l_price)
needtobuy_m += mincost * (needtobuy_l // 1.0)

print(int(needtobuy_m))

Submission status: Wrong Answer

Solution code:
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D)
N = int(input())
per_2l_price = [Q*8, H*4, S*2, D]
per_1l_price = [Q*4, H*2, S]
per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0


mincost = min(per_2l_price)
needtobuy_m += mincost * (needtobuy_l // 2.0)
needtobuy_l = needtobuy_l - 2.0 * (N // 2.0)
mincost = min(per_1l_price)
needtobuy_m += mincost * (needtobuy_l // 1.0)

print(int(needtobuy_m))

Submission status: Wrong Answer

Solution code:
def f(n):
    if n in dp:
        return dp[n]
    if n<0:
        return -1

    #print(dp)
    minv=10**9
    minq=-1
    for i,sq in enumerate(q):
        tmp=n-sq
        #print(sq,tmp)
        s=f(tmp)
        #print(s)
        if s>=0:
            if minv>s+a[i]:
                minv=s+a[i]
                minq=sq

    if minq>0:
        dp[n]=minv
        return minv
    else:
        return -1

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



import numpy as np
q=[0.25,0.5,1,2]
#a=[20,30,70,90]
a=spaceinput()
N=int(input())

cp=np.array(a)/q
mi=np.argmin(cp)

dp={}
dp[q[0]]=a[0]
dp[0]=0

'''
k=1
while True:
    tmp=a[k]*k
    if tmp>N:
        break
    dp[k*q[k]]=tmp

    k+=1
'''


f(min(5,N))
minv=10**20
for k in dp:
    if k==0:
        continue
    s=N/np.float(k)

    if (s)%1.0==0:
        tmp=dp[k]*s
        if minv>tmp:
            minv=tmp


print(int(minv))

Submission status: Wrong Answer

Solution code:
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D) # price 0.25 0.5 1.0 2.0
N = int(input())
per_2l_price = [Q*8, H*4, S*2, D]
per_1l_price = [Q*4, H*2, S]
per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0

if N % 2.0 == 0:
    mincost = min(per_2l_price)
    needtobuy_m += mincost * (N // 2.0)
else:
    mincost = min(per_2l_price)
    needtobuy_m += mincost * (needtobuy_l // 2.0)
    needtobuy_l = needtobuy_l - 2.0 * (N // 2.0)
    mincost = min(per_1l_price)
    needtobuy_m += mincost * (needtobuy_l // 1.0)


print(int(needtobuy_m))

Submission status: Wrong Answer

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

d_buy = n // 2
s_buy = (n % 2) // 1
h_buy = (n % 1) // 0.5
q_buy = (n % 0.5) // 0.25

cp = [q*8, h*4, s*2, d]
if min(cp) == cp[0]:
    q_buy += d_buy * 8
    d_buy = 0
elif min(cp) == cp[1]:
    h_buy += d_buy * 4
    d_buy = 0
elif min(cp) == cp[2]:
    s_buy += d_buy * 2
    d_buy = 0

cp = [q*8, h*4, s*2]
if min(cp) == cp[0]:
    q_buy += s_buy * 4
    s_buy = 0
elif min(cp) == cp[1]:
    h_buy += s_buy * 2
    s_buy = 0

cp = [q*8, h*4]
if min(cp) == cp[0]:
    q_buy += h_buy * 2
    h_buy = 0



sum = d * d_buy + s * s_buy + h * h_buy + q * q_buy
print(int(sum))