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
sayedathar11: 2016-06-16 07:50:12

very nice problem teaches you dp and map datastructures and also a new way of input ac in one go :)

code1monkey1: 2016-06-12 10:14:41

map is the saviour
1st dp problem , woohoo

macbox: 2016-06-08 06:50:45

Easy Logic but need to use some tricks

top_gun007: 2016-06-05 13:08:00

learned something new..worth it

get_right_jr: 2016-06-02 19:34:19

AC!!!!
1st DP problem :)
It was amazing problem!
Use HashMap ;)

Last edit: 2016-06-02 20:15:05
blueranger: 2016-06-02 18:23:21

Time: 0.00, Memory: 3.3M, C++
AC in one go!!!!!!!!!! :)

Last edit: 2016-06-02 18:52:25
mayank220588: 2016-05-26 20:52:37

how to ensure of two inputs only?
means how to stop input ?

azam_9: 2016-05-24 15:58:55

WA using vector..AC using maps..dont knw y??

Umesh Kumar Singla: 2016-05-24 14:06:56

@vstepano Please correct the 4th test case to either 999 -> 1370 or 9999(mind the four 9's) -> 16615

rohit_sharma: 2016-05-24 14:05:55

Getting TLE for input > 10^8 on ideone... but it is taking 3 seconds on my local environment .. how is that possible ??? I thought time limit was 9 sec. Working with Java.


Never mind ... found the reason... i had i7 machine and they are using Intel Pentium G860 for running test cases. Difference between performance of two is too much.

Last edit: 2016-05-24 15:33:15

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