IntermediateSimulation & Finance25 points

Months until the savings goal

A young engineer in Toronto saves for a house deposit. She starts with some money, adds a fixed deposit at the start of every month, and the bank pays monthly interest on the balance after the deposit. She wants to know how many months until she reaches her goal.

Rules for each month, using the decimal module: add the deposit to the balance, then interest = balance times annual / 1200, rounded to cents with halves up, and add the interest to the balance. After each month check whether the balance has reached the goal (balance greater than or equal to goal). If the starting balance already reaches the goal, the answer is 0 months. Give up after 1200 months.

Task: read four lines: starting balance, monthly deposit, annual interest rate in percent, and goal. Print Months: N and then Balance: B (2 decimals) for the first month in which the goal is reached. If the goal is not reached within 1200 months print only UNREACHABLE.

Sample tests

Input

5000
400
4.5
30000

Expected output

Months: 54
Balance: 30102.51

Input

0
250
0
1000

Expected output

Months: 4
Balance: 1000.00

Your answer is also checked against 4 hidden tests.