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
sumit suthar: 2015-11-02 14:16:39

Nice problem.Learn a lot :)

dig: 2015-10-27 14:54:13

easy dp... learnt new data structure...
be careful with the how to take the input values (how many inputs).

deeh: 2015-10-25 20:35:49

Right! Watch out for overflows.

garmel: 2015-10-19 23:50:05

hmm........dp
I'm not used that much to it but I'm doing a "little progress"
In fact I did only one dp from the time I'm engaged in programmationXDXD
hmmmmm....time exceeded
OMG...a silly mistake....flooking forward to submit
Whattttttt.......9s and I get a time exceeded answer

Last edit: 2015-10-20 00:42:21
rishabh: 2015-10-18 13:33:41

FIRST DP PROBLEM EVER!!!!

chinmoy17_c: 2015-10-10 04:27:55

in Java.....
you can try using scanner class.......
but do remember that scanner class can give the NZEC error.....

spk: 2015-10-05 06:27:15

how to take inputs in java?

ISHPREET: 2015-10-01 20:01:06

First dp ... enjoyed a lot ...:)

Last edit: 2015-10-01 20:01:48
nonushikhar: 2015-09-30 19:22:48

hufffff!! finally!! got ac
used dp first time :)

Howard Wolowitz: 2015-09-30 08:51:40

Use map @senshiya


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