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
spd123: 2018-11-27 14:31:52

Can someone please explain me the question?

baby_doll: 2018-11-21 22:45:43

Instead of array use dynamic array .
like
instead of this - int ar[1000000000] use this
long long *ar=new long long[1000000000];

And you can use map also but if someone is comfortable with array right now than use dynamic array.

Datta Sai Krishna: 2018-11-09 19:05:31

Used a set for dp... The Solution got Accepted :)

midoriya: 2018-10-24 19:55:58

AC in one go!!!!

jllew: 2018-10-14 22:29:03

consider int overflow for big input

adipat: 2018-10-11 19:50:29

Classic DP problem. If you're using C++, consider using vector, it has a larger capacity so you can pre-compute more values. I used bottom up DP. You can't compute upto 10^9 values because it's too slow but you can definitely compute upto 10^8 without any considerable loss in speed.

suryacodes: 2018-10-10 18:24:36

And it said accepted !!

harry_shit: 2018-09-19 16:19:35

real happiness is getting AC. :)

anant6025: 2018-09-13 22:33:49

Wohoo finally!
First DP problem AC

v_ns: 2018-09-09 17:53:01

Very interesting problem, you can't store values upto 10^9 in array, think of using DP till values you can precompute, then use the old recursion technique.


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