#ARC067C. [ARC067E] Grouping

[ARC067E] Grouping

Score : 600600 points

Problem Statement

There are NN people, conveniently numbered 11 through NN. We want to divide them into some number of groups, under the following two conditions:

  • Every group contains between AA and BB people, inclusive.
  • Let FiF_i be the number of the groups containing exactly ii people. Then, for all ii, either Fi=0F_i=0 or CFiDC \leq F_i \leq D holds.

Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 109+710^9+7.

Constraints

  • 1N1031 \leq N \leq 10^3
  • 1ABN1 \leq A \leq B \leq N
  • 1CDN1 \leq C \leq D \leq N

Input

The input is given from Standard Input in the following format:

NN AA BB CC DD

Output

Print the number of ways to divide the people into groups under the conditions, modulo 109+710^9+7.

3 1 3 1 2
4

There are four ways to divide the people:

  • (1,2),(3)(1,2),(3)
  • (1,3),(2)(1,3),(2)
  • (2,3),(1)(2,3),(1)
  • (1,2,3)(1,2,3)

The following way to divide the people does not count: (1),(2),(3)(1),(2),(3). This is because it only satisfies the first condition and not the second.

7 2 3 1 3
105

The only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people. There are 105105 such ways.

1000 1 1000 1 1000
465231251
10 3 4 2 5
0

The answer can be 00.