Problem:


入場料金

アイヅ温泉には、浴場とプールがあり、浴場を利用するには入浴券を、プールを利用するにはプール券をそれぞれ買う必要があります。これらの券の値段は、日によって変わるかもしれません。また、アイヅ温泉には以下のようなルールがあります。

 券は購入当日１回の利用に限り有効。

 「入浴券５枚以上かつプール券２枚以上」でまとめて買うと、すべての券が２割引になる。

温泉好きの貞吉さんとその友人たちは、アイヅ温泉に毎日のように通っています。彼らは皆気まぐれで、日によって使う枚数は異なります。アイヅ温泉には割引ルールがあるため、グループで協力して上手に買えば、合計料金を安く済ますことができるかもしれません。

入浴券とプール券の料金、使用する入浴券の枚数とプール券の枚数が入力として与えられたとき、最も安い合計料金を出力するプログラムを作成してください。ただし、使用する枚数より多く券を買うことで合計料金が安くなるなら、買った券すべてを使わなくともよいものとします。

入力

入力は以下の形式で与えられる。

N
x1 y1 b1 p1
x2 y2 b2 p2
:
xN yN bN pN

１行目のN(1 ≤ N ≤ 365)は料金を計算したい日数である。続くN行に、i日目の入浴券の料金xi(100 ≤ xi ≤ 1000)、プール券の料金yi(100 ≤ yi ≤ 1000)、使用する入浴券の枚数bi(0 ≤ bi ≤ 6)、使用するプール券の枚数pi(0 ≤ pi ≤ 6)が与えられる。入浴券とプール券共に料金は50円刻みである。

出力

それぞれの日について最も安い合計料金を１行に出力する。

入力例 1

2
100 100 1 1
1000 500 5 2

出力例 1

200
4800

入力例 2

5
500 500 1 1
500 500 5 2
1000 100 0 6
1000 100 6 0
100 1000 0 0

出力例 2

1000
2800
600
4960
0



Sample input:
2
100 100 1 1
1000 500 5 2


