Under construction

Still being built. Things may change

Soul Escape from Rough Blocks

Time limit1sMemory limit1024 MB

Summary
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.
Level

Medium5 of 10

Topics
Math, Greedy, Recursion
Solved
No attempts yet

Problem

One night a devil appeared at Daegu Science High School and trapped one student's soul in each of the NN 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 NN blocks form one chain of length NN.

Ian supports quantitative utilitarianism and wants to free as many souls as possible. He repeats the following process until no chain has length 33 or more. Removing a block also removes every link directly attached to that block.

  • Pick a chain CC with length 33 or more.
  • If the length of CC is 44 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, CC is no longer a chain, and 22 or 33 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 NN.

Output

Print the maximum number of blocks Ian can remove as a single integer.

Constraints

1≤N≤10181 \le N \le 10^{18} is an integer.

Examples1

  1. Example 1

    Input
    10
    
    Expected output
    4