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
2018-06-02 04:15:02
First time on this site, how are you supposed to handle the input if you don't know how long it is? should I look for EOF?
2018-06-01 06:17:07
nice dp problem,be careful with input and size of array in dp.
2018-05-28 04:50:47
Getting SIGABRT, problably because I don't know how to stop reading the input... Just made "while (cin>>n)". Does someone know how can I fix it? Thank you a lot!!
2018-05-24 13:49:16
dp array,and recursion for n>1000000
2018-05-20 22:19:09
How map<int, long long> works fine here for input 10^9? Isn't 10^9 very large to fit into int??
2018-05-16 12:44:43
watch out for the test case for 0 if your program is working otherwise and you are getting nzec runtime error
2018-05-09 12:54:22
u can not make a dp array of size 10^9 so make dp array of size 10^6 , precompute all values of dp array..
Then make recursive call when n >10^6 with base condition n<=10^6(because you have already computed all results).
2018-03-13 11:17:06 abualy
recursion, and memory array, solved with GO
2018-03-10 19:26:23
@pavanjupalli precompute some cases, see https://blog.binaryspaceship.com/2018/spoj-coins-solution/
2018-03-02 16:39:14
it shows time limit exceeded problem , can anyone here help me
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.