This page is still under construction.

Parts of this page are still being built. What you see may change.

Find the missing rank

Time limit2sMemory limit32 MB

Summary
Count score assignments within given ranges where no person receives rank R under tied ranking.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Prefix sum
Solved
No attempts yet

Problem

NN people take a mock exam whose maximum score is MM. Keunwoo roughly knows how strong they are, so he expects person kk to score at least AkA_k and at most BkB_k.

The exam is graded on a curve, so once it is over every person gets a rank between 11 and NN. A person's rank is the number of people with a strictly higher score, plus 11.

If N=5N=5 and M=10M=10 and the five people score 6, 5, 3, 9 and 5, their ranks are 2, 3, 5, 1 and 3 in that order. Because of the tie, nobody gets rank 4.

For his favourite number RR, Keunwoo wants to know how many outcomes leave rank RR empty. An outcome gives every person one score inside their own range, and two outcomes are different if at least one person's score is different.

Input

The first line contains the number of people NN and the maximum score MM. Each of the next NN lines contains the score range AkA_k and BkB_k of person kk. The last line contains Keunwoo's favourite number RR.

1≤N≤2501 \le N \le 250, 1≤M≤4001 \le M \le 400, 0≤Ak≤Bk≤M0 \le A_k \le B_k \le M, 1≤R≤N1 \le R \le N

Output

Print the number of outcomes in which nobody gets rank RR, modulo 1,000,000,007 (109+710^9+7).

Hint

Take N=4N=4, M=6M=6, the four ranges 1 to 3, 2 to 4, 3 to 5 and 4 to 6, and R=4R=4. Splitting by the scores of people 1, 2 and 3, the outcomes without a rank 4 are:

  • people 1 and 2 score 2: 9 outcomes
  • people 1 and 2 score 3 and person 3 scores at least 4: 6 outcomes
  • people 1 and 3 score 3 and person 2 scores 4: 3 outcomes
  • people 1, 2 and 3 all score 3: 3 outcomes

So 21 outcomes leave rank 4 empty.

Examples3

  1. Example 1

    Input
    4 6
    1 3
    2 4
    3 5
    4 6
    4
    
    Expected output
    21
    
  2. Example 2

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

    Input
    5 10
    3 3
    3 3
    3 3
    3 3
    3 3
    2
    
    Expected output
    1