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
2015-06-21 12:00:35 Rohit
I am getting time limit exceed .
This is my code:
<snip>
Please help


Last edit: 2022-08-09 22:49:09
2015-06-19 13:40:42
best question till now!!!!
2015-06-14 19:49:06 mohit
very good problem.. Beginners DP + Map
2015-06-08 13:24:13
since there are only few test cases dont perform bottom up memoization
2015-06-03 11:50:08
2nd DP....Learnt Maps ,feof ... Super tutorial problem :)
2015-05-31 21:27:16 Aman Agarwal
Good question for dp beginners(me) :P
mapping+dp+memoization paves the way
2015-05-31 15:55:14 :.Mohib.:
Greate confidence boost after this.... ;)
2015-05-26 09:27:21 Harsh Vardhan Ladha
DP :D Python dictionary memoization :D !!
2015-05-25 08:14:20 artha penn
for C++,
include stdio.h and use -> while(scanf("%d",&n)!=EOF) <- for testcases

you can use just DP (without maps) for correct but inefficient solutions
2015-05-20 13:56:29 SangKuan
check the test end,cost me too many times.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.