Slackline Adventure

Time limit2sMemory limit512 MB

Summary
Count unordered pairs of grid trees at distance in [L, R] whose line segment passes through no other tree, using visible lattice points and inclusion-exclusion over strip indices.
Level

Hard8 of 10

Topics
Math, Number theory, Combinatorics, Implementation
Solved
No attempts yet

Problem

Beltrano recently became interested in slackline. Slackline is a balance sport played on an elastic band stretched between two fixed points, which lets the practitioner walk and perform maneuvers on top of the band. During his vacation, all Beltrano wants to do is practice, so he went to a friend's farm, where there is a eucalyptus plantation.

The plantation is very well organized. The eucalyptus trees are arranged in N rows with M trees each. There is a one-meter gap between each row, and the trees in different rows are all perfectly aligned with a one-meter gap between them.

Beltrano will set up the slackline using two trees. When setting up the slackline, Beltrano does not like the distance between the two trees to be too small, since the best maneuvers require the band to be at least L meters long. It is also not possible to stretch the band too much, since it has a maximum length of R meters. Note that when the band is stretched between the two chosen trees, there cannot be any other tree on the line formed between them; otherwise it would not be possible to use the entire band for the maneuvers.

Beltrano would like to know in how many different ways it is possible to set up the slackline using the trees of the farm. Two ways are considered different if at least one of the trees where the band was tied is different.

Input

The input consists of a single line containing four integers, N, M, L, R, representing respectively the number of rows and columns of the plantation and the minimum and maximum lengths of the slackline (1 ≤ N, M ≤ 105; 1 ≤ L ≤ R ≤ 105).

Output

Your program must produce a single line with an integer representing in how many different ways the slackline can be set up. Since the result may be large, the answer must be this number modulo 109 + 7.

Examples3

  1. Example 1

    Input
    2 2 1 1
    
    Expected output
    4
    
  2. Example 2

    Input
    2 3 1 4
    
    Expected output
    13
    
  3. Example 3

    Input
    3 4 1 4
    
    Expected output
    49