Bob is now so rich that he can sustain a respectable quality of life from his competition winnings (aka not rich at all). As Bob was resting between his competitions his mind wandered off to doing other things … with all of his money! Suddenly, he remembers his grandfather showing him the ins and outs of the stock market and decides to try "playing" for himself.
After some illegal insider trading business time passes, Bob has observed enough stock market fluctuations per second to draw up the function
— | |||
---|---|---|---|
… | |||
Note:
In other words, the next value
There are only two possible outcomes for an investment in the
Given some of Bob's initial investments, determine the amount of time it would take to reach equilibrium, or state the length of the cycle through which the value of the stock will loop.
Input Specification
The first line of the input contains a single integer
The next
It is guaranteed that Bob's money, and all amounts the
Output Specification
Your program should output
If Equilibrium: Bob's investment becomes $D after E second(s)!
, where
Otherwise, output Instability: Loop of length L encountered after M second(s)!
, where
Sample Input
3
288
730
876
Sample Output
Equilibrium: Bob's investment becomes $370 after 6 second(s)!
Equilibrium: Bob's investment becomes $370 after 1 second(s)!
Instability: Loop of length 2 encountered after 14 second(s)!
Explanation
The first case is really an extension of the second case, as shown after applying the function
The second case is reduced from
The third case eventually ends at a cycle of length two:
Comments