Under construction

Still being built. Things may change

Time is of the Essence

Time limit2sMemory limit512 MB

Summary
Given a chain of unit conversions and an amount in the smallest unit, print a rounded answer in the largest unit and a rough answer in the top two units.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Do you know how long one million seconds is? How about one billion seconds? The exact answer to the first question is 11 days, 13 hours, 46 minutes and 40 seconds. That is accurate, but it is chopped much finer than anyone needs. A useful answer is "11 days, 14 hours", or just "12 days" after rounding. Three million inches works the same way: "47 miles", or "47 miles, 613 yards". This problem asks for those two rough answers for a given chain of units.

Input

The first line has this form.

n name_1 c_1 name_2 c_2 ... name_{n-1} c_{n-1} name_n

Each nameiname_i is the name of a unit, and each cic_i says how many units of type namei+1name_{i+1} fit in one unit of type nameiname_i. For example, a first line of 4 days 24 hours 60 minutes 60 seconds says that one day has 24 hours, one hour has 60 minutes and one minute has 60 seconds. nn is the number of unit names, and 2≤n≤102 \le n \le 10. Every name is an alphabetic string with no blanks and is already written in plural form. Print the given name as it is, whatever number stands next to it. Every cic_i is a positive integer, and the product c1c2⋯cn−1c_1 c_2 \cdots c_{n-1} is at most 101810^{18}.

The second line has the amount mm measured in the last unit namenname_n (1≤m≤20000000001 \le m \le 2000000000).

Output

Print two lines. Let P=c1c2⋯cn−1P = c_1 c_2 \cdots c_{n-1} be the number of namenname_n units in one name1name_1 unit, and let Q=P/c1Q = P / c_1 be the number of namenname_n units in one name2name_2 unit.

The first line holds m/Pm / P rounded to the nearest integer, a space, then name1name_1.

The second line holds ⌊m/P⌋\lfloor m / P \rfloor and name1name_1, then the leftover m−⌊m/P⌋⋅Pm - \lfloor m / P \rfloor \cdot P divided by QQ and rounded to the nearest integer, then name2name_2.

Rounding goes up whenever the fractional part is 0.50.5 or more. The second line does no carrying, so its second number is sometimes equal to c1c_1. Do not print thousands separators.

Examples4

  1. Example 1

    Input
    4 days 24 hours 60 minutes 60 seconds
    1000000
    
    Expected output
    12 days
    11 days 14 hours
    
  2. Example 2

    Input
    5 years 365 days 24 hours 60 minutes 60 seconds
    1000000000
    
    Expected output
    32 years
    31 years 259 days
    
  3. Example 3

    Input
    2 feet 12 inches
    11
    
    Expected output
    1 feet
    0 feet 11 inches
    
  4. Example 4

    Input
    4 jiffys 2 lambtailshakes 11 flashes 3 twinklings
    20902
    
    Expected output
    317 jiffys
    316 jiffys 1 lambtailshakes