func_code_string: #include <bits/stdc++.h>   using namespace std;   using i64 = long long;   constexpr int MAX = 400010;   constexpr int MOD = 1000000007;   i64 fac[MAX], inv[MAX];   int l[MAX], r[MAX], x[MAX], cnt[MAX];   i64 ModPow(i64 a, i64 b, i64 p = MOD) {     i64 ret = 1;     for (a %= p; b; b >>= 1) {       if (b & 1) ret = ret * a % p;       a = a * a % p;     }     return ret;   }   inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); }   void Init() {     fac[0] = 1;     inv[0] = 1;     for (int i = 1; i < MAX; ++i) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = Inv(fac[i]);     }   }   inline i64 C(int n, int m) {     return n < m ? 0 : fac[n] * inv[m] % MOD * inv[n - m] % MOD;   }   i64 Solve(int n, int k) {     int m = 0;     for (int i = 0; i < n; ++i) {       l[i] <<= 1;       r[i] = ((r[i] << 1) | 1);       x[m++] = l[i];       x[m++] = r[i];     }     sort(x, x + m);     int a = x[0], b = x[m - 1];     x[m++] = a - 1;     x[m++] = b + 1;     sort(x, x + m);     m = unique(x, x + m) - x;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; ++i) {       int u = lower_bound(x, x + m, l[i]) - x;       int v = lower_bound(x, x + m, r[i]) - x;       ++cnt[u];       --cnt[v];     }     i64 ret = 0;     for (int i = 1; i < m - 1; ++i) {       cnt[i] += cnt[i - 1];       if (cnt[i] >= k) {         int u = ((x[i + 1] + 1) >> 1), v = ((x[i] + 1) >> 1);         int d = u - v;         i64 cur = C(cnt[i], k) * d % MOD;         ret = (ret + cur) % MOD;       }     }     return ret;   }   int main() {     Init();     int n, k;     while (~scanf( %d%d , &n, &k)) {       for (int i = 0; i < n; ++i) {         scanf( %d%d , &l[i], &r[i]);       }       printf( %d n , (int)Solve(n, k));     }     return 0;   }   