Sample output:
200
4800

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(N):
    x,y,b,p = list(map(int,input().split()))


    def calc(x,y,b,p):
        m = min(p//2,b//5)
        return 0.8*(5*m*x + 2*m*y) + (b-5*m)*x + (p-2*m)*y
    
    v = []
    v.append(calc(x,y,b,p))
    add_p = 2 - p % 2
    add_b = 5 - b % 5
    v.append(calc(x,y,b+add_b,p))
    v.append(calc(x,y,b,p+add_p))
    v.append(calc(x,y,b+add_b,p+add_p))
    print(int(min(v)))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    a,b,c,d=map(int,input().split())
    q,w,e,r=0,0,0,0
    q,w=a*c,b*d
    e=q+w
    if c<=5 and d>=2:
        e=e*0.8
    e=int(e)
    print(e)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    a,b,c,d=map(int,input().split())
    q,w,e,r=0,0,0,0
    q,w=a*c,b*d
    e=q+w
    if c>=5 and d>=2:
        e=e*0.8
    e=int(e)
    print(e)

Submission status: Wrong Answer

Solution code:
n=input()
for i in range(n):
	x,y,b,p=map(int,raw_input().split())
	if b>4 and p>2:print (x*b+y*p)*8/10
	elif b>4:print min(x*b+y*p,(x*b+y*2)*8/10)
	else:print min(x*b+y*p,(x*5+y*2)*8/10)

Submission status: Wrong Answer

Solution code:
n=input()
for i in range(n):
	x,y,b,p=map(int,raw_input().split())
	if b>4 and p>1:print (x*b+y*p)*8/10
	elif b>4:print min(x*b+y*p,(x*b+y*2)*8/10)
	else:print min(x*b+y*p,(x*5+y*2)*8/10)

Submission status: Wrong Answer

Solution code:
n=input()
for i in range(n):
	x,y,b,p=map(int,raw_input().split())
	print min(x*b+y*b,(x*max(b,5)+y*max(p,2))*8/10)

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    x,y,b,p = list(map(int,input().split()))


    def calc(x,y,b,p):
        m = min(p//2,b//5)
        #return 0.8*(5*m*x + 2*m*y) + (b-5*m)*x + (p-2*m)*y
        c = x*b + y*p
        return 0.8*c if m > 0 else c
    
    v = []
    v.append(calc(x,y,b,p))
    add_p = 2 - p % 2
    add_b = 5 - b % 5
    v.append(calc(x,y,b+add_b,p))
    v.append(calc(x,y,b,p+add_p))
    v.append(calc(x,y,b+add_b,p+add_p))
    print(int(min(v)))
    #print(v)

Submission status: Accepted

Solution code:
while True:
  try: n=int(input())
  except: break;
  for i in range(n):
    (x,y,b,p)=map(int,input().split())
    s=b*x+p*y
    t=(max(b,5)*x+max(p,2)*y)*4//5
    print(min(s,t))

Submission status: Accepted

Solution code:
for i in range(int(input())):
  (x,y,b,p)=map(int,input().split())
  print(min(b*x+p*y,(max(b,5)*x+max(p,2)*y)*4//5))

Submission status: Accepted

Solution code:
import sys
f = sys.stdin


n = int(f.readline())

for line in f:
    x, y, b, p = map(int, line.split())
    regular = x * b + y * p
    discount = int(x * 0.8) * max(b, 5) + int(y * 0.8) * max(p, 2)
    print(min(regular, discount))

Submission status: Accepted

Solution code:
n = input()
for i in range(n):
    x, y, b, p = map(int, raw_input().strip().split(" "))
    if b >= 5 or p >= 2:
        if b < 5:
            print min(x * b + y * p, (x * 5 + y * p) * 4 / 5)
        elif p < 2:
            print min(x * b + y * p, (x * b + y * 2) * 4 / 5)
        else:
            print  (x * b + y * p) * 4 / 5
    else:
        print x * b + y * p

Submission status: Accepted

Solution code:
N = input()
for i in range(N):
    s = map(int, raw_input().split())
    x = s[0]
    y = s[1]
    bath = s[2]
    pool = s[3]
    fee = x * bath + y * pool
    disc_fee = max(bath, 5) * x + max(pool, 2) * y
    disc_fee = disc_fee * 4 / 5
    print "%d" % min(fee, disc_fee)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    x,y,b,p=map(int,input().split())
    print(min(b*x+p*y,(x*max(b,5)+y*max(p,2))*4//5))

Submission status: Accepted

Solution code:
# Aizu Problem 0278: Admission Fee

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


N = int(input())
for k in range(N):
    x, y, b, p = [int(_) for _ in input().split()]
    print(min(x * b + y * p, (x * max(b, 5) + y * max(p, 2)) * 8 // 10))

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
    a,b,c,d=map(int,input().split())
    q,w,e,r,g=0,0,0,0,0
    q,w=a*c,b*d
    e=q+w
    f=[]
    f.append(e)
    if c<5 and d<2:
        g=(a*5+b*2)*0.8
        f.append(g)
    if c<5 and d>=2:
        g=(a*5+b*d)*0.8
        f.append(g)
    if c>=5 and d<2:
        g=(a*c+b*2)*0.8
        f.append(g)
    if c>=5 and d>=2:
        e=e*0.8
        f.append(e)
    print(int(min(f)))

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    x, y, b, p = map(int, input().split())
    if b >= 5 and p >= 2:
        print(int((x*b + y*p) * 0.8))
    else:
        regular_price = x*b + y*p
        if b < 5:
            b = 5
        
        if p < 2:
            p = 2

        discount = int((x*b + y*p) * 0.8)
        if regular_price <= discount:
            print(regular_price)
        else:
            print(discount)

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x, y, b, p = map(int, input().split())
    if b >= 5 and p >= 2:
        print((x*b + y*p)*4//5)
    else:
        normal = x*b + y*p
        discounted = ( x*max(5, b) + y*max(2, p) )*4//5
        if normal < discounted:
            print(normal)
        else:
            print(discounted)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    x, y, a, b = map(int, input().split())
    print(min(x * a + y * b, int(0.8 * (x * max(5, a) + y * max(2, b)))))

Submission status: Accepted

Solution code:
# AOJ 0278: Admission Fee
# Python3 2018.6.25 bal4u

n = int(input())
for i in range(n):
	x, y, b, p = map(int, input().split())
	sm = x*b + y*p
	if b < 5: b = 5
	if p < 2: p = 2
	print(min(sm, ((x*b+y*p)*4)//5))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
  x, y, b, p = map(int, input().split())
  cost = x * b + y * p
  if b >= 5 and p >= 2:
    print(cost * 4 // 5)
    continue
  print(min(cost, (x * max(5, b) + y * max(2, p)) * 4 // 5))

Submission status: Accepted

Solution code:
for i in range(input()):
    x, y, b, p = map(int, raw_input().split())
    cost1 = x * b + y * p
    cost2 = (x * max(b, 5) + y * max(p, 2)) * 0.8
    print "%d" % min(cost1, cost2)

Submission status: Accepted

Solution code:
n=input()
for i in range(n):
	x,y,b,p=map(int,raw_input().split())
	if b>4 and p>1:print (x*b+y*p)*8/10
	elif b>4:print min(x*b+y*p,(x*b+y*2)*8/10)
	elif p>1:print min(x*b+y*p,(x*5+y*p)*8/10)
	else:print min(x*b+y*p,(x*5+y*2)*8/10)

Submission status: Accepted

Solution code:
n=input()
for i in range(n):
	x,y,b,p=map(int,raw_input().split())
	print min(x*b+y*p,(x*max(b,5)+y*max(p,2))*8/10)

Submission status: Accepted

Solution code:
for i in range(input()):
	x,y,b,p=map(int,raw_input().split())
	print min(x*b+y*p,(x*max(b,5)+y*max(p,2))*8/10)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    x,y,b,p = map(int,input().split())
    s = x * b + y * p
    t = int((x * 5 + y * 2) * 0.8)
    u = s
    if s <= t:
        print(s)

    else:
        if 5 - b > 0:
            u += (5 - b) * x

        if 2 - p > 0:
            u += (2 - p) * y
        print(min(s,int(u * 0.8)))

Submission status: Accepted

Solution code:
N=int(input())
s=[]
ans=[]

for i in range(N):
    s.append(list(map(int,input().split())))

for i in range(N):
    tmp=s[i][0]*s[i][2]+s[i][1]*s[i][3]
    if s[i][2]>=5 and s[i][3]>=2:
        tmp*=0.8
        ans.append(int(tmp))
    else:
        if s[i][2]>=5:
            tmp2=tmp+s[i][1]*(2-s[i][3])
            tmp2*=0.8
        elif s[i][3]>=2:
            tmp2=tmp+s[i][0]*(5-s[i][2])
            tmp2*=0.8
        else:
            tmp2=tmp+s[i][0]*(5-s[i][2])+s[i][1]*(2-s[i][3])
            tmp2*=0.8
        ans.append(int(min(tmp,tmp2)))

for i in range(N):
    print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())
for _ in range(N):
	A = []
	x, y, b, p = map(int, input().split())
	s = x*b+y*p  #全部バラ
	A.append(int(s))
	wari = 0.8*(5*x+2*y)
	for i in range(1, 4):
		s = wari*i
		if b-(5*i)>0:
			s += 0.8*(b-(5*i))*x
		if p-(2*i)>0:
			s += 0.8*(p-(2*i))*y
		A.append(int(s))
	print(min(A))

Submission status: Accepted

Solution code:
inputs = [list(map(int, input().split())) for _ in range(int(input()))]
ans = []

def niwari(x, y, _b, _p):
  b = 5 if _b < 5 else _b
  p = 2 if _p < 2 else _p
  return int(0.8*(x*b+y*p))

for inpt in inputs:
  x, y, b, p = inpt
  if b >= 5 and p >= 2:
    # まとめ買いで2割引
    ans.append(str(int((x*b+y*p)*0.8)))
  else:
    ans.append(str(min(int(x*b+y*p), niwari(x, y, b, p))))

print('\n'.join(ans))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x, y, b, p = map(int, input().split())
    pr = x * b + y * p
    s = int((max(b, 5) * x + max(p, 2) * y) * 0.8)
    if s < pr:
        print(s)
    else:
        print(pr)

Submission status: Accepted

Solution code:
N = int(input())
xybp = [list(map(int,input().split())) for _ in range(N)]
for X in xybp:
    x,y,b,p = X[0],X[1],X[2],X[3]
    kouho1 = x*b+y*p
    if b <= 5 and p <= 2:
        kouho2 = 0.8*x*5+0.8*y*2
    elif b > 5 and p <= 2:
        kouho2 = 0.8*x*b+0.8*y*2
    elif b <= 5 and p > 2:
        kouho2 = 0.8*x*5+0.8*y*p
    else:
        kouho2 = 0.8*x*b+0.8*y*p
    print(min(kouho1,int(kouho2)))

Submission status: Accepted

Solution code:
day_n = int(input())

for _ in range(day_n):

    bath_p, pool_p, bath_n, pool_n = map(int, input().split())

    normal_sum = bath_p * bath_n + pool_p * pool_n
    
    if bath_n >= 5 and pool_n >= 2:
        print(int(normal_sum * 0.8))
    else:
        discounted_sum = normal_sum
        
        if bath_n < 5:
            discounted_sum += bath_p * (5 - bath_n)
        
        if pool_n < 2:
            discounted_sum += pool_p * (2 - pool_n)
        
        discounted_sum *= 0.8
        
        print(int(min(normal_sum, discounted_sum)))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    x, y, b, p = [int(x) for x in input().split()]
    
    f = x * b + y * p
    d = max(5,b)* x + max(2, p) * y
    d = int(d * 0.8)
    print(min(f,d))

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    x, y, b, p = map(int, input().split())
    print(min(x*b+y*p, (x*max(b,5)+y*max(p,2))*4//5))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Admission Fee
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0278

"""
import sys


def solve():
    x, y, b, p = map(int, input().split())
    p1 = x * b + y * p
    p2 = (x * max(b, 5) + y * max(p, 2)) * 8 // 10
    return min(p1, p2)


def main(args):
    N = int(input())
    for _ in range(N):
        ans = solve()
        print(ans)


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

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    x, y, b, p = map(int, input().split())
    print(int(min(x*b + y*p, (x*max(b, 5) + y*max(p, 2))*0.8)))

Submission status: Accepted

Solution code:

N = int(input())

for l in range(N):
    x,y,b,p = [int(i) for i in input().split()]
    
    ans = x*b + y*p
    
    if b < 5:
        b = 5
    if p < 2:
        p = 2
            
    ans = min(ans, (x*b + y*p) * 4 // 5)

    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    x, y, b, p = map(int, input().split())
    print(min(x*b+y*p, (x*max(b,5)+y*max(p,2))*4//5))

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
    x,y,b,p=map(int,input().split())
    if b>=5 and p>=2:
        print(int((x*b+y*p)*0.8))
    else:
        keep=x*b+y*p
        if b<5:b=5
        if p<2:p=2
        keep2=int((x*b+y*p)*0.8)
        print(min(keep,keep2))

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    x, y, b, p = map(int, input().split())
    if b < 5 and p < 2:
        ans = min((x*b+y*p), ((x*5+y*2)*0.8))
    elif b >= 5 and p < 2:
        ans = min((x*b+y*p), ((x*b+y*2)*0.8))
    elif b < 5 and p >= 2:
        ans = min((x*b+y*p), ((x*5+y*p)*0.8))
    else:
        ans = (x*b+y*p)*0.8

    print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input().split())
for i in range(n):
    a,b,c,d=map(int,input().split())
    q,w,e,r=0,0,0,0
    q,w=a*c,b*d
    e=q+w
    if c<=5 and d<=2:
        r=e*0.8
    print(r)