#include using namespace std; #define int long long // #define double long double #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORR(i, a, b) for(int i = (a); i > (b); --i) #define REP(i, n) for(int i = 0; i < (n); ++i) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOREACH(x, a) for(auto &(x) : (a)) #define VECCIN(x) \ for(auto &youso_ : (x)) cin >> youso_ #define bitcnt(x) __builtin_popcount(x) #define lbit(x) __builtin_ffsll(x) #define rbit(x) (64 - __builtin_clzll(x)) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() #define cinfast() cin.tie(0), ios::sync_with_stdio(false) #define PERM(c) \ sort(All(c)); \ for(bool cp = true; cp; cp = next_permutation(All(c))) #define COMB(n, k) \ for(ll bit = (1LL << k) - 1; bit < (1LL << n); bit = next_combination(bit)) #define PERM2(n, k) \ COMB(n, k) { \ vector sel; \ for(int bitindex = 0; bitindex < n; bitindex++) \ if(bit >> bitindex & 1) sel.emplace_back(bitindex); \ PERM(sel) { Printv(sel); } \ } #define MKORDER(n) \ vector od(n); \ iota(All(od), 0LL); template inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template inline void CIN(Head &&head, Tail &&... tail) { cin >> head; CIN(move(tail)...); } template inline void COUT(Head &&head) { cout << (head) << "\n"; } template inline void COUT(Head &&head, Tail &&... tail) { cout << (head) << " "; COUT(forward(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ long long __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template inline void eputs(T s) { cout << s << "\n"; exit(0); } template void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } long long next_combination(long long sub) { long long x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } // generic lambdas template #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) [[nodiscard]] #elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__((warn_unused_result)) #endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) static inline constexpr decltype(auto) fix(F &&f) noexcept { return [f = std::forward(f)](auto &&... args) { return f(f, std::forward(args)...); }; } template using PQG = priority_queue, greater>; template using PQ = priority_queue; typedef long long ll; typedef vector VL; typedef vector VVL; typedef pair PL; typedef vector VPL; typedef vector VB; typedef vector VD; typedef vector VS; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18; const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1}; #define PI 3.141592653589793238 #define EPS 1e-7 // 1000000007 で割ったあまりを扱う構造体 template struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if(val < 0) v += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if(val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if(val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while(b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if(val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, Fp &x) noexcept { return is >> x.val; } friend constexpr Fp modpow(const Fp &a, long long n) noexcept { if(n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if(n & 1) t = t * a; return t; } }; using mint = Fp; //遅延seg template struct SegmentTree { using F = function; using G = function; using H = function; using P = function; int n; // dat(出力)のマージ(更新) F f; // lazをdatに反映演算 G g; // laz(更新)のパージ(更新)(下に伝播) H h; // lazをdatに反映演算(まとめ) P p; T e1; E e2; vector dat; vector laz; SegmentTree(int n_, F f, G g, H h, T e1, E e2, vector v = vector(), P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), e1(e1), e2(e2), p(p) { init(n_); if(n_ == (int)v.size()) build(n_, v); } void init(int n_) { n = 1; while(n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, e1); laz.clear(); laz.resize(2 * n - 1, e2); } void build(int n_, vector v) { for(int i = 0; i < n_; i++) dat[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } inline void eval(int len, int k) { if(laz[k] == e2) return; if(k * 2 + 1 < n * 2 - 1) { laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]); laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]); } dat[k] = g(dat[k], p(laz[k], len)); laz[k] = e2; } T update(int a, int b, E x, int k, int l, int r) { eval(r - l, k); if(r <= a || b <= l) return dat[k]; if(a <= l && r <= b) { laz[k] = h(laz[k], x); return g(dat[k], p(laz[k], r - l)); } eval(r - l, k); return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r)); } T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); } T query(int a, int b, int k, int l, int r) { eval(r - l, k); if(r <= a || b <= l) return e1; if(a <= l && r <= b) return dat[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } T query(int a, int b) { return query(a, b, 0, 0, n); } }; signed main() { LCIN(N, M, K); mint e1 = 0, e2 = 0; auto f = [](mint a, mint b) { return a + b; }; auto g = [](mint a, mint b) { return a + b; }; auto h = [](mint a, mint b) { return a + b; }; auto p = [](mint a, mint b) { return a * b; }; SegmentTree seg(N + 1, f, g, h, e1, e2, vector(N + 1), p); SegmentTree seg2(N + 1, f, g, h, e1, e2, vector(N + 1), p); VPL lr; REP(i, M) { LCIN(l, r); l--, r--; lr.emplace_back(l, r); } seg.update(0, 1, 1); REP(i, K) { seg2.init(N + 1); REP(j, M) { ll l = lr[j].fi, r = lr[j].se; mint sum = seg.query(l, r + 1); seg2.update(l, r + 1, sum); } swap(seg, seg2); } cout << seg.query(N - 1, N) << "\n"; }