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.
hide comments
little_finger:
20180615 09:28:09
Do we know the no of test cases? 

vgupta1127:
20180604 07:38:31
how do i take variable inputs in java??? Because the question does not specify the no of test cases? 

alwerty:
20180602 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? 

thunderbird18:
20180601 06:17:07
nice dp problem,be careful with input and size of array in dp. 

caro_linda2018:
20180528 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!! 

akash13s:
20180524 13:49:16
dp array,and recursion for n>1000000 

ayushtopper:
20180520 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?? 

ankitk2909:
20180516 12:44:43
watch out for the test case for 0 if your program is working otherwise and you are getting nzec runtime error 

nitish235:
20180509 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..


abualy:
20180313 11:17:06
recursion, and memory array, solved with GO 
Added by:  Tomek Czajka 
Date:  20050503 
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 