In the lift
Practice
3.3 (7 votes)
Basic math
Easy Medium
Mathematics
Mathematics
Problem
91% Success 1345 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are \(n\) floors in a building and \(n\) buttons in a lift. The floors are indexed from \(1\) to \(n\).

You live in the \(k^{th}\) floor. You want to stay alone in the lift. This is not possible because many people live in the building.

At the first floor, many people get into the lift and press the button for their destination floor. Assume that the buttons that are pressed are \(b_1,b_2,b_3...b_m\). Note that the \(k^{th}\) floor button is always pressed because you are still in the lift.

The happiness value is defined as follows:

  • If a button represents the floor number that is greater than or equal to \(k\) is pressed and no button that contains a number that is strictly smaller than \(k\) is pressed, then the value of the button is \(k\).

  • If no button contains a number that is strictly greater than \(k\), then its value is \(k-x\) where \(x\) is the second-largest number on the buttons that are pressed.

  • Otherwise the value is \(0\).

Determine the total happiness value of every situations modulo \(10^9+7\). Each button can be pressed or not be pressed.

Input Format

The first line contains two integers \(n, k\) (\(1\leq n,k\leq10^9\))

Output Format

Print the answer modulo \(10^9+7\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
39 votes
Tags:
MathematicsOpenApprovedEasy-MediumMathamatics
Points:30
15 votes
Tags:
MathematicsEasy-MediumOpenApprovedGreedy algorithmMathamatics
Points:30
29 votes
Tags:
MathematicsEasy-MediumMathematicsMathamatics