COINS - Bytelandian gold coins

In Byteland they have a very strange monetary system.

Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit).

You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins.

You have one gold coin. What is the maximum amount of American dollars you can get for it?

Input

The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.

Output

For each test case output a single line, containing the maximum amount of American dollars you can make.

Example

Input:
12
2

Output:
13
2

You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. It is better just to change the 2 coin directly into $2.


Added by:Tomek Czajka
Date:2005-05-03
Time limit:9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:Purdue Programming Contest Training

hide comments
2015-11-02 14:16:39 sumit suthar
Nice problem.Learn a lot :)
2015-10-27 14:54:13 dig
easy dp... learnt new data structure...
be careful with the how to take the input values (how many inputs).
2015-10-25 20:35:49
Right! Watch out for overflows.
2015-10-19 23:50:05
hmm........dp
I'm not used that much to it but I'm doing a "little progress"
In fact I did only one dp from the time I'm engaged in programmationXDXD
hmmmmm....time exceeded
OMG...a silly mistake....flooking forward to submit
Whattttttt.......9s and I get a time exceeded answer

Last edit: 2015-10-20 00:42:21
2015-10-18 13:33:41 rishabh
FIRST DP PROBLEM EVER!!!!
2015-10-10 04:27:55
in Java.....
you can try using scanner class.......
but do remember that scanner class can give the NZEC error.....
2015-10-05 06:27:15
how to take inputs in java?
2015-10-01 20:01:06 ISHPREET
First dp ... enjoyed a lot ...:)

Last edit: 2015-10-01 20:01:48
2015-09-30 19:22:48
hufffff!! finally!! got ac
used dp first time :)
2015-09-30 08:51:40 Howard Wolowitz
Use map @senshiya
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.