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
Howard Wolowitz: 2015-09-30 08:51:40

Use map @senshiya

senshiya: 2015-09-25 16:20:26



plz help me in prblm Bytelandian gold coins ....if i use recursion for every number its tle ..if i use arr of size 1000000000 its not possible...help me out

Mit: 2015-09-21 19:17:53

watch out for integer overflow :)

bunnycoder: 2015-09-09 14:44:34

May be the best problem for beginers.

Vipin: 2015-09-06 12:33:14

My First DP On Spoj.
Learned This
while(scanf("%d",&n)==1)

sri: 2015-09-06 09:26:57

first dp in spoj!
#dp

Jay: 2015-08-25 17:52:02

first dp !!

Shivam Singh: 2015-08-24 05:18:32

recursion with memoization would do the tricks, watch out for SIGSEVs

thearkguy: 2015-08-22 19:33:57

At first I cached 100000000 values, the toll on memory and time was enormous (0.31s, 385MBs) then I started decreasing the cache until I got an okay result (0.00s, 3.4MB). Haha good for me learning that you don't need to cache everything.

tarunsai: 2015-08-21 03:45:00

maps+memo :) easy one!!


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