This page is still under construction.

Parts of this page are still being built. What you see may change.

Binary Knockout

Time limit1sMemory limit128 MB

Summary
A coin game on a line: each coin may double its position or move one step right; the player unable to move loses. Find the k-th value of n where the second player wins.
Level

Hard9 of 10

Topics
Game theory, Math, Bit manipulation
Solved
No attempts yet

Problem

Two players play a game called binary knockout. It is played on a board of nn fields numbered from 11 to nn. At the start every field holds exactly one pawn. The players move alternately.

A single move works as follows: pick a pawn on some field ii and move it to field 2ki2^k i for any integer k≥1k \ge 1, as long as that field exists (that is, 2ki≤n2^k i \le n). If the destination field already held a pawn, the two pawns knock each other out and both are removed from the board.

A player who cannot make any move on their turn loses.

The first player moves first and the second player moves second. By choosing the board size nn carefully, the second player can be given a guaranteed winning strategy; this happens, for example, for boards of size 11, 1010, and 1111. List every board size on which the second player has a winning strategy in increasing order, and report the kk-th of them.

Input

The only line of input contains one integer kk (1≤k≤1 000 000 0001 \le k \le 1\,000\,000\,000).

Output

Output a single integer: the kk-th smallest board size on which the second player has a winning strategy.

Examples4

  1. Example 1

    Input
    2
    
    Expected output
    10
    
  2. Example 2

    Input
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    
    Expected output
    11
    
  4. Example 4

    Input
    4
    
    Expected output
    34