Run Walk Run!

0

0 votes
Medium
Problem

A person covers N metres daily on foot as part of his fitness plan. He can cover a single metre by walking or running. His energy level decreases by 1 unit after running a single metre, and increases by 1 unit after walking a single metre. Energy level should always remain non-negative.

One fine day he starts wondering that in how many differnt ways he can cover the N metres if his initial energy level is E units. Can you find this answer for him? Since the answer can be very large, output it modulo 109+7.

NOTE:

  • He can complete each single metre either by running or walking, but not both.
  • His energy level should remain non-negative even after completing all N metres.
  • Two ways are different if there exists at least one metre such that he is walking this metre in one way and running this metre in the other.

INPUT FORMAT

The only line of input contains two space separated integers N and E, the number of metres he has to cover and his initial energy level.

CONSTRAINTS

  • 1 ≤ ≤ 105
  • 0 ≤ ≤ 105

OUTPUT FORMAT

Output a single integer, the answer to his question modulo 109+7.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

He has to cover 3 metres and has an initial energy level of 1 unit. The ways he can do this are -

  1. W W W
  2. W W R
  3. W R W
  4. W R R
  5. R W W
  6. R W R

Note that, R R W and R R R are not valid as in both the ways, his energy level becomes negative after completing 2 metres.

Editor Image

?