This page is still under construction.

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

Hongjun's Intersection

Time limit2sMemory limit512 MB

Summary
Sum the lengths of the intersections of all k-subsets of given segments, modulo 1e9+7.
Level

Hard8 of 10

Topics
Sorting, Combinatorics, Prefix sum
Solved
No attempts yet

Problem

There are NN one dimensional segments on a horizontal line. Call the ii-th segment [Li,Ri][L_i, R_i] (Li≤RiL_i \le R_i). The length of a segment is f([Li,Ri])=Ri−Li+1f([L_i, R_i]) = R_i - L_i + 1, and the length of the empty set is f(∅)=0f(\varnothing) = 0.

You are given a positive integer kk with k≤Nk \le N. For every way of choosing kk distinct segments, add up the length of the intersection of the chosen segments:

∑1≤i1<i2<⋯<ik≤Nf([Li1,Ri1]∩[Li2,Ri2]∩⋯∩[Lik,Rik])\sum_{1 \le i_1 < i_2 < \cdots < i_k \le N} f\bigl([L_{i_1}, R_{i_1}] \cap [L_{i_2}, R_{i_2}] \cap \cdots \cap [L_{i_k}, R_{i_k}]\bigr)

Write a program that computes this sum.

The answer can be very large, so print it modulo 109+710^9 + 7.

Input

The first line contains NN and kk. (1≤k≤N≤200,0001 \le k \le N \le 200{,}000)

Each of the next NN lines contains two integers LiL_i and RiR_i describing the ii-th segment. (−109≤Li≤Ri≤109-10^9 \le L_i \le R_i \le 10^9)

Output

Print on one line the sum of the intersection lengths over every way of choosing kk distinct segments, modulo 109+710^9 + 7.

Hint

When the segments are [1,2][1, 2], [1,3][1, 3], [2,3][2, 3] and k=2k = 2, there are three ways to choose, and the intersection lengths are:

f([1,2]∩[1,3])=f([1,2])=2f([1,2] \cap [1,3]) = f([1,2]) = 2

f([1,2]∩[2,3])=f([2,2])=1f([1,2] \cap [2,3]) = f([2,2]) = 1

f([1,3]∩[2,3])=f([2,3])=2f([1,3] \cap [2,3]) = f([2,3]) = 2

So the answer is 2+1+2=52 + 1 + 2 = 5.

Examples3

  1. Example 1

    Input
    3 2
    1 2
    1 3
    2 3
    
    Expected output
    5
    
  2. Example 2

    Input
    3 2
    1 2
    5 6
    10 11
    
    Expected output
    0
    
  3. Example 3

    Input
    5 3
    0 4
    0 4
    0 4
    0 4
    0 4
    
    Expected output
    50