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
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
supertramp_sid: 2016-05-23 09:34:55

Please check the data type you use. made a silly mistake by using int instead of long long.

partha2717: 2016-05-19 08:22:09

Silly mistake took 3 WA. :(

vstepano: 2016-05-18 08:56:36

Pay attention to the fact that the input doesn’t contain the number of test cases!!!

Here are some test data:
0 -> 0
15 ->15
33 -> 36
999 -> 16615
1000000000 -> 4243218150

satoruu: 2016-05-17 03:23:35

That was awesome!

jitendrakk: 2016-05-13 17:10:58

Oh.. It was presentation error not wrong answer.

jitendrakk: 2016-05-13 16:46:49

I need some tricky edge cases?


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 PERL 6 VB.net
Resource:Purdue Programming Contest Training