module mod_grouping
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: f(0:1000), invf(0:1000)
contains
  subroutine init(n)
    implicit none
    integer, intent(in) :: n
    integer :: i
    f = 0_8
    invf = 0_8
    f(0) = 1_8
    invf(0) = 1_8
    do i = 1, n
      f(i) = mod(f(i-1)*int(i,8),md)
      invf(i) = inv(f(i))
    end do
    return
  end subroutine init
  integer(8) function perm(n,k)
    implicit none
    integer, intent(in) :: n, k
    perm = 0_8
    if (n.lt.0.or.k.gt.n) return
    perm = mod(f(n)*invf(n-k),md)
    return
  end function perm
  function inv(n) result(y)
    implicit none
    integer(8), intent(in) :: n
    integer(8) :: a, b, x, y, t, q
    a = mod(n,md)
    b = md
    x = 0
    y = 1
    do while(b.ne.0_8)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    do while (y.lt.0_8)
      y = y+md
    end do
    y = mod(y,md)
    return
  end function inv
  recursive function pow(a,b) result(r)
    implicit none
    integer(8), intent(in) :: a, b
    integer(8) :: r
    r = 1_8
    if (b.eq.0_8) return
    if (mod(b,2_8).eq.0_8) then
      r = pow(a,b/2_8)
      r = mod(r*r,md)
      return
    end if
    r = mod(a*pow(a,b-1_8),md)
    return
  end function pow
end module mod_grouping
program grouping
  use mod_grouping
  implicit none
  integer :: n, a, b, c, d, i, j, k
  integer(8) :: x, y, dp(0:1000,0:1000)
  read(*,*) n, a, b, c, d
  call init(n)
  dp = 0_8
  do i = 0, n
    dp(i,0) = 1_8
  end do
  do i = a, b
    do j = 1, n
      dp(i,j) = mod(dp(i-1,j)*perm(n-j,0),md)
      do k = c, d
        if (j-i*k.lt.0_8) exit
        x = mod(dp(i-1,j-i*k)*perm(n-j+i*k,i*k),md)
        y = mod(inv(pow(f(i),int(k,8)))*invf(k),md)
        dp(i,j) = mod(dp(i,j)+mod(x*y,md),md)
      end do
    end do
  end do
  write(*,'(i0)') dp(b,n)
  stop
end program grouping