Under construction

Still being built. Things may change

Slot Machines

Interview

Time limit1sMemory limit128 MB

Summary
Simulate a gambler who cycles through three slot machines with fixed payout periods and stops when she runs out of quarters, and report the total number of plays.
Level

Easy3 of 10

Topics
Simulation, Implementation, Math
Solved
No attempts yet

Problem

Martha takes a jar of quarters to the casino, intending to get rich. She plays three machines in turn — machine 11, then 22, then 33, then back to 11, and so on. Unknown to her, the machines are entirely predictable. Each play costs one quarter.

  • Machine 11 pays 3030 quarters on every 35th35^{\text{th}} time it is played.
  • Machine 22 pays 6060 quarters on every 100th100^{\text{th}} time it is played.
  • Machine 33 pays 99 quarters on every 10th10^{\text{th}} time it is played.

Whenever a machine pays out, its play counter resets to 00. Martha keeps playing as long as she has at least one quarter, and goes broke when the jar is empty.

Input

The input consists of four integers separated by spaces or newlines.

  • The first integer is the number of quarters QQ in Martha's jar (1≤Q<10001 \le Q < 1000).
  • The next three integers are how many times machine 11, machine 22, and machine 33 have each been played since they last paid out.

Output

Print a single line with the total number of times Martha plays before going broke:

Martha plays N times before going broke.

where NN is the total number of plays.

Examples4

  1. Example 1

    Input
    48
    3
    10
    4
    
    Expected output
    Martha plays 66 times before going broke.
    
  2. Example 2

    Input
    1
    0
    0
    0
    
    Expected output
    Martha plays 1 times before going broke.
    
  3. Example 3

    Input
    5
    0
    0
    0
    
    Expected output
    Martha plays 5 times before going broke.
    
  4. Example 4

    Input
    2
    0
    0
    0
    
    Expected output
    Martha plays 2 times before going broke.