14. Toggle Bits After the MSB

Difficulty: easy · Bit Manipulation

Problem

Joseph is studying digital logic. His assignment: take a positive integer `N`, write it in binary, and toggle (flip) every bit from the most significant set bit down to the least significant bit, including the most significant bit itself. Print the value of the resulting binary number as a decimal integer. For example, `10` is `1010` in binary; toggling every bit gives `0101`, which is `5`.

Input

A single line containing the integer `N`.

Output

Print the decimal value after toggling.

Example 1

Input:
10
Output:
5

Explanation: 10 = 1010 in binary; flipping all four bits gives 0101 = 5.

Example 2

Input:
5
Output:
2

Explanation: 5 = 101; flipping gives 010 = 2.

Constraints

- 1 <= N <= 10^9

Solutions are judged against 2 sample and 11 hidden tests. Sign in to solve it · All problems