Bit sorting
Hard
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
On the set of nonnegative integers, we introduce the following order relation: we assume that the number of A is less than the number of B in two cases:
When a binary number in units of A is less than B.
When a binary number with A as many units as in B, and A less than B in the usual sense.
Now sort ascending set of all integers from 0 to n inclusive, using this new order relation. Your task is to find how many will be in position k. Numbering of positions is carried out with the unit.
Input
The first line contains the integers n and k (0 ≤ n ≤ 10^16
, 1 ≤ k ≤ n + 1).
Output
Print the k-th number in the sorted sequence.
Examples
Input #1
Answer #1
Note
Numbers from 0 to 10 will be sorted in the next way: 0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 7.
Submissions 63
Acceptance rate 8%