Soul Escape from Rough Blocks
Time limit1sMemory limit1024 MB
Given N blocks in a row, repeatedly remove blocks from chains of length 3 or more, keeping the new chains as long as possible. Find the maximum blocks removed for N up to 1e18.
Problem
One night a devil appeared at Daegu Science High School and trapped one student's soul in each of the blocks. The blocks are arranged in a row, and adjacent blocks are linked by a chain. Starting from some block and repeatedly moving to a linked block, the set of blocks you can reach is called a chain, and the number of blocks in a chain is its length. At the start, all blocks form one chain of length .
Ian supports quantitative utilitarianism and wants to free as many souls as possible. He repeats the following process until no chain has length or more. Removing a block also removes every link directly attached to that block.
- Pick a chain with length or more.
- If the length of is or less, remove one block. Otherwise, remove two non-adjacent blocks. A removed block must satisfy these conditions:
- The block must have two links attached to it. In other words, a block at either end of the chain cannot be removed.
- After the removal, is no longer a chain, and or new chains are formed. The minimum length among the new chains should be as large as possible.
Find the maximum number of blocks Ian can remove.
Input
The first line contains the number of blocks .
Output
Print the maximum number of blocks Ian can remove as a single integer.
Constraints
is an integer.