After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points.

At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs C roubles and decreases hunger by N points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.

Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.


-----Input-----

The first line contains two integers hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59) — the time of Andrew's awakening.

The second line contains four integers H, D, C and N (1 ≤ H ≤ 10^5, 1 ≤ D, C, N ≤ 10^2).


-----Output-----

Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10^{ - 4}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-4}$.


-----Examples-----
Input
19 00
255 1 100 1

Output
25200.0000

Input
17 41
1000 6 15 11

Output
1365.0000



-----Note-----

In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.

In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Greedy algorithms


Solutions:
from math import ceil
(hh, mm) = map(int, input().split())
(hunger, hpm, cost, feed) = map(float, input().split())
price = ceil(hunger / feed) * cost * (1 if hh < 20 else 0.8)
if hh < 20:
	minutes = (20 - hh) * 60 - mm
	evening_hunger = hunger + minutes * hpm
	discount_price = ceil(evening_hunger / feed) * 0.8 * cost
	price = min(price, discount_price)
print(price)


(l, k) = list(map(int, input().split()))
(h, d, c, n) = list(map(int, input().split()))
if l < 20:
	na = (20 - l) * 60
	la = na - k
	man = la * d
	sa = man + h
	ta = sa // n
	if sa / n == ta:
		ga = c * ta
	else:
		ga = c * (ta + 1)
elif l >= 20:
	ta = h // n
	if h / n == ta:
		ga = c * ta
	else:
		ga = c * (ta + 1)
lop = h // n
if lop == h / n:
	kj = c * lop
else:
	kj = c * (lop + 1)
print(min(kj, 80 / 100 * ga))


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hh < 20:
	i = math.ceil((((20 - hh - 1) * 60 + (60 - mm)) * D + H) / N) * C * 0.8
	j = math.ceil(H / N) * C
	if i > j:
		print('%.4f' % j)
	else:
		print('%.4f' % i)
else:
	k = math.ceil(H / N) * C * 0.8
	print('%.4f' % k)


import math
arr = list(map(str, input().strip().split(' ')))
n = int(arr[0])
t = int(arr[1])
(h, d, c, nn) = map(int, input().strip().split(' '))
if n >= 20:
	price = 0.8 * c * math.ceil(h * 1.0 / nn * 1.0)
	print(price)
else:
	hunger = (20 * 60 - n * 60 - t) * d + h
	price = min(0.8 * c * math.ceil(hunger * 1.0 / nn * 1.0), math.ceil(h * 1.0 / nn * 1.0) * c)
	print(price)


