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
hitesh87: 2017-09-24 11:39:26

Very good problem for those who are learning dp. My first dp problem and also learned maps.

debarati18: 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?

debarati18: 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?

metahost: 2017-09-16 07:33:49

AC in one go !

vishesh197: 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...

s_agrawal_1997: 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
kejriwal_pk: 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.

stranger77: 2017-08-27 08:25:54

First recursive solution that i have written.....

Sebastian Ceronik: 2017-08-23 14:43:11

Silly me. tried to use int. switched to long and AC.

knive35: 2017-08-17 12:17:51

"not more than 10" costs me 5 WA's


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