This page is still under construction.

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

Base-2 Palindromes

Interview

Time limit1sMemory limit256 MB

Summary
Find the M-th positive integer whose binary representation reads the same forward and backward and print it in decimal.
Level

Medium5 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

A positive integer NN is a base-bb palindrome when the base-bb representation of NN reads the same forward and backward. For example, the decimal number 7 is a single digit in every base 8 or larger, so it is a palindrome in all of those bases. It is a palindrome in base 2 (111111) and in base 6 (1111) as well, but not in base 3 (2121), base 4 (1313), base 5 (1212), or base 7 (1010). Written in base 10 and sorted from smallest, the base-2 palindromes begin 1, 3, 5, 7.

Find the MM-th base-2 palindrome and print it in base 10.

Input

The first line contains one positive integer MM written in base 10. (1≤M≤500001 \le M \le 50000)

Output

Print the MM-th base-2 palindrome in base 10 on the first line.

Examples2

  1. Example 1

    Input
    1
    
    Expected output
    1
    
  2. Example 2

    Input
    3
    
    Expected output
    5