(h, m) = map(int, input().split())
(a, d, cost, val) = map(int, input().split())
x = 20 * 60
tim = h * 60 + m
ans = (a + val - 1) // val * cost
for i in range(123456):
	rem = a - i * val + max(x - tim, 0) * d
	if rem > 0:
		ans = min(ans, i * cost + (rem + val - 1) // val * 0.8 * cost)
	else:
		ans = min(ans, i * cost)
print('%.10f' % ans)


I = lambda : map(int, input().split())
(hh, mm) = I()
(H, D, C, N) = I()
print(min((H + N - 1) // N * C, (H + D * max(0, 1200 - 60 * hh - mm) + N - 1) // N * 0.8 * C))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
k = math.ceil(h / n)
if hh >= 20:
	print(k * 0.8 * c)
else:
	ans = k * c
	di = 20 - hh
	di *= 60
	di -= mm
	h += d * di
	ans = min(ans, math.ceil(h / n) * 0.8 * c)
	print(ans)


import math

def main():
	(h, m) = map(int, input().split())
	(H, d, c, n) = map(int, input().split())
	x = math.ceil(H / n)
	cost = x * c
	diff = 0
	if h < 20:
		diff += 60 * (20 - h)
		diff -= m
	else:
		diff = 0
	H += diff * d
	x = math.ceil(H / n)
	cost = min(cost, x * 0.8 * c)
	print(cost)
main()


import math
(ho, mi) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
nr = math.ceil(h / n)
nc = nr * c
des = False
if ho >= 20 and ho <= 23:
	des = True
if not des:
	dif = 60 - mi
	dif += (19 - ho) * 60
	h += dif * d
	rate = math.ceil(h / n)
	tc = rate * c * 0.8
	if tc < nc:
		print(tc)
	else:
		print(nc)
else:
	print(nc * 0.8)


(h, m) = list(map(int, input().split()))
(hu, d, c, n) = list(map(int, input().split()))
if h >= 20:
	if hu % n != 0:
		hu = hu + n - hu % n
	print(hu * 4 * c / (5 * n))
else:
	lhu = hu
	p = float('inf')
	if hu % n != 0:
		hu = hu + n - hu % n
	p = min(p, hu * c / n)
	hu = lhu + ((19 - h) * 60 + (60 - m)) * d
	if hu % n != 0:
		hu = hu + n - hu % n
	p = min(p, hu * c * 4 / (5 * n))
	print(p)


def solve(hh, mm, H, D, C, N):
	l1 = C * int(H / N + (1 if H % N else 0))
	if hh < 20:
		H += D * (60 * (20 - hh) - mm)
	l2 = 4 * C / 5 * int(H / N + (1 if H % N else 0))
	return min(l1, l2)
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
print('%.4f' % solve(hh, mm, H, D, C, N))


from math import ceil
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
mins = 0
if hh < 20:
	mins = 60 * (19 - hh) + (60 - mm)
new_h = h + mins * d
print(min(ceil(h / n) * c, ceil(new_h / n) * c * 0.8))


from math import ceil
time = input()
catbun = input()
check = time.split(' ')
current = 0
current += int(check[0]) * 60
current += int(check[1])
discountTime = 1200
record = catbun.split(' ')
H = int(record[0])
D = int(record[1])
C = int(record[2])
N = int(record[3])
minimum = 0
minimum = ceil(H / N) * C
if discountTime - current > 0:
	H = H + (discountTime - current) * D
	C = C * 0.8
	if ceil(H / N) * C < minimum:
		minimum = ceil(H / N) * C
else:
	C = C * 0.8
	if ceil(H / N) * C < minimum:
		minimum = ceil(H / N) * C
print(round(minimum, 3))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
x = (H + N - 1) // N * C
y = 0
if hh < 20:
	y = ((20 * 60 - (hh * 60 + mm)) * D + N - 1 + H) // N * C * 0.8
else:
	y = (H + N - 1) // N * C * 0.8
print(min(x, y))


from math import ceil
(H, M) = input().split()
(h, d, c, n) = input().split()
(H, M, h, d, c, n) = (int(H), int(M), int(h), int(d), int(c), int(n))
if H < 20 or (H == 20 and M == 0):
	print(min(ceil(h / n) * c, ceil((h + d * (1200 - H * 60 - M)) / n) * 0.8 * c))
else:
	print(ceil(h / n) * 0.8 * c)


t = input()
(h, d, c, n) = [int(x) for x in input().split()]
s = int(t[:2]) * 60 + int(t[3:])
if s >= 1200:
	if h % n == 0:
		print(h // n * c * (4 / 5))
		exit()
	else:
		print((h // n + 1) * c * (4 / 5))
		exit()
if h % n == 0:
	v1 = h // n * c
else:
	v1 = (h // n + 1) * c
if (h + d * (1200 - s)) % n == 0:
	v2 = (h + d * (1200 - s)) // n * c * (4 / 5)
else:
	v2 = ((h + d * (1200 - s)) // n + 1) * c * (4 / 5)
print(min(v1, v2))


R = lambda : map(int, input().split())
(h, m) = R()
(H, D, C, N) = R()
H += N - 1
print(min(H // N * C, (H + max(0, 1200 - h * 60 - m) * D) // N * C * 0.8))


from math import *
(chour, cmin) = map(int, input().strip().split())
(h, d, c, n) = map(int, input().strip().split())
price1 = 100000000
price2 = 100000000
if chour < 20:
	t1 = chour + 1
	t2 = (20 - t1) * 60
	diff = t2 + (60 - cmin)
	bunneed = h + diff * d
	price1 = ceil(bunneed / n) * c - ceil(bunneed / n) * c * 0.2
	bunneed = ceil(h / n)
	price2 = bunneed * c
	if price1 < price2:
		price1 = '{0:.6f}'.format(price1)
		print(price1)
	else:
		price2 = '{0:.6f}'.format(price2)
		print(price2)
else:
	bunneed = ceil(h / n)
	price2 = bunneed * c - bunneed * c * 0.2
	price2 = '{0:.6f}'.format(price2)
	print(price2)


import math

def solve():
	(houro, mino) = list(map(int, input().split()))
	(hunger, inc, cost, dec) = list(map(int, input().split()))
	t_l = 0
	if houro < 20:
		t_l = 20 - houro - 1
		t_l *= 60
		t_l += 60 - mino
	(x, y) = (math.ceil((t_l * inc + hunger) / dec) * 0.8 * cost, math.ceil(hunger / dec) * cost)
	print('%.5f' % min(x, y))
solve()


from math import ceil
(hh, mm) = list(map(int, input().split()))
(H, D, C, N) = list(map(int, input().split()))

def compute_before_discount():
	num_of_buns = ceil(H / N)
	return num_of_buns * C
before_discount = compute_before_discount()

def coumpte_time_before_discount():
	if hh < 20:
		return (20 - (hh + 1)) * 60 + 60 - mm
	else:
		return 0

def compute_on_discount():
	time_before_discount = coumpte_time_before_discount()
	new_numger_level = H + D * time_before_discount
	num_of_buns = ceil(new_numger_level / N)
	return num_of_buns * (C * 8 / 10)
on_discount = compute_on_discount()
print(round(min(before_discount, on_discount), 4))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())

def buns(h, n):
	ans = h // n
	if h % n != 0:
		ans += 1
	return ans
if hh >= 20:
	print(0.8 * C * buns(H, N))
	exit()
t = 20 * 60 - hh * 60 - mm
b1 = buns(H, N)
b2 = buns(H + t * D, N)
c1 = float(C)
c2 = 0.8 * C
print(min(b1 * c1, b2 * c2))


import sys

def main():
	file = sys.stdin
	line1 = file.readline()
	line2 = file.readline()
	(hour, minute) = line1.split()
	(H, D, C, N) = line2.split()
	(hour, minute) = (int(hour), int(minute))
	(H, D, C, N) = (int(H), int(D), float(C), int(N))
	if hour >= 20:
		bunsRequired = roundUp(H / N)
		cost = bunsRequired * (0.8 * C)
		print('{:.4f}'.format(cost))
	else:
		timeLeft = (20 - hour) * 60 - minute
		incrementInHunger = timeLeft * D
		totalHungerIfWaited = H + incrementInHunger
		totalCostIfWaited = roundUp(totalHungerIfWaited / N) * (0.8 * C)
		totalCostIfNotWaited = roundUp(H / N) * C
		minimumCost = min(totalCostIfWaited, totalCostIfNotWaited)
		print('{:.4f}'.format(minimumCost))

def roundUp(n):
	if n % 1 != 0:
		return int(n) + 1
	else:
		return int(n)
main()


import math
(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
mn = (20 - h) * 60 - m
if mn < 0:
	mn = 0
a1 = C * math.ceil(H / N)
a2 = C * 0.8 * math.ceil((H + mn * D) / N)
print(min(a1, a2))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
temp = math.ceil(h / n)
result = temp * c
if hh < 20:
	hh += 1
	mn = 60 - mm
	mn += 60 * (20 - hh)
	h += mn * d
	temp = math.ceil(h / n)
	temp *= c
	temp = temp - temp * 0.2
	result = min(result, temp)
else:
	result = result - result * 0.2
print('%0.4f' % result)


(hh, mm) = list(map(int, input().split()))
t = hh * 60 + mm
(h, d, c, n) = list(map(int, input().split()))
import math
if t >= 20 * 60:
	print(0.8 * c * math.ceil(h / n))
else:
	res = c * math.ceil(h / n)
	h += (1200 - t) * d
	res = min(res, 0.8 * c * math.ceil(h / n))
	print(res)


import sys, math
(hour, minutes) = map(int, input().strip().split(' '))
(hunger, increment, cost, calorie) = map(int, input().strip().split(' '))
fl = 0
if hour >= 20:
	print(math.ceil(hunger / float(calorie)) * cost * 0.8)
else:
	minutes = 60 - minutes + 60 * (20 - hour - 1)
	a1 = math.ceil((hunger + minutes * increment) / float(calorie)) * cost * 0.8
	a2 = math.ceil(hunger / float(calorie)) * cost
	print(min(a1, a2))


import math
(h, m) = [int(h) for h in input().split()]
(d, e, f, g) = [int(d) for d in input().split()]
if h >= 20:
	r = math.ceil(d / g)
	j = f - f / 5
	cost = r * j
	print('{0:.4f}'.format(cost))
else:
	h = h * 60 + m
	t = 1200 - h
	r = math.ceil(d / g)
	cost = r * f
	d = d + t * e
	r = math.ceil(d / g)
	j = f - f / 5
	cost = min(cost, r * j)
	print('{0:.4f}'.format(cost))


from math import ceil
(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if h >= 20:
	print(0.8 * C * ceil(H / N))
else:
	minutes = 20 * 60 - h * 60 - m
	no_wait = C * ceil(H / N)
	with_wait = 0.8 * C * ceil((H + D * minutes) / N)
	print(min(with_wait, no_wait))


import math
(hh, mm) = [int(x) for x in input().split()]
(h, d, c, n) = [int(x) for x in input().split()]
if hh >= 20:
	print(0.8 * c * math.ceil(h / n))
else:
	print(min(0.8 * c * math.ceil((((20 - hh) * 60 - mm) * d + h) / n), c * math.ceil(h / n)))


import math
(hh, mm) = [int(i) for i in input().split()]
(h, d, c, n) = [int(i) for i in input().split()]
if hh < 20:
	print('{:.4f}'.format(min(math.ceil(h / n) * c, math.ceil((h + (abs(hh - 20) * 60 - mm) * d) / n) * (c * 0.8))))
else:
	print('{:.4f}'.format(math.ceil(h / n) * (c * 0.8)))


from math import ceil
(hh, mm) = list(map(int, input().split()))
(H, D, C, N) = list(map(int, input().split()))
t = 0
if hh < 20:
	t = (19 - hh) * 60 + (60 - mm)
elif hh == 20 and mm == 0:
	t = 0
elif mm == 0:
	t = 60 * (43 - hh) + (60 - mm)
ans1 = float(ceil(H / N) * C)
ans2 = float(ceil((H + D * t) / N) * 0.8 * C)
print(min(ans1, ans2))


import math
(h, m) = map(int, input().split(' '))
(H, D, C, N) = map(int, input().split(' '))
if h >= 20:
	t1 = math.ceil(H / N)
	total = t1 * C
	print(total * 0.8)
else:
	t2 = math.ceil(H / N)
	total = t2 * C
	t3 = (19 - h) * 60 + (60 - m)
	t3 = t3 * D
	H = H + t3
	tk = math.ceil(H / N)
	total1 = tk * C
	t = total1 * 0.8
	if t < total:
		print(t)
	else:
		print(total)


import math

def cost(h, c, n):
	return c * ((h + n - 1) // n)
(hh, mm) = [int(x) for x in input().split()]
(h, d, c, n) = [int(x) for x in input().split()]
money = []
if hh < 20:
	money.append(cost(h, c, n))
	h += (20 - hh - 1) * 60 * d + (60 - mm) * d
c *= 0.8
money.append(cost(h, c, n))
print(min(money))


def solve():
	(hh, mm) = map(int, input().split())
	(H, D, C, N) = map(int, input().split())
	hh = hh * 60 + mm
	if hh >= 20 * 60 + 0:
		c = (H + N - 1) // N * C * 0.8
		print('{:.4f}'.format(c))
	else:
		a = (H + N - 1) // N * C
		b = (H + (1200 - hh) * D + N - 1) // N * C * 0.8
		print('{:.4f}'.format(min(a, b)))
solve()


disc_time = 1200
time = input().split()
given_time = int(time[0]) * 60 + int(time[1])
time_diff = abs(disc_time - given_time)
val = list(map(int, input().split()))
inc_hunger = time_diff * val[1]
initial_hunger = val[0]
cost = val[2]
discount_cost = 0.8 * cost
dec_hunger = val[3]
req = -1
if initial_hunger % dec_hunger == 0:
	req = initial_hunger / dec_hunger
else:
	req = initial_hunger // dec_hunger + 1
cost1 = req * cost
req = -1
initial_hunger += inc_hunger
if initial_hunger % dec_hunger == 0:
	req = initial_hunger / dec_hunger
else:
	req = initial_hunger // dec_hunger + 1
cost2 = req * discount_cost
if given_time >= disc_time:
	print(cost1 // cost * discount_cost)
else:
	print(min(cost1, cost2))


from math import *
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
mm += hh * 60
if mm < 1200:
	val1 = ceil((h + (1200 - mm) * d) / n) * c * 0.8
	val2 = ceil(h / n) * c
	print('{:.4f}'.format(min(val1, val2)))
else:
	cost1 = ceil(h / n) * c * 0.8
	print('{:.4f}'.format(cost1))


from datetime import timedelta as TD
import math

def discount(h, c):
	if 20 <= h:
		return c * 0.8
	return c
(h, m) = map(int, input().split(' '))
(H, D, C, N) = map(int, input().split(' '))
now = discount(h, C) * math.ceil(H / N)
later = now
if h < 20:
	sec_until_8 = TD(hours=20) - TD(hours=h, minutes=m)
	hunger = H + D * math.ceil(sec_until_8.seconds / 60)
	later = discount(20, C) * math.ceil(hunger / N)
print('{:.4f}'.format(min(now, later)))


from math import ceil
[hh, mm] = list(map(int, input().split()))
[H, D, C, N] = list(map(int, input().split()))
S = 0
if 20 <= hh <= 23:
	S = 0.8 * C * ceil(H / N)
elif 0 <= hh <= 19:
	S = min(C * ceil(H / N), 0.8 * C * ceil((H + D * (1200 - (hh * 60 + mm))) / N))
print(round(S, 3))


from math import ceil
(h, m) = list(map(int, input().split()))
(X, Answer) = (list(map(int, input().split())), 0)
Diff = max(20 * 60 - (h * 60 + m), 0)
After = ceil((X[0] + Diff * X[1]) / X[-1]) * (X[-2] - X[-2] * 0.2)
print(min(After, ceil(X[0] / X[-1]) * X[-2]) if Diff > 0 else After)


import getpass
import sys
import math
from decimal import Decimal
import decimal
files = True
debug = False
if getpass.getuser() == 'frohenk' and files:
	debug = True
	sys.stdin = open('test.in')
elif files:
	pass

def lcm(a, b):
	return a * b // math.gcd(a, b)

def ria():
	return [int(i) for i in input().split()]

def range_sum(a, b):
	ass = (b - a + 1) // 2 * (a + b)
	if (a - b) % 2 == 0:
		ass += (b - a + 2) // 2
	return ass

def comba(n, x):
	return math.factorial(n) // math.factorial(n - x) // math.factorial(x)
(h, m) = ria()
time = h * 60 + m
offerTime = max(20 * 60 - time, 0)
(h, d, c, n) = ria()
mini = math.ceil(h / n) * c
h += offerTime * d
mini = min(math.ceil(h / n) * c * 0.8, mini)
print(mini)


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
minut = 20 * 60 - (hh * 60 + mm)
p = (D * minut + H) / N
if (D * minut + H) % N == 0:
	p = (D * minut + H) // N
else:
	p = (D * minut + H) // N + 1
q = H / N
if H % N == 0:
	q = H // N
else:
	q = H // N + 1
if hh < 20:
	if p * (C * 4 / 5) < q * C:
		print(p * (C * 4 / 5))
	else:
		print(q * C)
else:
	print(q * (C * 4 / 5))


from datetime import datetime

def main():
	(HH, MM) = input().split()
	(H, D, C, N) = map(int, input().split())
	a = -(-H // N) * C
	b = float('inf')
	if int(HH) < 20:
		d1 = datetime.strptime('20:00', '%H:%M')
		t = HH + ':' + MM
		d2 = datetime.strptime(t, '%H:%M')
		s = (d1 - d2).total_seconds() / 60
		b = -(-(D * s + H) // N) * C * 0.8
	else:
		a *= 0.8
	print(min(a, b))
main()


def main():
	(h, m) = map(int, input().split())
	(H, D, C, N) = map(int, input().split())
	x = (H + N - 1) // N
	y = (H + D * max((20 - h) * 60 - m, 0) + N - 1) // N
	print('%.4f' % (min(x, y * 0.8) * C))
main()


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())

def calSum(h, n, c):
	to_buy = h // n
	if h % n != 0:
		to_buy += 1
	return to_buy * c
ans_0 = calSum(h, n, c)
time_left = 0
if hh < 20:
	time_left = (20 - hh) * 60 - mm
else:
	time_left = 0
h = h + time_left * d
ans_8 = calSum(h, n, c) * 0.8
print(min(ans_0, ans_8))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hh >= 20:
	print((H + N - 1) // N * 0.8 * C)
else:
	v1 = (H + N - 1) // N * C
	d = (20 - hh - 1) * 60 + 60 - mm
	v2 = (H + d * D + N - 1) // N * 0.8 * C
	print(min(v1, v2))


import math
(hh, mm) = [str(i) for i in input().split()]
(H, D, C, N) = [float(i) for i in input().split()]
disc = 1200

def toTime(s):
	h = int(s[:2])
	m = int(s[3:])
	return h * 60 + m

def toDate(k):
	h = math.floor(k / 60.0)
	k -= h * 60
	mm = k
	return '%02d:%02d' % (h, mm)

def timePenalty(now, buyTime):
	global D
	return abs(now - buyTime)
wake = toTime('%s:%s' % (hh, mm))
penalty = timePenalty(wake, disc)
lateH = math.ceil((H + penalty * D) / float(N))
if wake >= disc:
	H = math.ceil(H / float(N))
	cost = H * C * 0.8
	print('%.4f' % cost)
else:
	later = lateH * C * 0.8
	H = math.ceil(H / float(N))
	immediate = C * H
	print('%.4f' % min(later, immediate))


(h, m) = map(int, input().split())
(x, d, c, n) = map(int, input().split())
if h >= 20:
	print((x + n - 1) // n * (c * 0.8))
else:
	ans = min((x + ((20 - h) * 60 - m) * d + n - 1) // n * (c * 0.8), (x + n - 1) // n * c)
	print('%.7f' % ans)


(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())

def cost(H, C, N):
	nb = H // N + (1 if H % N != 0 else 0)
	return C * nb

def to20(h, m):
	if h >= 20:
		return 0
	return (20 - h) * 60 - m
op1 = cost(H + D * to20(h, m), 0.8 * C, N)
op2 = cost(H, C, N)
print(min(op1, op2))


from math import ceil
(hh, mm) = map(int, input().split())
(starve, starve_per_min, cost, n) = map(int, input().split())
x = ceil(starve / n)
fin_cost1 = round(x * cost, 4)
fin_cost2 = 0
if hh >= 20 and hh <= 24:
	print(round(x * (cost * 0.8), 4))
else:
	minute = (20 - hh) * 60 - mm
	starve += minute * starve_per_min
	x = ceil(starve / n)
	fin_cost2 = round(x * (cost * 0.8), 4)
	if fin_cost1 < fin_cost2:
		print(fin_cost1)
	else:
		print(fin_cost2)


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
ans = 10000000000.0
for m in range(hh * 60 + mm, 1440):
	if 1200 <= m:
		k = 0.8
	else:
		k = 1.0
	tmp = (h + (m - hh * 60 - mm) * d + n - 1) // n * c * k
	ans = min(ans, tmp)
print(ans)


from math import ceil
(hh, mm) = input().split()
(H, D, C, N) = input().split()
t20 = 20 * 60
time = int(hh) * 60 + int(mm)
if t20 <= time:
	res = ceil(int(H) / int(N)) * float(C) * 0.8
else:
	res1 = ceil(int(H) / int(N)) * float(C)
	res2 = ceil(((t20 - time) * int(D) + int(H)) / int(N)) * float(C) * 0.8
	res = min(res1, res2)
res = round(res, 3)
print(res)


(hours, minutes) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if 20 <= hours <= 23:
	need_to_buy = h // n
	if need_to_buy * n >= h:
		cost = 0.8 * need_to_buy * c
		print(cost)
	else:
		cost = 0.8 * need_to_buy * c + 0.8 * c
		print(cost)
else:
	buy_as_soon_as_possible = h // n
	buy_as_soon_as_possible_cost = 0
	if buy_as_soon_as_possible * n >= h:
		buy_as_soon_as_possible_cost = buy_as_soon_as_possible * c
	else:
		buy_as_soon_as_possible_cost = buy_as_soon_as_possible * c + c
	diff = 20 * 60 - (60 * hours + minutes)
	new_hungry = h + diff * d
	buy_awaiting = new_hungry // n
	buy_awaiting_cost = 0
	if buy_awaiting * n >= new_hungry:
		buy_awaiting_cost = buy_awaiting * c * 0.8
	else:
		buy_awaiting_cost = buy_awaiting * c * 0.8 + c * 0.8
	print(min(buy_as_soon_as_possible_cost, buy_awaiting_cost))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	immediateBuy = (c - c * 0.2) * math.ceil(h / n)
	print(immediateBuy)
else:
	immediateBuy = c * math.ceil(h / n)
	minutes = (20 - hh) * 60 - mm
	H = h + minutes * d
	afterdiscount = (c - c * 0.2) * math.ceil(H / n)
	if immediateBuy > afterdiscount:
		print(afterdiscount)
	else:
		print(immediateBuy)


from math import gcd, floor, ceil
from random import randrange

def li():
	return list(map(int, input().split()))
(h, m) = li()
(cur, d, c, n) = li()
if 60 * h + m < 20 * 60:
	an = (cur + n - 1) // n * c
	cur += (20 * 60 - 60 * h - m) * d
	c *= 0.8
	an = min(an, c * ((cur + n - 1) // n))
else:
	c *= 0.8
	an = c * ((cur + n - 1) // n)
print(an)


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
minp = 0.0
dm = 0
if hh >= 20:
	dm = 0
else:
	dm = (20 - hh) * 60 - mm
p = math.ceil(H / N) * C
ps = math.ceil((H + dm * D) / N) * C * 0.8
if p > ps:
	minp = ps
else:
	minp = p
print(f'{minp:.4f}')


import sys, copy

def convert(h, m):
	return 60 * h + m
(hh, mm) = map(int, sys.stdin.readline().split())
(h, d, c, n) = map(int, sys.stdin.readline().split())
now = convert(hh, mm)
diff = convert(24, 0) - now
ans = 9876543210
for i in range(diff):
	temp_cat = i * d + h
	temp_time = now + i
	if temp_time >= convert(20, 0):
		cost = temp_cat // n * (c * 0.8) if temp_cat % n == 0 else (temp_cat // n + 1) * (c * 0.8)
	else:
		cost = temp_cat // n * c if temp_cat % n == 0 else (temp_cat // n + 1) * c
	ans = min(ans, cost)
print('%f' % ans)


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh < 20:
	s1 = ((h - 1) // n + 1) * c
	s2 = ((h + (1200 - (hh * 60 + mm)) * d - 1) // n + 1) * c * 0.8
	ans = min(s1, s2)
else:
	ans = ((h - 1) // n + 1) * c * 0.8
print(ans)


import collections
import os
import sys
from io import BytesIO, IOBase
import math
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	(hh, mm) = inps()
	(h, d, c, n) = list(map(int, input().split()))
	tm = 0
	cost = 0
	if hh < 20:
		tm += 60 - mm
		tm += (20 - hh - 1) * 60
		tm *= d
		cost = min(c * math.ceil(h / n), 0.8 * c * math.ceil((tm + h) / n))
	else:
		cost = 0.8 * c * math.ceil(h / n)
	print(round(cost, 4))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import *
(h, m) = input().split()
h = int(h)
m = int(m)
(q, w, e, r) = input().split()
q = int(q)
w = int(w)
e = int(e)
r = int(r)
H = 1.2 * q / 1.2
D = 1.2 * w / 1.2
C = 1.2 * e / 1.2
N = 1.2 * r / 1.2

def skidka(a):
	return C * 0.8

def hun(a, b, c):
	return a + b * c
if h >= 20:
	ans = ceil(H / N) * skidka(C)
else:
	t = 60 - m
	t += (19 - h) * 60
	ans = min(ceil((t * D + H) / N) * skidka(C), ceil(H / N) * C)
print(ans)


import math
(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
mins = h * 60 + m
discount = 20 * 60
feed_now = math.ceil(H / N) * C
feed_discount = math.ceil((H + D * max(0, discount - mins)) / N) * C * 0.8
print(min(feed_now, feed_discount))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh > 20 or (hh == 20 and mm >= 0):
	print((h // n + (h % n != 0)) * c * 0.8)
else:
	if mm != 0:
		m = 60 - mm
		hh += 1
	else:
		m = 0
	ex = h + ((20 - hh) * 60 + m) * d
	print(min((ex // n + (ex % n != 0)) * c * 0.8, (h // n + (h % n != 0)) * c))


import math
(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if h >= 20:
	print(C * 0.8 * math.ceil(H / N))
else:
	k = (20 - h - 1) * 60 + 60 - m
	print(min(C * math.ceil(H / N), C * 0.8 * math.ceil((H + D * k) / N)))


import math
(hh, mm) = map(int, input().split(' '))
(H, D, C, N) = map(int, input().split(' '))
if hh < 20:
	x = math.ceil(H / N)
	a = H + D * (1200 - 60 * hh - mm)
	y = math.ceil(a / N)
	print(min(x * C, y * C * 0.8))
else:
	x = math.ceil(H / N)
	print(x * C * 0.8)


(hh, mm) = map(int, input().split())
t = 60 * hh + mm
(h, d, c, n) = map(int, input().split())
ans1 = ((h - 1) // n + 1) * c
ans2 = ((h + d * max(1200 - t, 0) - 1) // n + 1) * 0.8 * c
print(min(ans1, ans2))


from math import ceil
import datetime
(h, m) = [int(x) for x in input().split(' ')]
(hunger, hincrease, costOfBun, hdecrease) = [float(x) for x in input().split(' ')]
if h >= 20:
	print(ceil(hunger / hdecrease) * (costOfBun * 0.8))
else:
	v = datetime.timedelta(hours=20) - datetime.timedelta(hours=h, minutes=m)
	minsToEight = ceil(v.seconds / 60)
	hungerAtEight = hunger + hincrease * minsToEight
	BuyNoWait = ceil(hunger / hdecrease) * costOfBun
	BuyWait = ceil(hungerAtEight / hdecrease) * (costOfBun * 0.8)
	print(min(BuyNoWait, BuyWait))


(x, y) = input().split()
(h, d, c, n) = input().split()
(x, y, h, d, c, n) = (int(x), int(y), int(h), int(d), int(c), int(n))
if x <= 19 and y <= 59:
	z = 20 * 60 - 60 * x - y
	if h % n == 0:
		a = h / n
	else:
		a = int(h / n) + 1
	if (h + d * z) % n == 0:
		b = (h + d * z) / n
	else:
		b = int((h + d * z) / n) + 1
	q = a * c
	w = b * c * 0.8
	if q < w:
		print(q)
	else:
		print(w)
else:
	if h % n == 0:
		a = h / n
	else:
		a = int(h / n) + 1
	print(a * c * 0.8)


import math
(hh, mm) = [int(x) for x in input().split(' ')]
(H, D, C, N) = [int(x) for x in input().split(' ')]
if hh >= 20 and hh <= 23:
	x = math.ceil(H / N)
	print(x * (C * 0.8))
else:
	x1 = math.ceil(H / N)
	k1 = x1 * C
	h1 = 19 - hh
	h2 = 60 - mm
	H2 = H + h1 * 60 * D + h2 * D
	x2 = math.ceil(H2 / N)
	k2 = x2 * (C * 0.8)
	print(min(k1, k2))


def small(a, b):
	return a if a < b else b
import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	print(4 * c / 5 * math.ceil(h / n))
else:
	min = 60 * 20 - (60 * hh + mm)
	l = int(h / n) if h % n == 0 else int(h / n) + 1
	r = int((h + min * d) / n) if (h + min * d) % n == 0 else int((h + min * d) / n) + 1
	print(small(c * l, 4 * c / 5 * r))


(h, m) = list(map(int, input().split()))
(H, D, C, N) = list(map(int, input().split()))
psd = h * 60 + m
if psd >= 20 * 60:
	if H % N == 0:
		needed = H // N
	else:
		needed = H // N + 1
	print(needed * C * 0.8)
else:
	if H % N == 0:
		a = H // N * C
	else:
		a = (H // N + 1) * C
	x = (20 * 60 - psd) * D + H
	if x % N == 0:
		b = x // N * C * 0.8
	else:
		b = (x // N + 1) * C * 0.8
	print(min(a, b))


import sys
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(float, input().split())
mm += hh * 60
sale = 20 * 60
if mm >= sale:
	C *= 0.8
	tmp = H / N
	if tmp != int(tmp):
		tmp = int(tmp) + 1
	atTheMoment = tmp * C
	print(atTheMoment)
	sys.exit()
tmp = H / N
if tmp != int(tmp):
	tmp = int(tmp) + 1
atTheMoment = tmp * C
H += (sale - mm) * D
tmp = H / N
if tmp != int(tmp):
	tmp = int(tmp) + 1
afterSale = tmp * (C * 0.8)
print(atTheMoment) if atTheMoment < afterSale else print(afterSale)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	(h, m) = mi()
	(H, D, C, N) = mi()
	mn = 0
	hr = 0
	ansa = math.ceil(H / N) * C
	if h < 20:
		if m != 0:
			mn = 60 - m
			h += 1
		hr = 20 - h
	H += (hr * 60 + mn) * D
	ansb = math.ceil(H / N) * C - math.ceil(H / N) * C * 0.2
	print(min(ansa, ansb))
main()


import math
import sys
(hh, mm) = [int(x) for x in input().split()]
(h, d, c, n) = [int(x) for x in input().split()]
dift = 20 * 60 - (hh * 60 + mm)
z = math.ceil((dift * d + h) / n) * c * 0.8
s = math.ceil(h / n) * c
if hh >= 20:
	print(math.ceil(h / n) * c * 0.8)
	sys.exit()
print(min(s, z))


(h, m) = list(map(int, input().split()))
(cur, d, c, n) = list(map(int, input().split()))
ans = cur // n * c
if cur % n != 0:
	ans += c
time = h * 60 + m
if time < 20 * 60:
	cur += d * (20 * 60 - time)
ans1 = cur // n * 0.8 * c
if cur % n != 0:
	ans1 += 0.8 * c
ans = min(ans, ans1)
print('%.4f' % ans)


import math
import logging
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)

def solve(hh, mm, h, d, c, n):
	if hh >= 20:
		return 0.8 * c * math.ceil(h / n)
	logger.debug('Can buy at %s:%s for %s', hh, mm, c * math.ceil(h / n))
	logger.debug('Can buy at 20:00 for %s', 0.8 * c * math.ceil((h + d * ((20 - hh) * 60 - mm)) / n))
	return min(c * math.ceil(h / n), 0.8 * c * math.ceil((h + d * ((20 - hh) * 60 - mm)) / n))

def main():
	(hh, mm) = input().strip().split()
	hh = int(hh)
	mm = int(mm) if mm != '00' else 0
	(h, d, c, n) = map(int, input().strip().split())
	result = solve(hh, mm, h, d, c, n)
	print(result)
main()


import math
(h, m) = map(int, input().split())
(H, d, c, n) = map(int, input().split())

def solve(Hun, de, ca, n):
	return math.ceil(Hun / n) * ca
result1 = solve(H, d, c, n)
if 20 <= h < 24 and m >= 0:
	print(round(result1 * (8 / 10), 4))
else:
	temp1 = 20 * 60
	temp2 = h * 60 + m
	temp3 = temp1 - temp2
	h = int(temp3 / 60)
	m = temp3 % 60
	H += temp3 * d
	result2 = solve(H, d, c, n)
	print(min(round(result1, 4), round(result2 * 0.8, 4)))


import math
(hh, m) = [int(x) for x in input().split()]
(n, d, c, h) = [int(x) for x in input().split()]
if hh >= 20:
	t = c * 0.8
	one = math.ceil(n / h) * t
	print(one)
else:
	one = math.ceil(n / h) * c
	k = (20 - hh - 1) * 60 + (60 - m)
	n += k * d
	t = c * 0.8
	two = math.ceil(n / h) * t
	print(min(one, two))


import sys
import math
import itertools
import collections

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
(hh, mm) = mi()
(H, D, C, N) = mi()
if hh < 20:
	print(min(math.ceil((H + ((20 - hh) * 60 - mm) * D) / N) * (0.8 * C), math.ceil(H / N) * C))
else:
	print(math.ceil(H / N) * (0.8 * C))


n = str(input()).split()
hh = n[0]
mm = n[1]
if mm[0] == 0:
	mm = int(mm[1])
else:
	mm = int(mm)
if hh[0] == 0:
	hh = int(hh[1])
else:
	hh = int(hh)
n = str(input()).split()
H = int(n[0])
D = int(n[1])
C = int(n[2])
N = int(n[3])
checkCost = 0
checkCostEff = True
if hh >= 20 and hh <= 23:
	C = C - float(C) * 0.2
	checkCostEff = False
import math
if checkCostEff:
	discountH = 0
	discountM = 0
	minCost = 0
	if mm > 0:
		discountH = 19 - hh
		discountM = 60 - mm
	else:
		discountH = 20 - hh
	minCost = int(discountH * 60) + discountM
	TempH = H + minCost * D
	numberCNeeded = math.ceil(TempH / N)
	tempC = C - float(C) * 0.2
	checkCost = float(tempC * numberCNeeded)
numberCNeeded = math.ceil(H / N)
totalCost = float(C * numberCNeeded)
totalCost = round(totalCost, 4)
checkCost = round(checkCost, 4)
if totalCost <= checkCost or checkCost == 0:
	print(totalCost)
else:
	print(checkCost)


import math
w = []
s = input()
for i in s.split():
	w.append(int(i))
hh = w[0]
mm = w[1]
d = []
tmp = input()
for i in tmp.split():
	d.append(int(i))
(H, D, C, N) = (d[0], d[1], d[2], d[3])
if hh >= 20:
	r = math.ceil(H / N) * C * 0.8
	print(r)
else:
	sum = 60 - mm + (20 - hh - 1) * 60
	r = math.ceil((sum * D + H) / N) * C * 0.8
	q = math.ceil(H / N) * C
	if r < q:
		print(r)
	else:
		print(q)


(a, b) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
mit = a * 60 + b
mit2 = 20 * 60
dmit = mit2 - mit
if dmit < 0:
	dmit = 0
disc = 0.8 * c
h += n - 1
ans = min((h + dmit * d) // n * disc, h // n * c)
print('{0:.5f}'.format(ans))


s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
(hh, mm) = (s1[0], s1[1])
(h, d, c, n) = (s2[0], s2[1], s2[2], s2[3])
res = 0
if hh >= 20:
	if h % n == 0:
		res = h / n * c * 0.8
	else:
		res = (h // n + 1) * c * 0.8
	print(res)
else:
	x = 60 - mm
	y = 20 - hh - 1
	res1 = h + (y * 60 + x) * d
	if res1 % n == 0:
		res1 = res1 / n * c * 0.8
	else:
		res1 = (res1 // n + 1) * c * 0.8
	res2 = 0
	if h % n == 0:
		res2 = h / n * c
	else:
		res2 = (h // n + 1) * c
	print(min(res1, res2))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
x = 60 - mm
y = 60 * (19 - hh)
p = math.ceil(h / n)
if hh >= 20:
	print('{0:0.4f}'.format(p * c * 0.8))
else:
	b = h + d * (x + y)
	bc = math.ceil(b / n)
	print('{0:0.4f}'.format(min(p * c, 0.8 * bc * c)))


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
now = 0.0
later = 0.0
time = 0
now = math.ceil(H / N) * C
if hh < 20:
	time = (20 - hh) * 60 - mm
later = math.ceil((H + D * time) / N) * C
later *= 0.8
print(min(round(now, 4), round(later, 4)))


stroka1 = input()
stroka2 = input()
count = 0
hours = int(stroka1[0] + stroka1[1])
minuts = int(stroka1[3] + stroka1[4])
H = stroka2[0]
D = ''
C = ''
N = ''
for i in range(1, len(stroka2)):
	if stroka2[i] == ' ':
		count += 1
	elif count == 0:
		H += stroka2[i]
	elif count == 1:
		D += stroka2[i]
	elif count == 2:
		C += stroka2[i]
	else:
		N += stroka2[i]
H = int(H)
D = int(D)
C = float(C)
N = int(N)
answer = 0
if hours >= 20:
	while H > 0:
		answer += C * 0.8
		H -= N
else:
	minuts = (20 - hours) * 60 - minuts
	answer1 = 0
	answer2 = 0
	H1 = H
	while H1 > 0:
		answer1 += C
		H1 -= N
	H += D * minuts
	while H > 0:
		answer2 += C * 0.8
		H -= N
	if answer1 > answer2:
		answer = answer2
	else:
		answer = answer1
print(answer)


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	num = math.ceil(h / n)
	print(num * c * 0.8)
else:
	num1 = math.ceil(h / n)
	cost1 = num1 * c
	h1 = ((19 - hh) * 60 + (60 - mm)) * d
	num2 = math.ceil((h + h1) / n)
	cost2 = num2 * c * 0.8
	print(min([cost1, cost2]))


from math import *
(hh, mm) = map(int, input().split())
mm += hh * 60
(hunger, inc, cost, dec) = map(int, input().split())
if mm >= 1200:
	print(ceil(hunger / dec) * cost * 0.8)
else:
	(a, b) = (ceil((hunger + (1200 - mm) * inc) / dec) * cost * 0.8, ceil(hunger / dec) * cost)
	print(min(a, b))


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(float, input().split())
if hh >= 20:
	res = math.ceil(H / N) * 0.8 * C
else:
	time = (20 - hh - 1) * 60 + 60 - mm
	res = min(math.ceil(H / N) * C, math.ceil((H + time * D) / N) * 0.8 * C)
print('%.6f' % res)


R = lambda : map(int, input().split())
(h, m) = R()
(H, D, C, N) = R()
p = (H + N - 1) // N * C
if h < 20:
	p = min(p, (H + (1200 - h * 60 - m) * D + N - 1) // N * C * 0.8)
else:
	p *= 0.8
print(p)


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hh < 20:
	x = H // N
	if H % N == 0:
		prix = x * C
	else:
		prix = (x + 1) * C
	H += (20 * 60 - hh * 60 - mm) * D
	x = H // N
	if H % N == 0:
		prix_ = x * C * 0.8
	else:
		prix_ = (x + 1) * C * 0.8
	if prix_ < prix:
		prix = prix_
else:
	x = H // N
	if H % N == 0:
		prix = x * C * 0.8
	else:
		prix = (x + 1) * C * 0.8
print(prix)


def div(a, b):
	return a // b + int(a % b != 0)
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
wait = 0
if hh < 20:
	wait = 60 * (20 - hh - 1) + 60 - mm
print(0.2 * min(div(h, n) * c * 5, div(wait * d + h, n) * c * 4))


(a, b) = map(int, input().split())
t = a * 60 + b
(a, b, c, d) = map(int, input().split())
mx = 1000000000000000000
for i in range(t, 1440):
	x = a + b * (i - t)
	if x % d > 0.5:
		x = x // d + 1
	else:
		x = x // d
	x = x * c
	if i >= 1200:
		x = x * 0.8
	if x < mx:
		mx = x
print(mx)


from math import ceil
(hours, minutes) = map(int, input().split(' '))
(H, D, C, N) = map(int, input().split(' '))
sale_start = 20 * 60
sale_end = 23 * 60 + 59
time = hours * 60 + minutes
if sale_start <= time <= sale_end:
	print(ceil(H / N) * C * 0.8)
else:
	go_price = ceil(H / N) * C
	wait_price = ceil((H + D * (sale_start - time)) / N) * C * 0.8
	print(min(go_price, wait_price))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
t = hh * 60 + mm - 20 * 60
tm = h / n
if h / n != h // n:
	tm += 1
	tm = int(tm)
tm1 = (abs(t) * d + h) / n
if tm1 != int(tm1):
	tm1 += 1
	tm1 = int(tm1)
if t >= 0:
	print(tm * c * 0.8)
else:
	print(min(tm * c, tm1 * c * 0.8))


(hh, mm) = list(map(int, input().split()))
(h, d, c, n) = list(map(int, input().split()))
if hh >= 20:
	c *= 0.8
	cost1 = cost2 = (h + n - 1) // n * c
else:
	cost1 = (h + n - 1) // n * c
	h += (20 * 60 - hh * 60 - mm) * d
	c *= 0.8
	cost2 = (h + n - 1) // n * c
print('{:.10f}'.format(min(cost1, cost2)))


(h, m) = map(int, input().split())
time = h * 60 + m
time = 1200 - time
(h, d, c, n) = map(float, input().split())
if time <= 0:
	k = h / n
	if k % 1 != 0:
		k = int(k) + 1
	print(c * 0.8 * k)
else:
	k = h / n
	if k % 1 != 0:
		k = int(k) + 1
	p1 = c * k
	h += d * time
	k = h / n
	if k % 1 != 0:
		k = int(k) + 1
	p2 = c * 0.8 * k
	print(min(p1, p2))


import sys, math
(hh, mm) = list(map(int, sys.stdin.readline().split()))
(h, d, c, n) = list(map(int, sys.stdin.readline().split()))
time_til_eight = (20 - hh) * 60 if mm == 0 else (20 - hh - 1) * 60 + (60 - mm)
if time_til_eight > 0:
	print(min(math.ceil(h / n) * c, math.ceil((h + time_til_eight * d) / n) * c * 0.8))
else:
	print(math.ceil(h / n) * c * 0.8)


import math
(h, m) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
start = math.ceil(H / N) * C
if h >= 20:
	stop = math.ceil(H / N) * C * 0.8
else:
	stop = math.ceil((H + (20 * 60 - (h * 60 + m)) * D) / N) * C * 0.8
print(min(start, stop))


(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
rem_m = 0
if H % N != 0:
	totCost1 = (int(H / N) + 1) * C
else:
	totCost1 = int(H / N) * C
if h < 20:
	if m > 0:
		rem_m = 60 - m + (20 - (h + 1)) * 60
	else:
		rem_m = (20 - h) * 60
H += D * rem_m
if H % N != 0:
	totCost2 = (int(H / N) + 1) * (C * 0.8)
else:
	totCost2 = int(H / N) * (C * 0.8)
if totCost1 < totCost2:
	print('%.4f' % totCost1)
else:
	print('%.4f' % totCost2)


import math

def minutes_until_20_oclock(hour, minute):
	total_minutes = 0
	if minute != 0:
		total_minutes += 60 - minute
		hour = (hour + 1) % 24
	hours_remaining_to_20 = 20 - hour if hour < 20 else 24 - (hour - 20)
	total_minutes += hours_remaining_to_20 * 60
	return total_minutes
(hour, minute) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
discount_if_spend_now = 0.8 if 20 <= hour < 24 else 1
spent_money_now = math.ceil(H / N) * C * discount_if_spend_now
spent_money_8_oclock = math.ceil((minutes_until_20_oclock(hour, minute) * D + H) / N) * C * 0.8
answer = min(spent_money_now, spent_money_8_oclock)
print('%.4f' % answer)


import math
(hr, mi) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hr >= 20:
	C_discount = C - C / 5
	total = math.ceil(H / N) * C_discount
	print('{0:.4f}'.format(total))
else:
	totalNow = math.ceil(H / N) * C
	minutesForSale = 0
	saleHour = 20
	if mi != 0:
		minutesForSale = 60 - mi
		saleHour -= 1
	minutesForSale += (saleHour - hr) * 60
	C_discount = C - C / 5
	H_new = H + D * minutesForSale
	totalNew = math.ceil(H_new / N) * C_discount
	print('{0:.4f}'.format(min(totalNow, totalNew)))


def convert_to_mins(h, m):
	return h * 60 + m

def count_food(hunger, decrise_val):
	count_of_bread = 0
	while hunger > 0:
		hunger = hunger - decrise_val
		count_of_bread += 1
	return count_of_bread

def count_sum(quantity, cost_per_one, id):
	result_summ = 0
	if id == 0:
		discount_val = cost_per_one / 100 * 20
		new_cost = cost_per_one - discount_val
		result_summ = new_cost * quantity
	elif id == 1:
		result_summ = quantity * cost_per_one
	return result_summ

def cost_if_wait(def_time, adder_of_hungry_val, decrise_val, cost_per_one, hunger_current):
	new_hunger = hunger_current + def_time * adder_of_hungry_val
	bread = count_food(new_hunger, decrise_val)
	return count_sum(bread, cost_per_one, 0)
hh_mm = list()
hh_mm = input()
splited_hh_mm = hh_mm.split()
hh = int(splited_hh_mm[0])
mm = int(splited_hh_mm[1])
min_sum = 0
h_d_c_n = list()
h_d_c_n = input()
splited_h_d_c_n = h_d_c_n.split()
hungry_of_cat = int(splited_h_d_c_n[0])
adder_of_hungry = int(splited_h_d_c_n[1])
cost = int(splited_h_d_c_n[2])
decrease_of_hungry = int(splited_h_d_c_n[3])
minutes_now = convert_to_mins(hh, mm)
minutes_begin_discount = convert_to_mins(20, 0)
minutes_end_discount = convert_to_mins(23, 59)
if minutes_now >= minutes_begin_discount and minutes_now <= minutes_end_discount:
	quantity_of_bread = count_food(hungry_of_cat, decrease_of_hungry)
	min_sum = count_sum(quantity_of_bread, cost, 0)
elif minutes_now < minutes_end_discount:
	delta_time = minutes_begin_discount - minutes_now
	cost_one = cost_if_wait(delta_time, adder_of_hungry, decrease_of_hungry, cost, hungry_of_cat)
	quantity_of_bread = count_food(hungry_of_cat, decrease_of_hungry)
	cost_two = count_sum(quantity_of_bread, cost, 1)
	min_sum = min(cost_one, cost_two)
print(min_sum)


import math
to_min = lambda h, m: h * 60 + m
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
t = to_min(hh, mm)
dt = to_min(20, 0)
if t < dt:
	dh = (dt - t) * d + h
	dp = math.ceil(dh / n)
	p = math.ceil(h / n)
	print(min(0.8 * dp * c, p * c))
else:
	print(0.8 * c * math.ceil(h / n))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
p = 60 - mm
t = abs(20 - (hh + 1))
z = 0
if hh >= 20:
	print(math.ceil(h / n) * c * 0.8)
	z = 1
else:
	t = t * 60 + p
if z == 0:
	pr = math.ceil(h / n) * c
	h = h + t * d
	pre = math.ceil(h / n) * c * 0.8
	print(min(pr, pre))


from math import ceil
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	amount = ceil(h / n) * c
	ans = amount - amount * 20 / 100
	print(ans)
else:
	amount1 = ceil(h / n) * c
	h = (60 - mm + (20 - hh - 1) * 60) * d + h
	amount2 = ceil(h / n) * c
	ans = amount2 - amount2 * 20 / 100
	if amount1 > ans:
		print(ans)
	else:
		print(amount1)


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
vecher = 20 * 60
if hh * 60 + mm >= vecher:
	cbul = H // N + 1 if H % N != 0 else H // N
	print(cbul * C * 0.8)
else:
	slep = vecher - (hh * 60 + mm)
	H2 = H + slep * D
	cbul2 = H2 // N + 1 if H2 % N != 0 else H2 // N
	p2 = cbul2 * C * 0.8
	cbul = H // N + 1 if H % N != 0 else H // N
	p = cbul * C
	print(min(p, p2))


(hh, mm) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
res = (H + N - 1) // N * (C if hh < 20 else C * 0.8)
if hh < 20:
	minutes = (20 - hh) * 60 - mm
	x = H + minutes * D
	res = min(res, (x + N - 1) // N * (C * 0.8))
print('{:.8f}'.format(float(res)))


import math
first = input().split(' ')
hh = int(first[0])
mm = int(first[1])
t = hh * 60 + mm
disc = 20 * 60
second = input().split(' ')
h = int(second[0])
d = int(second[1])
c = int(second[2])
n = int(second[3])
if t > disc:
	print(0.8 * math.ceil(h / float(n)) * c)
else:
	wait = 0.8 * math.ceil((h + d * (disc - t)) / float(n))
	imme = math.ceil(h / float(n))
	print(min(c * imme, c * wait))


(hh, mm) = input().split(' ')
(H, D, C, N) = map(int, input().split())
hh = int(hh)
mm = int(mm)

def calcMins():
	h = 20 - hh
	m = 60 - mm
	minsToEven = 0
	if m > 0:
		minsToEven = (h - 1) * 60 + m
	else:
		minsToEven = h * 60
	return minsToEven

def ordinaryCalc():
	buns = 0
	if H % N != 0:
		buns = H // N + 1
	else:
		buns = H // N
	return buns

def toEveningCalc(minsToEven):
	buns = 0
	if (minsToEven * D + H) % N != 0:
		buns = (minsToEven * D + H) // N + 1
	else:
		buns = (minsToEven * D + H) // N
	return buns
if hh >= 20 and (hh <= 23 and mm <= 59):
	buns = ordinaryCalc()
	calc = buns * C
	ans = calc - calc * 20 / 100
	print('%.3f' % ans)
else:
	minsToEven = calcMins()
	calc1 = toEveningCalc(minsToEven) * C
	ans1 = calc1 - calc1 * 20 / 100
	ans2 = ordinaryCalc() * C
	print('%.3f' % min(ans1, ans2))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())

def ceildiv(a, b):
	return -(-a // b)
left = max(20 * 60 - hh * 60 - mm, 0)
B = ceildiv(H + D * left, N) * C * 0.8
C = ceildiv(H, N) * C * 1.0
print(min(B, C))


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
h = (20 - hh - 1) * 60
m = 60 - mm
t = h + m if h >= 0 else 0
ca = math.ceil(H / N) * C
c8 = math.ceil((H + t * D) / N) * C * 0.8
if ca < c8:
	print('{:.4f}'.format(ca))
else:
	print('{:.4f}'.format(c8))


import math
(hh, mm) = [int(n) for n in input().split()]
(H, D, C, N) = [int(n) for n in input().split()]
M1 = hh * 60 + mm
M2 = 20 * 60
if M2 - M1 > 0:
	T1 = math.ceil(H / N) * C
	H += (M2 - M1) * D
	T2 = 0.8 * math.ceil(H / N) * C
	print(min(T1, T2))
else:
	T = 0.8 * math.ceil(H / N) * C
	print(T)


(hh, mm) = map(int, input().split())
(H, D, cost, nutr) = map(int, input().split())
hh = 60 * hh + mm
if hh >= 1200:
	print('{:.4f}'.format((H + nutr - 1) // nutr * cost * 0.8))
else:
	print('{:.4f}'.format(min((H + nutr - 1) // nutr * cost, (H + (1200 - hh) * D + nutr - 1) // nutr * cost * 0.8)))


def main():
	(hh, mm) = map(int, input().split())
	(h, d, c, n) = map(int, input().split())
	needTime = max(0, 1200 - (60 * hh + mm))
	needCnt = (h + n - 1) // n
	res = needCnt * c
	needCnt = (h + needTime * d + n - 1) // n
	res = min(res, needCnt * 0.8 * c)
	print(res)
main()


(h, m) = map(int, input().split())
(h1, d, c, n) = map(int, input().split())
if h >= 20:
	if h1 % n == 0:
		k = h1 // n
	else:
		k = h1 // n + 1
	print(k * c - 0.2 * (k * c))
else:
	if h1 % n == 0:
		k = h1 // n
	else:
		k = h1 // n + 1
	l = k * c
	p = 60 - m
	s = 19 - h
	tot = 60 * s + p
	h1 = h1 + d * tot
	if h1 % n == 0:
		k = h1 // n
	else:
		k = h1 // n + 1
	z = k * c - 0.2 * (k * c)
	print('{:.5f}'.format(min(z, l)))


from math import ceil
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
time_now = 60 * hh + mm
time_sale = 60 * 20
d_time = time_sale - time_now
c = 0.8 * C
if d_time <= 0:
	print('{:.4f}'.format(ceil(H / N) * c))
else:
	print('{:.4f}'.format(min(ceil(H / N) * C, ceil((H + D * d_time) / N) * c)))


from math import ceil
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(float, input().split())
if hh >= 20:
	num = ceil(H / N)
	print(0.8 * num * C)
else:
	num = ceil(H / N)
	num_wait = ceil((H + (20 * 60 - hh * 60 - mm) * D) / N)
	cost = num * C
	cost_wait = 0.8 * num_wait * C
	print(min(cost, cost_wait))


import math
(r, m) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if r >= 20:
	print(math.ceil(h / n) * c * 0.8)
else:
	print(min(math.ceil(((20 * 60 - r * 60 - m) * d + h) / n) * c * 0.8, math.ceil(h / n) * c))


time = [int(i) for i in input().split()]
(hh, mm) = (time[0], time[1])
s = [int(i) for i in input().split()]
(h, d, c, n) = (s[0], s[1], s[2], s[3])
mm += hh * 60
time = 1200
if time - mm <= 0:
	h_res = h
else:
	h_res = h + d * (time - mm)
c_sale = 0.8 * c
if h_res / n == h_res // n:
	count = h_res // n
else:
	count = h_res // n + 1
result1 = count * c_sale
if h / n == h // n:
	count = h // n
else:
	count = h // n + 1
result2 = count * c
print(min(result1, result2))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
hh = hh * 60 + mm
mm = max(20 * 60, hh)
print(min(c * ((h + n - 1) // n), c * 0.8 * (((mm - hh) * d + h + n - 1) // n)))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
from math import ceil
if hh < 20:
	print(min(ceil((h + (60 - mm + (20 - hh - 1) * 60) * d) / n) * c * 0.8, ceil(h / n) * c))
else:
	print(ceil(h / n) * c * 0.8)


import math as m
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hh >= 20:
	at_current = float(0.8 * C * m.ceil(H / N))
	res = at_current
else:
	minutes = (20 - hh) * 60 + 0 - mm
	at_current = float(C * m.ceil(H / N))
	at_20 = float(m.ceil((H + D * minutes) / N) * (C * 0.8))
	res = min(at_current, at_20)
print('{0:.4f}'.format(res))


(hr, m) = [int(x) for x in input().strip().split(' ')]
(h, d, c, n) = [int(x) for x in input().strip().split(' ')]
buns = h // n
if h % n > 0:
	buns += 1
rightAway = buns * c
later = rightAway
if hr >= 20 and hr <= 23:
	rightAway -= rightAway * 0.2
else:
	dMin = 60 - m
	dHr = 20 - (hr + 1)
	dMin += 60 * dHr
	h += d * dMin
	buns = h // n
	if h % n > 0:
		buns += 1
	later = buns * c - buns * c * 0.2
print(min(rightAway, later))


(h, m) = map(int, input().split())
(k, d, c, n) = map(int, input().split())
from math import ceil
if h >= 20:
	print(ceil(k / n) * (c * 0.8))
else:
	a1 = ceil(k / n) * c
	r = 60 * (20 - h) - m
	a2 = ceil((k + r * d) / n) * (c * 0.8)
	print(min(a1, a2))


from math import ceil
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh < 20:
	delta_time = (20 - hh - 1) * 60 + (60 - mm)
	hunger = h + delta_time * d
	ans = ceil(hunger / n) * c * 80 / 100
	ans1 = ceil(h / n) * c
	print(min(ans, ans1))
else:
	ans = ceil(h / n) * c * 80 / 100
	print(ans)


from sys import stdin, stdout
import math
(hours, minutes, hunger, hunger_rate, bun_cost, bun_value) = [int(x) for x in stdin.read().split()]

def answer(hours, minutes, hunger, hunger_rate, bun_cost, bun_value):
	m = hhmm_to_m(hours, minutes)
	minutes_until_8pm = difference(m, 20 * 60)

	def priceNow():
		return buns_required(hunger, bun_value) * bun_cost

	def priceLater():
		bc = 0.8 * bun_cost
		return buns_required(minutes_until_8pm * hunger_rate + hunger, bun_value) * bc
	if minutes_until_8pm > 0:
		return min(priceNow(), priceLater())
	else:
		return priceNow() * 0.8

def hhmm_to_m(hh, mm):
	return hh * 60 + mm

def difference(startminutes, endminutes):
	return endminutes - startminutes

def buns_required(hunger, bun_value):
	return math.ceil(1.0 * hunger / bun_value)

def formatted_answer(answer_value):
	return '{:.4f}'.format(answer_value)
print(formatted_answer(answer(hours, minutes, hunger, hunger_rate, bun_cost, bun_value)))


import math
(h, m) = map(int, input().split())
(h1, d, c, n) = map(int, input().split())
mins = 0
if h < 20:
	mins = (19 - h) * 60 + (60 - m)
newh = h1 + mins * d
cost = math.ceil(h1 / n)
newcost = math.ceil(newh / n)
cost = cost * c
newcost *= c - 0.2 * c
print(min(cost, newcost))


(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())

def noofbuns(hun, n):
	if hun % n == 0:
		return round(hun / n, 4)
	else:
		return round(hun // n + 1, 4)
if h * 60 + m > 1200:
	print(round(noofbuns(H, N) * C * 0.8, 4))
else:
	a = 20 * 60 - h * 60 - m
	ch = H + a * D
	cost1 = round(noofbuns(ch, N) * C * 0.8, 4)
	cost2 = round(noofbuns(H, N) * C, 4)
	print(round(min(cost1, cost2), 4))


(h, m) = list(map(int, input().split()))
(H, D, C, N) = list(map(int, input().split()))
after = C * 0.8
ans = (H + N - 1) // N * C
tm = h * 60 + m
tm1 = 20 * 60 + 0
tm2 = 23 * 60 + 59
if tm1 <= tm <= tm2:
	print('{:.16f}'.format((H + N - 1) // N * after))
else:
	tm3 = tm1 - tm
	print('{:.16f}'.format(min(ans, (H + N - 1 + D * tm3) // N * after)))


import math as ma
from sys import exit

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

def num():
	return map(int, input().split())

def nu():
	return int(input())
(hh, mm) = num()
(h, d, c, n) = num()
x = c - 0.2 * c
if hh < 20:
	v1 = ma.ceil(h / n) * c
	hh1 = 20 * 60 - hh * 60 - mm
	hh1 = h + d * hh1
	v2 = ma.ceil(hh1 / n) * x
	min = min(v1, v2)
	print(min)
else:
	v1 = ma.ceil(h / n) * x
	print(v1)


(hh, mm) = input().split(' ')
hh = int(hh)
mm = int(mm)
(h, d, c, n) = input().split(' ')
h = int(h)
d = int(d)
c = int(c)
n = int(n)
if hh < 20:
	x = ((20 - hh - 1) * 60 + (60 - mm)) * d + h
	x = x / n
	if x == int(x):
		x = int(x)
	else:
		x = int(x) + 1
	disa = 0.8 * c * x
	y = h / n
	if y == int(y):
		y = int(y)
	else:
		y = int(y) + 1
	b = c * y * 1.0
	ans = min(disa, b)
else:
	y = h / n
	if y == int(y):
		y = int(y)
	else:
		y = int(y) + 1
	b = c * y * 0.8
	ans = b
print(ans)


import os, sys
from io import BytesIO, IOBase

def main():
	(h, m) = rints()
	(hunger, plus, cost, neg) = rints()
	cur_time = h * 60 + m
	diff = 0 if 20 * 60 <= cur_time < 24 * 60 else (20 * 60 - cur_time) % 1440
	print(f'{min(ceil1(hunger + diff * plus, neg) * 0.8 * cost, cost * ceil1(hunger, neg)):.3f}')

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
main()


def ceil(m):
	m_floor = int(m // 1)
	diff = m - m_floor
	if diff > 0:
		return m_floor + 1
	else:
		return m_floor
(hh, mm) = list(map(int, input().split()))
(h, d, c, n) = list(map(int, input().split()))
dt_m = 60 - mm
dt_h = 20 - hh
if dt_h <= 0:
	dt = 0
else:
	dt = (dt_h - 1) * 60 + dt_m
if dt > 0:
	wait_h = h + dt * d
	cost = min(0.8 * ceil(wait_h / n) * c, ceil(h / n) * c)
else:
	cost = 0.8 * ceil(h / n) * c
print('{0:.4f}'.format(cost))


from math import ceil
(hh, mm) = [int(i) for i in input().split()]
(H, D, C, N) = [int(i) for i in input().split()]
val1 = ceil(H / N) * C
wait = 20 * 60 - hh * 60 - mm
if hh >= 20:
	val2 = (H + N - 1) // N * C * 0.8
else:
	val2 = ceil((H + wait * D) / N) * 0.8 * C
print(min(val1, val2))


import math

def main():
	(hh, mm) = [int(x) for x in input().split()]
	t = hh * 60 + mm
	(H, D, C, N) = [int(x) for x in input().split()]
	if t > 20 * 60:
		print(math.ceil(H / N) * C * 0.8)
	else:
		c1 = math.ceil(H / N) * C
		dt = 20 * 60 - t
		c2 = math.ceil((H + D * dt) / N) * C * 0.8
		print(min(c1, c2))
main()


import math
(hh, mm) = list(map(int, input().split()))
(h, d, c, n) = list(map(int, input().split()))
if hh >= 20:
	print(c * 0.8 * math.ceil(h / n))
else:
	p = c * 0.8 * math.ceil(((20 * 60 - hh * 60 - mm) * d + h) / n)
	q = c * math.ceil(h / n)
	print(min(p, q))


(hour, minut) = map(int, input().split())
(h, d, c, n) = map(float, input().split())
time = hour * 60 + minut
ind = 0
ans = 100000000000000000000000000000000000000000000000000000
while time < 24 * 60:
	hungr = h + ind * d
	if time >= 20 * 60:
		price = c * 0.8
		if hungr % n == 0:
			a = hungr // n * price
		else:
			a = (hungr // n + 1) * price
	else:
		price = c * 1
		if hungr % n == 0:
			a = hungr // n * price
		else:
			a = (hungr // n + 1) * price
	if a < ans:
		ans = a
	time += 1
	ind += 1
print(ans)


(h, m) = map(int, input().split())
(g, u, s, k) = map(int, input().split())
d20 = (g + k - 1) // k * s
v = (20 - h - 1) * 60 + (60 - m)
if v < 0:
	v = 0
s2 = s - s / 5
p20 = (g + v * u + k - 1) // k * s2
print(min(d20, p20))


from math import ceil
(h, m) = list(map(int, input().split()))
X = list(map(int, input().split()))
print(min(ceil((X[0] + max(20 * 60 - (h * 60 + m), 0) * X[1]) / X[-1]) * (X[-2] - X[-2] * 0.2), ceil(X[0] / X[-1]) * X[-2]))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
mm += hh * 60
if mm >= 1200:
	(t, c) = divmod(H, N)
	if c:
		t += 1
	ans = t * C * 0.8
else:
	(t2_d, t2_m) = divmod(H, N)
	if t2_m:
		t2_d += 1
	H += (1200 - mm) * D
	(t1_d, t1_m) = divmod(H, N)
	if t1_m:
		t1_d += 1
	ans = min(t2_d * C, t1_d * C * 0.8)
print('%3f' % ans)


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
time = hh * 60 + mm
if time <= 1200:
	time = 1200 - time
else:
	time = 0
print(round(min(C * 0.8 * math.ceil((H + time * D) / N), C * math.ceil(H / N)), 4))


(x, y) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
t = 60 * (19 - x) + 60 - y
import math
a = (h + t * d) / n
w = h / n
l = math.ceil(a)
u = math.ceil(w)
if x < 20:
	c1 = l * c * 0.8
	c2 = u * c
else:
	c1 = u * c * 0.8
	c2 = u * c
z = min(c1, c2)
p = format(z, '.4f')
print(p)


from __future__ import print_function, division
from math import ceil
import sys
if sys.version_info < (3, 0):
	input = raw_input
	range = xrange
(ho, mi) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
togo = (20 - ho) * 60 - mi
hungernow = h
hungerthen = h + togo * d
if togo > 0:
	print('%.20f' % min(ceil(hungerthen / n) * (c * 0.8), ceil(hungernow / n) * c))
else:
	print('%.20f' % (ceil(hungernow / n) * (c * 0.8)))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	buns = math.ceil(h / n)
	print(buns * c * 0.8)
elif mm == 0:
	reh = 20 - hh
	buns = math.ceil(h / n)
	c1 = buns * c
	h += reh * 60 * d
	bu = math.ceil(h / n)
	c2 = bu * c * 0.8
	print(min(c1, c2))
else:
	buns = math.ceil(h / n)
	c1 = buns * c
	rem = 60 - mm
	hh += 1
	reh = 20 - hh
	h += rem * d
	h += reh * 60 * d
	bu = math.ceil(h / n)
	c2 = bu * c * 0.8
	print(min(c1, c2))


(n, m) = map(int, input().split())
(a, b, c, d) = map(int, input().split())
if n >= 20:
	p = 0
else:
	p = (19 - n) * 60 + 60 - m
k = a // d
if a % d != 0:
	k += 1
k1 = (a + p * b) // d
if (a + p * b) % d != 0:
	k1 += 1
print(min(k * c, k1 * 0.8 * c))


from math import ceil
(h, m) = map(int, input().split())
(hang, d, c, n) = map(int, input().split())
if 20 <= h <= 23:
	print(ceil(hang / n) * (c * 0.8))
else:
	se = ceil(hang / n) * c
	t = (20 - h - 1) * 60 + 60 - m
	p = ceil((hang + d * t) / n) * (c * 0.8)
	if se < p:
		print('%.5f' % se)
	else:
		print('%.5f' % p)


(hh, mm) = map(int, input().split())
curminutes = hh * 60 + mm
(h, d, c, n) = map(int, input().split())
cost_now = (h + n - 1) // n * c
thenminutes = 20 * 60
if thenminutes <= curminutes:
	print(cost_now * 0.8)
else:
	hunger_then = (thenminutes - curminutes) * d + h
	print(min(cost_now, (hunger_then + n - 1) // n * c * 0.8))


R = lambda : list(map(int, input().split()))
(hh, mm) = R()
(h, d, c, n) = R()
import math
cb = math.ceil(h * 1.0 / n) * c
mn = hh * 60 + mm
e = 20 * 60
dp = c * 0.8
if mn <= e:
	nh = h + d * (e - mn)
	cb = min(cb, math.ceil(nh * 1.0 / n) * dp)
else:
	cb = cb * 0.8
print(cb)


(hh, mm) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
mref = 20 * 60
mnow = hh * 60 + mm
if mnow >= mref:
	num = int(H / N)
	if H % N != 0:
		num += 1
	print(num * 0.8 * C)
else:
	hun = H + D * (mref - mnow)
	num = int(hun / N)
	if hun % N != 0:
		num += 1
	m1 = num * 0.8 * C
	hun = H
	num = int(hun / N)
	if hun % N != 0:
		num += 1
	m2 = num * C
	print('%.4f' % min(m1, m2))


import math
(hou, m) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hou in range(20, 24):
	print(math.ceil(h / n) * (4 / 5 * c))
else:
	fir = math.ceil(h / n) * c
	hd = 20 - hou - 1
	md = 60 - m
	sec = math.ceil((h + (60 * hd + md) * d) / n) * 4 * c / 5
	print(min(fir, sec))


ans2 = 99999999999999
(t, m) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
a = h // n
if h % n > 0:
	a += 1
ans1 = a * c
if t < 20:
	m_left = 60 - m
	t_left = 20 - t
	t_left -= 1
	t_left = t_left * 60
	t_left += m_left
	t_left *= d
	h += t_left
	b = h // n
	if h % n > 0:
		b += 1
	ans2 = b * c
	dis = ans2 * 0.2
	ans2 -= dis
else:
	ans2 = ans1 - ans1 * 0.2
print(min(ans1, ans2))


import math
a = input()
a = a.split()
hh = int(a[0])
mm = int(a[1])
a = input()
a = a.split()
h = int(a[0])
d = int(a[1])
c = int(a[2])
n = int(a[3])
if hh >= 20:
	xx = math.ceil(h / n) * c * 0.8
else:
	t = (19 - hh) * 60 + (60 - mm)
	d = d * t
	if math.ceil(h / n) * c > math.ceil((h + d) / n) * c * 0.8:
		xx = math.ceil((h + d) / n) * c * 0.8
	else:
		xx = math.ceil(h / n) * c
print(format(xx, '.4f'))


tim = [int(x) for x in input().split()]
hh = tim[0]
mm = tim[1]
n = [int(x) for x in input().split()]
H = n[0]
D = n[1]
C = n[2]
N = n[3]
time = hh * 60 + mm
disTime = 20 * 60
h0 = H
buns0 = 0
if time > disTime:
	while h0 > 0:
		buns0 += 1
		h0 -= N
	value0 = round(C * buns0 * 0.8, 4)
	print(value0)
	exit()
elif time < disTime:
	catHunger = H + D * (disTime - time)
	h1 = catHunger
	buns1 = 0
	while h1 > 0:
		buns1 += 1
		h1 -= N
	value1 = round(C * buns1 * 0.8, 4)
	h2 = H
	buns2 = 0
	while h2 > 0:
		buns2 += 1
		h2 -= N
	value2 = round(C * buns2, 4)
print(min(value1, value2))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(float, input().split())
sum1 = float(H // N * C)
sum2 = 10000000000000000000000
if H % N != 0:
	sum1 += C
if hh >= 20 and hh < 24:
	sum1 *= 0.8
if hh < 20:
	dh = 19 - hh
	dm = 60 - mm
	H += (dh * 60 + dm) * D
	sum2 = float(H // N * C * 0.8)
	if H % N != 0:
		sum2 += C * 0.8
print(min(sum1, sum2))


import math
(hh, mm) = list(map(int, input().split()))
(h, d, c, n) = list(map(int, input().split()))
dc = c - 0.2 * c
ans = 0
if 20 <= hh and hh <= 23:
	ans = dc * math.ceil(h / n)
else:
	ans1 = c * math.ceil(h / n)
	ans2 = dc * math.ceil((h + d * ((20 - hh) * 60 - mm)) / n)
	ans = min(ans1, ans2)
print(ans)


R = lambda : map(int, input().split())
(h, m) = R()
(l, d, c, n) = R()
print(min((l + n - 1) // n * c, (l + n - 1 + max(0, d * ((20 - h) * 60 - m))) // n * c * 0.8))


import math
wakeup_time = list(map(int, input().split()))
hour = wakeup_time[0]
minute = wakeup_time[1]
paramters = list(map(int, input().split()))
h = paramters[0]
d = paramters[1]
c = paramters[2]
n = paramters[3]
DISCOUNT_TIME = 20
DISCOUNT = 0.8
MAX_MINUTES = 60
min_cost = 10120000
no_disc_cost = math.ceil(h / n) * c
rem_mins = (DISCOUNT_TIME - hour) * MAX_MINUTES
if minute != 0:
	rem_mins = rem_mins - minute
disc_cost = DISCOUNT * c
total_disc_cost = math.ceil((h + d * rem_mins) / n) * disc_cost
if hour >= DISCOUNT_TIME:
	min_cost = math.ceil(h / n) * disc_cost
else:
	min_cost = min(no_disc_cost, total_disc_cost)
print('%.4f' % min_cost)


import os
import math
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(h, m) = invr()
	(H, D, C, N) = invr()
	curr_time = h * 60 + m
	curr_cost = math.ceil(H / N) * C
	later_cost = curr_cost
	if curr_time <= 1200:
		H += (1200 - curr_time) * D
		later_cost = math.ceil(H / N) * C
		later_cost *= 0.8
	else:
		curr_cost *= 0.8
		later_cost = curr_cost
	print(min(curr_cost, later_cost))


import math
(time_hour, time_sec) = [int(i) for i in input().strip().split()]
(h, d, c, n) = [int(i) for i in input().strip().split()]
time_difference = 0
if time_hour < 20:
	time_difference = 20 - time_hour
	if time_sec != 0:
		time_difference -= 1
		time_difference *= 60
		time_difference += 60 - time_sec
	else:
		time_difference *= 60
print(min(math.ceil((h + time_difference * d) / n) * c * 0.8, math.ceil(h / n) * c))


from math import ceil

def main():
	tmp = list(map(int, input().split()))
	t = tmp[0] * 60 + tmp[1]
	(h, d, c, n) = list(map(int, input().split()))
	a = c * ceil(h / n)
	if t >= 20 * 60:
		b = 0.8 * c * ceil(h / n)
	else:
		b = 0.8 * c * ceil((d * (20 * 60 - t) + h) / n)
	print('{:f}'.format(a if a < b else b))
main()


from math import ceil
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
print(min(C * ceil(H / N), 4 * C * 1 / 5 * ceil((D * max(0, 60 * 20 - 60 * hh - mm) + H) / N)))


import math
time = input()
time = list(map(int, time.split()))
(hh, mm) = (time[0], time[1])
par = input()
par = list(map(int, par.split()))
(H, D, C, N) = (par[0], par[1], par[2], par[3])
if hh >= 20 and hh < 24:
	res = math.ceil(H / N) * C * 0.8
else:
	res1 = math.ceil(H / N) * C
	wait = (19 - hh) * 60 + (60 - mm)
	res2 = math.ceil((H + wait * D) / N) * C * 0.8
	res = min(res1, res2)
print(res)


from math import ceil
(h, m) = list(map(int, input().split()))
(H, d, c, n) = list(map(float, input().split()))
if h >= 20:
	print(round(ceil(H / n) * c * 0.8, 3))
else:
	print(round(min(ceil(H / n) * c, ceil(((20 * 60 - h * 60 - m) * d + H) / n) * c * 0.8), 3))


import math
(hh, mm) = map(float, input().split())
(H, D, C, N) = map(float, input().split())
mm += hh * 60
if mm >= 1200:
	print(math.ceil(H / N) * C * 0.8)
else:
	print(min(math.ceil(H / N) * C, math.ceil((H + D * (1200 - mm)) / N) * C * 0.8))


from math import ceil
x = input().split()
(hh, mm) = (int(x[0]), int(x[1]))
x = input().split()
(h, d, c, n) = (int(x[0]), int(x[1]), int(x[2]), int(x[3]))
if hh < 20:
	a = ceil((((20 - hh - 1) * 60 + 60 - mm) * d + h) / n) * c * 0.8
	b = ceil(h / n) * c
	print(min(a, b))
else:
	a = ceil(h / n) * c * 0.8
	print(a)


from math import ceil
import datetime
time = [int(i) for i in input().split()]
(h, d, c, n) = [int(i) for i in input().split()]

def subtract(time):
	minutesTwenty = 20 * 60
	minutes = time[0] * 60 + time[1]
	return minutesTwenty - minutes

def cost(h, c, n):
	return ceil(h / n) * c

def moneyAfter(time, h, d, c, n):
	if subtract(time) < 0:
		newh = h
	else:
		newh = subtract(time) * d + h
	return cost(newh, c, n) - cost(newh, c, n) * 0.2

def moneyBefore(time, h, d, c, n):
	if subtract(time) < 0:
		return 999999999999999999999999999999999999999
	return cost(h, c, n)
if moneyBefore(time, h, d, c, n) > moneyAfter(time, h, d, c, n):
	print(moneyAfter(time, h, d, c, n))
else:
	print(moneyBefore(time, h, d, c, n))


import math
a = [int(x) for x in input().split()]
hh = a[0]
mm = a[1]
a = [int(x) for x in input().split()]
h = a[0]
d = a[1]
c = a[2]
n = a[3]
if hh < 20:
	ans1 = math.ceil(h / n)
	ans1 = ans1 * c
	minutes = 60 - mm + (20 - hh - 1) * 60
	h = h + minutes * d
	ans2 = math.ceil(h / n)
	cs = c - 0.2 * c
	ans2 = ans2 * cs
	if ans2 < ans1:
		print('%.4f' % ans2)
	else:
		print('%.4f' % ans1)
elif hh >= 20 and hh <= 23:
	c = c - 0.2 * c
	ans = math.ceil(h / n)
	ans = ans * c
	print('%.4f' % ans)


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if 20 - hh < 0 or (20 - hh == 0 and mm > 0):
	print(math.ceil(H / N) * C * 0.8)
	exit(0)
from20clock = (20 - hh) * 60 - mm
need = from20clock * D + H
cost1 = math.ceil(need / N) * C * 0.8
cost2 = math.ceil(H / N) * C
print(min(cost1, cost2))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh < 20:
	ht = 0
	ht += (20 - hh - 1) * 60
	ht += 60 - mm
	ht *= d
	x1 = math.ceil(h / n) * c
	x2 = math.ceil((h + ht) / n) * c * 0.8
	print(float(min(x1, x2)))
else:
	x = math.ceil(h / n) * c
	x *= 0.8
	print(float(x))


from math import ceil
(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
diff = max(0, 20 * 60 - (h * 60 + m))
ans = min(ceil(H / N) * C, ceil((H + diff * D) / N) * 0.8 * C)
print(ans)


from math import ceil
(hrs, mn) = map(int, input().split())
p_time = hrs * 60 + mn
(h, d, c, n) = map(float, input().split())
if p_time >= 1200:
	print(ceil(h / n) * 0.8 * c)
else:
	cost1 = ceil(h / n) * c
	m_min = 1200 - p_time
	h += d * m_min
	cost2 = ceil(h / n) * 0.8 * c
	print(min(cost1, cost2))


(h, m) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
current_time = h * 60 + m
current_buns = H // N
if H % N != 0:
	current_buns += 1
if current_time > 1200:
	print(current_buns * C * 0.8)
else:
	later_hunger = H + D * (1200 - current_time)
	later_buns = later_hunger // N
	if later_hunger % N != 0:
		later_buns += 1
	current_money = current_buns * C
	later_money = later_buns * C * 0.8
	if later_money > current_money:
		print(current_money)
	else:
		print(later_money)


import math
(hh, mm) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
M = 1000000000
(cost1, cost2, cost3) = (M, M, M)
nbuns = math.ceil(H / N)
cost1 = nbuns * C
disc_time = 20 * 60
close_time = 23 * 60 + 59
woke_time = hh * 60 + mm
if woke_time < disc_time:
	wait_time = disc_time - woke_time
	HH = H + D * wait_time
	nbuns = math.ceil(HH / N)
	cost2 = nbuns * C * 0.8
elif disc_time <= woke_time and woke_time <= close_time:
	nbuns = math.ceil(H / N)
	cost3 = nbuns * C * 0.8
cost = min(cost1, cost2, cost3)
print('{:.4f}'.format(cost))


import math as ma
H = list(map(int, input().split()))
a = list(map(int, input().split()))
if H[0] >= 20:
	ans = ma.ceil(a[0] / a[3])
	ans = ans * a[2]
	ans = ans * 0.8
	print(ans)
else:
	t = (20 - H[0]) * 60 - H[1]
	hn = a[0] + a[1] * t
	ans1 = ma.ceil(hn / a[3])
	ans1 = ans1 * a[2]
	ans1 = ans1 * 0.8
	ans = ma.ceil(a[0] / a[3])
	ans = ans * a[2]
	print(min(ans, ans1))


import math
import time
(h, m) = list(map(int, input().split()))
(hunger, decr, cost, n) = list(map(int, input().split()))
if h >= 20:
	b = hunger // n
	if hunger % n != 0:
		b += 1
	print(0.8 * b * cost)
else:
	b = hunger // n
	if hunger % n != 0:
		b += 1
	a = b * cost
	t = 20 * 60 - h * 60 - m
	hunger += t * decr
	b = hunger // n
	if hunger % n != 0:
		b += 1
	c = 0.8 * b * cost
	print(min(a, c))


s = input().split(' ')
time2 = 60 * 20
time1 = int(s[0]) * 60 + int(s[1])
if int(s[0]) >= 20:
	time1 = time2
(h, d, c, n) = map(int, input().split())
cost1 = h // n
if h % n != 0:
	cost1 += 1
hunger = h
cost1 *= c
cost2 = 0
y = time1
while y != time2:
	hunger += d
	y += 1
cost2 = hunger // n
if hunger % n != 0:
	cost2 += 1
hunger = h
cost2 *= c * 0.8
y = time1
cost3 = 0
while y != time2:
	cost3 += c
	hunger += d - n
	y += 1
count = hunger // n
if hunger % n != 0:
	count += 1
hunger = h
cost3 += c * count * 0.8
print(min(cost1, cost2, cost3))


import math
str = input()
str.replace(str[-1], ' ')
(hour, min) = map(int, str.split())
(H, D, C, N) = map(float, input().split())
s = 0
k = math.ceil((H + ((20 - hour) * 60 - min) * D) / N) * C * 0.8
n = C * math.ceil(H / N)
if (20 - hour) * 60 - min <= 0:
	s = n * 0.8
elif k < n:
	s = k
else:
	s = n
print(s)


__author__ = 'Esfandiar'
from math import ceil
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh < 20:
	M1 = ceil(h / n) * c
	h += (1200 - (hh * 60 + mm)) * d
	M2 = ceil(h / n) * (c - c / 5)
	print(min(M1, M2))
else:
	y = ceil(h / n) * (c - c / 5)
	print(y)


import sys
import math

def read_in():
	lines = sys.stdin.readlines()
	for i in range(len(lines)):
		lines[i] = lines[i].replace('\n', '')
	return lines

def main():
	lines = read_in()
	time = lines[0]
	params = lines[1]
	time_array = time.split(' ')
	params_array = params.split(' ')
	hh = int(time_array[0])
	mm = int(time_array[1])
	H = int(params_array[0])
	D = int(params_array[1])
	C = int(params_array[2])
	N = int(params_array[3])
	minutes_before_20 = (19 - hh) * 60 + (60 - mm)
	if minutes_before_20 < 0:
		minutes_before_20 = 0
	hung_at_20 = H + D * minutes_before_20
	hung_now = H
	m1 = float(math.ceil(hung_at_20 / N) * (C - C * 0.2))
	m2 = float(math.ceil(hung_now / N) * C)
	money_amount = min(m1, m2)
	print('{0:.4f}'.format(round(money_amount, 4)))
main()


l1 = list()
l2 = list()
l1 = input()
l2 = input()
l1 = l1.split(' ')
l2 = l2.split(' ')
h = float(l1[0])
m = float(l1[1])
H = float(l2[0])
D = float(l2[1])
C = float(l2[2])
N = float(l2[3])
ans = H
res = 0
if h >= 20:
	if H % N != 0:
		H += N - H % N
	print(H * (4 * C) / (5 * N))
	raise SystemExit
if ans % N != 0:
	ans += N - ans % N
ans = ans * C / N
m += h * 60
res = 1200 - m
res *= D
res += H
if res % N != 0:
	res += N - res % N
res = res * (4 * C) / (5 * N)
if res < ans:
	print(res)
else:
	print(ans)


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
now_amount = math.ceil(H / N) * C
if hh > 20 or (hh == 20 and mm > 0):
	print(now_amount * 0.8)
	exit(0)
delta_time = 20 * 60 - hh * 60 - mm
amount = math.ceil((H + delta_time * D) / N) * C * 0.8
print(min(now_amount, amount))


import math
(hh, mm) = input().split()
(h, d, c, n) = input().split()
hh = int(hh)
mm = int(mm)
h = int(h)
d = int(d)
c = int(c)
n = int(n)
sum = 0
if hh < 20:
	m = (20 - hh) * 60 - mm
	hung = h + m * d
	sum_2 = math.ceil(hung / n) * c * 0.8
	sum_1 = math.ceil(h / n) * c
	if sum_2 > sum_1:
		sum = sum_1
	else:
		sum = sum_2
else:
	sum = math.ceil(h / n) * c * 0.8
print('{:.4f}'.format(sum))


from math import ceil
(hrs, mins) = [int(x) for x in input().split()]
start_mins = hrs * 60 + mins
Limit_mins = 1200
additional_min = [0, Limit_mins - start_mins][start_mins < Limit_mins]
(hunger, incr, price, decr_ratio) = [int(x) for x in input().split()]
needed_now = ceil(hunger / decr_ratio)
curr_cost = needed_now * price
needed_at8 = ceil((hunger + additional_min * incr) / decr_ratio) * price * 0.8
print(min(needed_at8, curr_cost))


rd = lambda : map(int, input().split())
(h, m) = rd()
t = h * 60 + m
(h, d, c, n) = rd()
print(min((h + n - 1) // n * c, (max(0, 1200 - t) * d + h + n - 1) // n * c * 0.8))


R = lambda : map(int, input().split())
(h, m) = R()
(H, D, C, N) = R()
opt1 = (H // N + (H % N > 0)) * C
m = max(0, (20 - h) * 60 - m)
H = H + m * D
C = C / 5 * 4
opt2 = (H // N + (H % N > 0)) * C
print(min(opt1, opt2))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh in range(20, 24):
	print(math.ceil(h / n) * c * 4 / 5)
else:
	p1 = math.ceil(h / n) * c
	hd = 20 - hh - 1
	md = 60 - mm
	p2 = math.ceil((h + (60 * hd + md) * d) / n) * 4 * c / 5
	print(min(p1, p2))


from math import *
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
s = 1200
w = hh * 60 + mm
if w < s:
	xx = (s - w) * d + h
	x = ceil(xx / n) * c
	x = x - 0.2 * x
	y = float(ceil(h / n) * c)
	print(min(y, x))
else:
	xx = ceil(h / n) * c
	x = float(xx - 0.2 * xx)
	print(x)


from math import ceil
(h, m) = map(int, input().split())
if h >= 20:
	a = list(map(int, input().split()))
	a[2] *= 0.8
	print(ceil(a[0] / a[3]) * a[2])
else:
	a = list(map(int, input().split()))
	x = 1200 - (60 * h + m)
	y = ceil(a[0] / a[3]) * a[2]
	a[0] += x * a[1]
	a[2] *= 0.8
	z = ceil(a[0] / a[3]) * a[2]
	if y < z:
		z = y
	print('%.4f' % z)


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	print(c * 0.8 * ((h + n - 1) // n))
else:
	t = (20 - 1 - hh) * 60 + 60 - mm
	H = h + t * d
	print(min(c * ((h + n - 1) // n), c * 0.8 * ((H + n - 1) // n)))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh <= 19:
	hh = 19 - hh
	mm = 60 - mm
	hung1 = h + hh * 60 * d + mm * d
if hh >= 20:
	hung1 = h
hung2 = h
cost1 = math.ceil(hung1 / n) * 0.8 * c
cost2 = math.ceil(hung2 / n) * c
print(min(float(cost1), float(cost2)))


def f(l1, l2):
	(hh, mm) = l1
	(h, d, c, n) = l2
	m = hh * 60 + mm
	if m > 1200:
		return 0.8 * c * ((h + n - 1) // n)
	h2 = h + (1200 - m) * d
	return min(c * ((h + n - 1) // n), 0.8 * c * ((h2 + n - 1) // n))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
print(f(l1, l2))


TN = 1

def hour(hh, mm):
	ans = 1200 - 60 * hh - mm
	if ans > 0:
		return ans
	return 0

def solution():
	from math import ceil
	(hh, mm) = map(int, input().split())
	(h, d, c, n) = map(int, input().split())
	h1 = h + d * hour(hh, mm)
	ans = min(ceil(h1 / n) * c * 0.8, ceil(h / n) * c)
	print('%G' % ans)
while TN != 0:
	solution()
	TN -= 1


from math import ceil
t = list(map(int, input().split()))
i = list(map(int, input().split()))
hh = t[0]
mm = t[1]
H = i[0]
D = i[1]
C = i[2]
N = i[3]
if 20 <= hh and hh <= 23:
	cost_20 = ceil(H / N) * (C * 0.8)
else:
	time_passed = (20 - hh) * 60 - mm
	H_new = H + time_passed * D
	cost_20 = ceil(H_new / N) * (C * 0.8)
cost = ceil(H / N) * C
if cost < cost_20:
	print(cost)
else:
	print(cost_20)


import sys
readline = sys.stdin.readline
(h, m) = map(int, readline().split())
T = h * 60 + m
dic = 20 * 60 + 0
(H, D, C, N) = map(int, readline().split())
if T < dic:
	ans = min((-(-H // N) * C, -(-(H + (dic - T) * D) // N) * (C * 0.8)))
else:
	ans = -(-H // N) * C * 0.8
print(ans)


(h, m) = [int(i) for i in input().split()]
(H, D, C, N) = [int(i) for i in input().split()]
minutes_to_discount = (19 - h) * 60 + (60 - m)
if minutes_to_discount < 0:
	C = C * 0.8
hunger_discount = H + D * minutes_to_discount
cost_now = (int(H // N) + (H % N > 0)) * C
cost_then = (int(hunger_discount // N) + (hunger_discount % N > 0)) * C * 0.8
if minutes_to_discount < 0:
	print(cost_now)
else:
	print(min(cost_now, cost_then))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh <= 20:
	if mm == 0 or hh == 20:
		x = 20 - hh
		y = 0
	else:
		x = 19 - hh
		y = 60 - mm
	m = x * 60 + y
	l = math.ceil(h / n)
	tc1 = c * l
	h = h + d * m
	l1 = math.ceil(h / n)
	tc2 = (c - 0.2 * c) * l1
	print(min(tc1, tc2))
if hh > 20:
	l1 = math.ceil(h / n)
	tc2 = (c - 0.2 * c) * l1
	print(tc2)


from math import ceil
(hour, minutes) = map(int, input().split(' '))
(h, d, c, n) = map(int, input().split(' '))
buns = ceil(h / n)
cost1 = c * buns
if hour < 20:
	inMin = 20 * 60
	hour_min = 60 * hour
	minutes += hour_min
	difTime = inMin - minutes
	h += d * difTime
	buns = ceil(h / n)
	cost2 = c * buns * 0.8
else:
	cost2 = cost1 * 0.8
print('%.4f' % min(cost1, cost2))


(hours, minutes) = map(int, input().split())
(h, d, c, n) = map(float, input().split())
ans = 1000000000000000
for i in range(1440):
	if i < 60 * hours + minutes:
		continue
	dop_time = 60 * hours + minutes - i
	dop_value = dop_time * d
	golod = h + d * (i - 60 * hours - minutes)
	t = golod // n
	if golod > t * n:
		t += 1
	money = t * c
	if i >= 60 * 20:
		money *= 0.8
	ans = min(ans, money)
print(ans)


(h, m) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
money1 = 0
money2 = 0
mtotw = 0
if 20 <= h:
	if H % N:
		money2 = (H // N + 1) * (C - C * 0.2)
	else:
		money2 = H // N * (C - C * 0.2)
	print('%.4f' % money2)
else:
	if H % N:
		money1 = (H // N + 1) * C
	else:
		money1 = H // N * C
	if m == 0:
		mtotw = (20 - h) * 60
	else:
		mtotw = (20 - h - 1) * 60
		mtotw += 60 - m
	H += mtotw * D
	if H % N:
		money2 = (H // N + 1) * (C - C * 0.2)
	else:
		money2 = H // N * (C - C * 0.2)
	if money2 > money1:
		print('%.4f' % money1)
	else:
		print('%.4f' % money2)


from math import ceil
(hh, mm) = [int(x) for x in input().split()]
(H, D, C, N) = [int(x) for x in input().split()]
cst = ceil(H / N) * C
time_to_seil = 0
if hh < 20:
	time_to_seil = (20 - hh) * 60 - mm
print(min(cst, ceil((H + D * time_to_seil) / N) * C * 0.8))


t = input()
t = t.split()
t1 = int(t[0])
t2 = int(t[1])
a = input()
a = a.split()
h = int(a[0])
d = int(a[1])
c = int(a[2])
n = int(a[3])
if t1 >= 20:
	c = c * (8 / 10)
	q = h // n
	if h // n - h / n != 0:
		q = q + 1
	print(q * c)
else:
	td = (20 - t1) * 60 - t2
	h2 = h + td * d
	q2 = h2 // n
	q = h // n
	if h2 // n - h2 / n != 0:
		q2 = q2 + 1
	if h // n - h / n != 0:
		q = q + 1
	print(min(q2 * c * (8 / 10), q * c))


def f(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
t = hh * 60 + mm
if t >= 20 * 60:
	print(c * f(h, n) * 0.8)
else:
	print(min(c * f(h, n), c * 0.8 * f((20 * 60 - t) * d + h, n)))


import math
p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
H = int(q[0])
D = int(q[1])
C = int(q[2])
N = int(q[3])
l = []
if int(p[0]) < 20:
	Y = math.ceil(H / N)
	l.append(Y * C)
	V = (20 - int(p[0]) - 1) * 60
	B = 60 - int(p[1])
	V += B
	H = H + V * D
	Y = math.ceil(H / N)
	M = Y * C * 20 / 100
	l.append(Y * C - M)
	print(min(l))
else:
	Y = math.ceil(H / N)
	M = Y * C * 20 / 100
	l.append(Y * C - M)
	print(min(l))


(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
if hh >= 20:
	C = 0.8 * C
	cost = C * ((H + N - 1) // N)
	print('{:.4f}'.format(cost))
else:
	dh = 20 - hh - 1
	dm = 60 - mm
	t = dh * 60 + dm
	cost1 = C * ((H + N - 1) // N)
	cost2 = 0.8 * C * ((H + t * D + N - 1) // N)
	m = min(cost1, cost2)
	print('{:.4f}'.format(m))


import math
(h, m) = map(int, input().split())
(hu, d, c, n) = map(int, input().split())
temp = 1
if h < 20:
	if m != 0:
		temp = abs(19 - h) * 60 + (60 - m)
	else:
		temp = abs(20 - h) * 60
	temp = temp * d + hu
	temp = math.ceil(temp / n)
	temp1 = temp * c * 0.2
	temp = temp * c
	temp = temp - temp1
else:
	temp = math.ceil(hu / n) * 0.2 * c
	temp1 = math.ceil(hu / n) * c
	temp = abs(temp - temp1)
temp2 = math.ceil(hu / n)
temp2 = temp2 * c
if temp > temp2:
	print('%.4f' % temp2)
else:
	print('%.4f' % temp)


(hh, mm) = (int(x) for x in input().split())
(h, d, c, n) = (int(x) for x in input().split())
amnt = h // n
if amnt * n != h:
	amnt += 1
if hh >= 20:
	print(amnt * c * 0.8)
else:
	curr = amnt * c * 1.0
	time = (20 - hh) * 60 - mm
	nxt_amnt = (h + d * time) // n
	if nxt_amnt * n != h + d * time:
		nxt_amnt += 1
	nxt = nxt_amnt * c * 0.8
	print(min(curr, nxt))


(hh, mm) = [int(v) for v in input().split()]
(H, D, C, N) = [int(v) for v in input().split()]

def dvru(a, b):
	return (a + b - 1) // b
if hh >= 20:
	print(dvru(H, N) * (C * 0.8))
else:
	c1 = dvru(H, N) * C
	t = (20 - hh - 1) * 60 + (60 - mm)
	c2 = dvru(H + t * D, N) * (C * 0.8)
	print(min(c1, c2))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	print((h + n - 1) // n * (0.8 * c))
	quit()
mm1 = 1200 - hh * 60 - mm
print(min((h + n - 1) // n * c, (h + mm1 * d + n - 1) // n * (c * 0.8)))


import sys
import math
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
ax = list(map(int, sys.stdin.readline().split(' ')))
hh = ax[0]
mm = ax[1]
a = list(map(int, sys.stdin.readline().split(' ')))
h = a[0]
d = a[1]
c = a[2]
n = a[3]
if hh < 20:
	m1 = math.ceil(h / n) * c
	hrd = d * ((20 - hh) * 60 - mm)
	m2 = math.ceil((h + hrd) / n) * c * 0.8
	print(min(m1, m2))
else:
	m1 = math.ceil(h / n) * c * 0.8
	print(m1)


[n, m] = input().split(' ')
hh = int(n)
mm = int(m)
string = input().split(' ')
a = float(string[0])
b = float(string[1])
c = float(string[2])
d = float(string[3])
if hh < 20:
	num = ((20 - hh) * 60 - mm) * b + a
	if num % d == 0:
		sum1 = num // d
	else:
		sum1 = num // d + 1
	money1 = sum1 * c * 0.8
	if a % d == 0:
		sum2 = a // d
	else:
		sum2 = a // d + 1
	money2 = sum2 * c
	if money1 < money2:
		print('{:.4f}'.format(money1))
	else:
		print('{:.4f}'.format(money2))
else:
	if a % d == 0:
		sum3 = a // d
	else:
		sum3 = a // d + 1
	money = sum3 * c * 0.8
	print('{:.4f}'.format(money))


(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	print((h + n - 1) // n * c * 0.8)
else:
	cur = (h + n - 1) // n * c
	tr = (19 - hh) * 60 + (60 - mm)
	new = (h + n - 1 + tr * d) // n * c * 0.8
	print('%0.4f' % min(cur, new))


import math
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
one = math.ceil(h / n) * c
minutes = 0
if hh >= 20:
	minutes = 0
else:
	minutes = (19 - hh) * 60 + 60 - mm
tot = h + minutes * d
dis = c - c * 0.2
two = math.ceil(tot / n) * dis
ans = min(one, two)
print('{0:.4f}'.format(ans))


(th, tm) = input().split(' ')
(h, d, c, n) = input().split(' ')
th = int(th)
tm = int(tm)
h = int(h)
d = int(d)
c = int(c)
n = int(n)
if th < 20:
	toh = 20 - th - 1
	tom = 60 - tm
	tth = d * (toh * 60 + tom)
	ht = h + tth
	if ht % n == 0:
		htn = ht / n
	else:
		htn = ht // n + 1
	if h % n == 0:
		httn = h / n
	else:
		httn = h // n + 1
	cot = c * htn * 0.8
	if cot < c * httn:
		print('{0:.4f}'.format(cot))
	else:
		print('{0:.4f}'.format(c * httn))
elif th >= 20:
	if h % n == 0:
		httn = h / n
	else:
		httn = h // n + 1
	print('{0:.4f}'.format(c * httn * 0.8))


import math
(t, m) = input().split()
(h, d, c, n) = input().split()
t = int(t)
m = int(m)
h = int(h)
d = int(d)
c = int(c)
n = int(n)
if t >= 20:
	print(math.ceil(h / n) * c * 0.8)
else:
	dif = 20 * 60 - t * 60 - m
	ans1 = math.ceil((h + d * dif) / n) * c * 0.8
	ans2 = math.ceil(h / n) * c
	print(min(ans1, ans2))


import math
numbers = list(map(int, input().split()))
hh = numbers[0]
mm = numbers[1]
numbers = list(map(int, input().split()))
H = numbers[0]
D = numbers[1]
C = numbers[2]
N = numbers[3]

def func(hh, mm, H, D, C, N):
	minute = hh * 60 + mm
	if minute >= 1200:
		return C * math.ceil(H / N) * 0.8
	else:
		t = 1200 - H / (4 * D)
		a = C * math.ceil(H / N)
		b = C * math.ceil((H + (1200 - minute) * D) / N) * 0.8
		return min(a, b)
z = func(hh, mm, H, D, C, N)
print('%.4f' % z)


FMT = '%H:%M'
from datetime import datetime
import math

def calc(hh, mm, h, d, c, n, s, s2):
	a = 100000000000000.0
	b = math.ceil(h / n) * c
	if hh < 20:
		extra = datetime.strptime(s2, FMT) - datetime.strptime(s, FMT)
		extra = extra.seconds
		extra /= 60
		h += d * extra
		a = math.ceil(h / n) * c * 0.8
	elif hh >= 20:
		a = math.ceil(h / n) * c * 0.8
	print('%.5f' % min(a, b))
s2 = '20:00'
s = input()
(hh, mm) = map(int, s.split(' '))
s = str(hh) + ':' + str(mm)
(h, d, c, n) = map(int, input().split(' '))
calc(hh, mm, h, d, c, n, s, s2)


import math
from datetime import timedelta
(hh, mm) = map(int, input().split())
(h, d, c, n) = map(int, input().split())
if hh >= 20:
	cost = c * math.ceil(h / n)
	cost -= cost * 0.2
else:
	cost_noDis = c * math.ceil(h / n)
	t1 = timedelta(hours=20, minutes=0)
	t2 = timedelta(hours=hh, minutes=mm)
	t = t1 - t2
	time = list(str(t).split(':'))
	h_20 = h + (60 * int(time[0]) + int(time[1])) * d
	cost_dis = c * math.ceil(h_20 / n)
	cost_dis = cost_dis - cost_dis * 0.2
	cost = min(cost_dis, cost_noDis)
print(format(cost, '.4f'))


import math
(hr, m) = [int(x) for x in input().split()]
(h, d, c, n) = [int(x) for x in input().split()]
totalmin = hr * 60 + m
if totalmin >= 1200:
	print(0.8 * c * math.ceil(h / n))
	exit()
mina1 = c * math.ceil(h / n)
leftmin = 1200 - totalmin
h += leftmin * d
mina2 = 0.8 * c * math.ceil(h / n)
print(min(mina1, mina2))


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(float, input().split())
if hh < 20:
	kol_bulocheck_srazu = math.ceil(H / N)
	cena_srazu = C * kol_bulocheck_srazu
	rasnhh = 20 - hh
	if mm != 0:
		rasnhh -= 1
		mm = 60 - mm
	rasn = rasnhh * 60 + mm
	golod_dolb = D * rasn + H
	kol_bulocheck = math.ceil(golod_dolb / N)
	cena_dolb = C * 0.8 * kol_bulocheck
	if cena_dolb < cena_srazu:
		print('%.3f' % cena_dolb)
	elif cena_dolb > cena_srazu:
		print('%.3f' % cena_srazu)
	elif cena_dolb == cena_srazu:
		print('%.3f' % cena_srazu)
elif hh >= 20:
	kol_bulocheck = math.ceil(H / N)
	cena = C * 0.8 * kol_bulocheck
	print('%.3f' % cena)


from math import ceil
t = input()
(H, D, C, N) = map(int, input().split())
k = C * ceil(H / N)
if int(t[:2]) >= 20:
	print(C * ceil(H / N) * 80 / 100)
elif t[0] == '0' and t[3] == '0':
	l = int(t[1])
	l1 = int(t[4])
	if l1 == 0:
		l1 = 60
	else:
		l = l + 1
	l = ((20 - l) * 60 + (60 - l1)) * D
	k1 = C * ceil((H + l) / N) * 80 / 100
	if k > k1:
		print(k1)
	else:
		print(k)
elif int(t[:2]) < 20:
	if t[3] == '0' and int(t[0]) != 0:
		l = 20 - int(t[:2])
		l1 = int(t[4])
		if l1 == 0:
			l1 = 60
		else:
			l = 20 - int(t[:2]) - 1
		l = l * 60 * D + (60 - l1) * D
		k1 = C * ceil((H + l) / N) * 80 / 100
		if k > k1:
			print(k1)
		else:
			print(k)
	elif t[0] == '0' and int(t[3]) != 0:
		l1 = int(t[3:])
		l = 20 - int(t[1]) - 1
		l = l * 60 * D + (60 - l1) * D
		k1 = C * ceil((H + l) / N) * 80 / 100
		if k > k1:
			print(k1 / 1)
		else:
			print(k / 1)
	elif t[0] != '0' and t[3] != '0':
		l1 = int(t[3:])
		l = 20 - int(t[:2]) - 1
		l = l * 60 * D + (60 - l1) * D
		k1 = C * ceil((H + l) / N) * 80 / 100
		if k > k1:
			print(k1 / 1)
		else:
			print(k / 1)


import math
(hh, mm) = map(int, input().split())
(H, D, C, N) = map(int, input().split())
time = hh * 60 + mm
p = time * D
cost = C * math.ceil(H / N)
ans = 0
if hh < 20:
	remT = 20 * 60 - time
	newH = H + remT * D
	nCost = C * math.ceil(newH / N) * 0.8
	ans = min(nCost, cost)
else:
	ans = cost * 0.8
print(ans)


import math
(hour, minute) = [int(i) for i in input().split(' ')]
total_minute = hour * 60 + minute
(hungry, amount, cost, efficiency) = [int(i) for i in input().split()]
if total_minute > 1200:
	new_hungry = hungry
else:
	new_hungry = (20 * 60 - total_minute) * amount + hungry
cost_1 = 0.8 * cost * math.ceil(new_hungry / efficiency)
cost_0 = cost * math.ceil(hungry / efficiency)
result = min(cost_0, cost_1)
fraction = str(float(result - int(result)))
if len(fraction) < 6:
	fraction += '0' * (6 - len(fraction))
elif len(fraction) > 6:
	if int(fraction[6]) >= 5:
		fraction = str(float(fraction[:6]) + 0.0001)
	else:
		fraction = str(float(fraction[:6]))
print(str(int(result)) + fraction[1:])