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
Shubham Singh: 2014-06-29 17:16:41

What is meant by rounding the number??

code_do: 2014-06-27 21:37:35

@Tomek I am getting SIGABRT error in this code.Please help me with this code
<snip>

Last edit: 2022-08-09 22:49:19
Abhijeet Dubey: 2014-06-21 22:21:24

silly mistake in taking input caused me 6 NZEC errors...finally accepted... my first DP problem...

Last edit: 2014-06-21 22:24:39
AnilKumar: 2014-06-20 20:30:37

Getting segmentation fault if n = 10^9
till n = 10^8 its working fine...Any Suggestions???
P.S : coded in C

AnilKumar: 2014-06-20 20:18:52

@Gireek for n=999 ans - 1370

LUCIFER: 2014-06-20 20:08:40

please tell the answer for n=999

L: 2014-06-14 05:23:52

First DP... AC in first attempt!!!!
time =0.00sec mem 2.8MB
.....

Sumit Kushwaha: 2014-06-01 16:04:10

Dont worry about no of inputs. Just take a single input produce output. Repeat!

Sumit Kushwaha: 2014-05-31 13:33:57

How many inputs we need to take?

pvkcse: 2014-05-17 22:00:43

first program in c++ here...Got AC...


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