Find the missing rank

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

Hard8Dynamic programmingCombinatoricsPrefix sumNo attempts yetTime limit2sMemory limit32 MB

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.

1N2501 \le N \le 250, 1M4001 \le M \le 400, 0AkBkM0 \le A_k \le B_k \le M, 1RN1 \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.