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
2017-09-26 23:04:04
How can I get the testcases? My solution shows wrong answer but I want to know which testcase would have failed.
2017-09-24 11:39:26
Very good problem for those who are learning dp. My first dp problem and also learned maps.
2017-09-17 04:55:19
I am getting NZEC Runtime Exception. It's running fine in Ideone. How to know for which kind of input it's getting runtime error? Where to get sample test cases in SPOJ?
2017-09-17 04:55:19
I am getting NZEC Runtime Exception. It's running fine in Ideone. How to know for which kind of input it's getting runtime error? Where to get sample test cases in SPOJ?
2017-09-16 07:33:49
AC in one go !
2017-09-08 15:46:50
basic dp problem. Just take integer on coin as state of dp and use long long and vectors.AC in 4th go...
2017-09-06 21:35:28
if any one having problem with test cases than look at this
n can be divided into n/2,n/3,n/4
and these new coin can further divide and so on

Last edit: 2017-09-06 21:36:10
2017-09-06 14:35:08
At first, solved it using dp only. But when i saw a comment that , 1e9 cannot be stored in an array , then has to use both recursion and dp. In one go, AC.
2017-08-27 08:25:54
First recursive solution that i have written.....
2017-08-23 14:43:11 Sebastian Ceronik
Silly me. tried to use int. switched to long and AC.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.