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
dhia01: 2019-07-28 06:02:00

precompute 100 million number, the rest just use dp

triangle7201: 2019-07-23 01:38:48

For C++ users:
If you don't know how many inputs are there, use:
while(cin>>x) {}

Last edit: 2019-07-23 01:42:08
necrofool: 2019-07-19 18:39:33

Even the brute force recursive solution is getting accepted. Time limit is 9 freaking seconds, Lmao!

Last edit: 2019-07-19 18:39:47
rmcr714: 2019-07-16 10:40:29

guys for those who r unable to understand the problem and saying how come 1000000000 can be 4233... instead of 100000333.. some value. please read the problem carefully, say if u have 12 as input and u do 12/2 then 12/3 then 12/4 we get 6 ,3,4 respectively right ,now the point is to divide 6,3,4 into 3 parts like 6/2,6/3,6/4 same for 3 and 4 and see if the divisions are greater than 6,3,4 and return the max value. Its like a recursive thing and computing the same value again and again so its a dp problem ,try this approach and youll be able to see the difference in the answers who r doing it the wrong way. This msg was for those who didnt understand the problem clearly ,hope this helps someone ,thx

maximum_01: 2019-07-12 21:12:15

how to take input as we dont know how many inputs are there?

himmu_04: 2019-07-09 17:24:17

How to take input in python ??

am_venkat_2000: 2019-07-01 23:03:38

For Java users,

1) For the input, you could do the following:

Scanner x=new Scanner(System.in);
while(x.hasNextLong())
{
//body
}

2) If you are going to use Map, <Long, Long> works. No need for <Integer, BigInteger>.

vurise18: 2019-06-26 19:52:20

cant understand the question

cenation007: 2019-06-25 21:01:24

Easy peasy lemon squeezy
AC in one go :<)

puszek215: 2019-06-19 09:34:34

Python 3.5 solved with recursion and @memoize decorator.


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