Andrew Needs Help

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 0.5s
Memory limit: 256M

Author:
Problem type

Andrew is planning something and he needs your help. Andrew needs your help to determine how many permutations of the first N positive integers are good.

A permutation p is good if there exists an index i (1iN1) such that |pi+1pi|=D.

Since the answer might be very large, output it modulo 109+7.

Constraints

2N106
N2D<2N

Subtask 1 [10%]

2N8

Subtask 2 [30%]

2N2000

Subtask 3 [60%]

No additional constraints.

Input Specification

The first and only line contains N (2N106) and D (N2D<2N).

Output Specification

Output the number of good permutations, modulo 109+7.

Sample Input 1

Copy
3 2

Sample Output 1

Copy
4

Explanation

The good permutations are {1,3,2}, {2,1,3}, {2,3,1}, and {3,1,2}.

Sample Input 2

Copy
838383 833883

Sample Output 2

Copy
711361423

Comments

There are no comments at the moment.