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
anuragdw0710:
20230315 07:22:34
Memo can be done with hashing. 

r_aj1_23rj:
20220523 10:49:34
For C++ users=> Use while(cin>>n){} for taking the input, use map instead of arrays for memoization else you'll get an overflow. Use long long instead of int 

ive1010:
20220321 19:43:52
Java code to read the input


rz_ai:
20220113 21:31:36
Keep in mind the declaration of map must be outside the function 

rinku_2002:
20220111 07:37:19
when should we stop reading data?


levii_ackerman:
20210903 03:01:48
easy basic dp problem


x_sparrow_x:
20210903 02:03:34
AC in one Go


huangdachuan:
20210822 21:17:17
It has to be long long, int does not work, why is that for the same formula when we only do division operation? Last edit: 20210822 21:17:52 

dev_manus:
20210729 14:43:58
//just tell me whether this is right logic or I am wrong


the_art_maniac:
20210516 20:29:29
Reason for why arrays are not working: because using them will need a memory of 10^9 integers which is approx.. 10X times more than maximum limit , in maps memory is not wasted. 
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 