In the lift

3.3

7 votes
Basic Math, Easy-Medium, Mathematics, Mathematics
Problem

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 kth 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 b1,b2,b3...bm. Note that the kth 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 kx 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 109+7. Each button can be pressed or not be pressed.

Input Format

The first line contains two integers n,k (1n,k109)

Output Format

Print the answer modulo 109+7.

Sample Input
3 2
Sample Output
5
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

If 1 pressed 2 pressed 3 pressed, the happiness is 0

If 1 pressed 2 pressed 3 not pressed, the happiness is 1

If 1 not pressed 2 pressed 3 pressed, the happiness is 2

If 1 not pressed 2 pressed 3 not pressed, the happiness is 2

 

Editor Image

?