Average memory access time

A processor has an L1 cache, an L2 cache and main memory. Print the average memory access time:

AMAT = h1 + m1 × (h2 + m2 × T)

where h1 and h2 are the hit times, m1 and m2 the miss rates (m2 counts only the accesses that reach L2), and T the main memory time.

Input

One line: h1 m1 h2 m2 T (decimal numbers; the miss rates are from 0 to 1).

Output

The AMAT with 2 decimal places.

Examples

Example 1 · Input
1 0.05 10 0.2 100
Expected output
2.50
Example 2 · Input
2 0.1 20 0.5 200
Expected output
14.00

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Work from the bottom up: the time an L1 miss costs is the L2 hit time plus the L2 miss rate times the memory time.

Hint 2

AMAT = L1 hit time + L1 miss rate × that cost.

Solution

Show one correct solution (try it yourself first)
h1, m1, h2, m2, t = map(float, input().split())
print(f"{h1 + m1 * (h2 + m2 * t):.2f}")

Lesson: The memory hierarchy →