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
manvirag982:
20191025 11:22:39
hey guys pls help me


tarun_28:
20191024 07:14:54
Easy one. Thanks to @rmcr714 

jvictormv:
20191015 08:18:48
Be careful using int instead of long long int 

aman_atg:
20190916 10:43:50
ac in one go!! yeah!


emilio_cosy:
20190913 10:09:18
prefetch 10million coins' results, use this part as cache;


rockybuzz:
20190826 08:55:10
though only DP' is accepted ... 

siddharthvp:
20190816 18:25:31
Recursion with memoization 

mriow:
20190808 19:52:07
DP is not efficient here, because it is not needed to solve all previous subproblems (for n, we dont need all 1, 2, 3... n1 solutions).


addictd:
20190801 13:19:27
how to take input with javascript


dhia01:
20190728 06:02:00
precompute 100 million number, the rest just use dp 
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 