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
maradona: 2011-12-11 03:50:03

zzz...
I've got AC for this problem. And I want to recommend to everybody that use PASCAL to solve this problem. That's you should use "While not seekeof do" to stop the program. "While not eof do" don't give right answer!!!

jayesh hathila: 2011-09-18 09:34:27

stopping cindition of input??
and the output for 1000000000 i got 10833333

Ivan Sto¹iæ: 2011-08-27 01:02:39

If you are getting WA via c++ : Try loading with "%ld " (with a blank). Worked for me :)

Jason: 2011-08-14 15:56:16

help!! same answer 4243218150 for 1000000000 but still wrong answer

well, I changed my condition from n <= 11 to n <= n / 2 + n / 3 + n / 4 and got an AC

Last edit: 2011-08-14 15:57:33
hibernating: 2011-08-14 07:07:33

can anybdy tell me the stopping input condition????

deepak: 2011-08-07 18:30:05

plz tell me why prog# 5481162 wrong?
I have checked every possible test case ... plz reply...

jat: 2011-07-28 20:12:01

if n=1 000 000 000.......than answer is 1083333333
?

Santiago Palacio: 2011-06-17 06:44:11

@impulse: You're welcome ;)

impulse: 2011-06-16 11:23:31

geez, i got tle 3 times and now AC just because while (scanf()!=EOF)..., thank for @Santiago Palacio comment..


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