Under construction

Still being built. Things may change

Heap Structure

Time limit3sMemory limit1024 MB

Summary
Given a min-heap of n nodes, count how many nodes can hold the k-th smallest element.
Level

Medium6 of 10

Topics
Tree, Binary search, Math
Solved
No attempts yet

Problem

A minimum binary heap, often called a min-heap, is a binary tree-based data structure widely used in computer science. It has two main properties:

  1. Heap property: For any node, its value is less than or equal to the values of its children. So the minimum value in the heap is always at the root. The smallest element is always at the top.
  2. Binary tree structure: A min-heap is usually a complete binary tree. Every level is full except possibly the last, and the last level is filled from left to right. This structure lets min-heaps be implemented efficiently with arrays.

Min-heaps are often used to implement priority queues, which maintain a collection of elements with priorities. Because the minimum is kept at the root, a min-heap can retrieve and remove the element with the highest priority (lowest value) in logarithmic time. Removing any other element may take linear time.

Hank recently learned about min-heaps. He wonders how many nodes can hold the k-th smallest element in a min-heap of n nodes. Write a program to help him.

Input

The input contains two space-separated positive integers nn and kk.

Output

Output the number of nodes that can hold the kk-th smallest element in a min-heap of nn nodes.

Constraints

1≤k≤n≤10181≤k≤n≤10^{18}

Hint

Assume that all elements are distinct.

Examples2

  1. Example 1

    Input
    100 1
    
    Expected output
    1
    
  2. Example 2

    Input
    12 3
    
    Expected output
    6