This page is still under construction.

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

Negative Base

Time limit2sMemory limit512 MB

Summary
Find the integer of least absolute value whose negabinary (base -2) representation contains at least k consecutive zeroes, breaking ties by shortest representation.
Level

Medium6 of 10

Topics
Math, Bit manipulation, Brute force, Implementation
Solved
No attempts yet

Problem

The binary positional numeral system works as follows. Writing a nonnegative integer xx as a string "x_k…x_2x_1x_0x\_k \ldots x\_2 x\_1 x\_0" of zeroes and ones means x=x_k⋅2k+…+x_2⋅22+x_1⋅21+x_0⋅20x = x\_k \cdot 2^k + \ldots + x\_2 \cdot 2^2 + x\_1 \cdot 2^1 + x\_0 \cdot 2^0. Leading zeroes are omitted, so x_k=1x\_k = 1, except when x=0x = 0, which is written as "00".

The negabinary notation works in a similar way. Writing a number xx as a string "x_k…x_2x_1x_0x\_k \ldots x\_2 x\_1 x\_0" of zeroes and ones means x=x_k⋅(−2)k+…+x_2⋅(−2)2+x_1⋅(−2)1+x_0⋅(−2)0x = x\_k \cdot (-2)^k + \ldots + x\_2 \cdot (-2)^2 + x\_1 \cdot (-2)^1 + x\_0 \cdot (-2)^0. Leading zeroes are omitted here as well, so x_k=1x\_k = 1, except when x=0x = 0, which is written as "00". This notation has a unique representation for every integer, not only for nonnegative integers.

Negabinary notation of the numbers from −7-7 to 88:

−7-7100110011111
−6-61110111022110110
−5-51111111133111111
−4-41100110044100100
−3-31101110155101101
−2-21010661101011010
−1-11111771101111011
0000881100011000

Given an integer kk, find a number whose negabinary representation contains at least kk consecutive zeroes. Among such numbers, find the one with the least absolute value. If several answers remain, pick the one with the shortest negabinary representation.

Input

The first line of input contains an integer kk (1≤k≤301 \le k \le 30).

Output

Print one integer: the answer to the problem.

Examples1

  1. Example 1

    Input
    2
    
    Expected output
    4