using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair; using Number = System.Int64; class Solver { Scanner sc = new Scanner(); // public void Solve() { int N, M, K; sc.Make(out N, out M, out K); var lrs = sc.ArrInt2D(M); var dp = new SegmentTree(N, 0, (a, b) => a + b); dp.Update(0, 1); while (K-- > 0) { var newdp = new SegmentTree(N, 0, (a, b) => a + b, (a, b) => a + b); foreach (var lr in lrs) { int l = lr[0]-1, r = lr[1]; newdp.Update(l, r, dp.Query(l, r)); } for (var i = 0; i < N; i++) dp[i] = newdp.Query(i); dp.All_Update(); } WriteLine(dp.Query(N - 1, N)); } } public class SegmentTree { protected readonly T[] item; protected readonly int num; protected readonly Func func; protected readonly Func updateFunc; protected readonly T minT; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Parent(int index) => (index - 1) >> 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int index) => (index << 1) + 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + num - 1]; } set { item[i + num - 1] = value; } } public SegmentTree(int num, T minT, Func func, Func updateFunc = null) { this.func = func; this.num = 1; this.minT = minT; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (this.num <= num) this.num <<= 1; item = new T[2 * this.num - 1]; for (var i = 0; i < 2 * this.num - 1; i++) item[i] = minT; } public void Update(int index, T value) { index += num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = func(item[Left(index)], item[Right(index)]); } } public virtual void Update(int left, int right, T value) => Update(left, right, 0, 0, num, value); protected virtual void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = num - 2; i >= 0; i--) item[i] = func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += num - 1; var value = func(minT, item[index]); while (index > 0) { index = Parent(index); value = func(value, item[index]); } return value; } public virtual T Query(int left, int right) => Query(left, right, 0, 0, num); protected virtual T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return minT; if (left <= l && r <= right) return item[k]; else return func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } /// /// check(func(item[st]...item[i]))がtrueとなる最小のi /// public int Find(int st, Func check) { var x = minT; return Find(st, check, ref x, 0, 0, num); } private int Find(int st, Func check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = func(x, item[k]); return check(x) ? k - num + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(func(x, item[k]))) { x = func(x, item[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } public struct ModInt { public const long MOD = (int)1e9 + 7; //public const long MOD = 998244353; public long num { get; set; } public ModInt(long n = 0) { num = n; } private static ModInt[] _fac;//階乗 private static ModInt[] _inv;//逆数 private static ModInt[] _facrev;//1/(i!) public override string ToString() => num.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= MOD) l.num -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.num * r.num % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.num; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void CombBuild(int n) { _fac = new ModInt[n + 1]; _facrev = new ModInt[n + 1]; _inv = new ModInt[n + 1]; _inv[1] = 1; _fac[0] = _fac[1] = 1; _facrev[0] = _facrev[1] = 1; for (var i = 2; i <= n; i++) { _fac[i] = _fac[i - 1] * i; _inv[i] = MOD - _inv[MOD % i] * (MOD / i); _facrev[i] = _facrev[i - 1] * _inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => _fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Div(ModInt n) => _inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacRev(ModInt n) => _facrev[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = _fac[n]; calc = calc * _facrev[r]; calc = calc * _facrev[n - r]; return calc; } } #region Template public class Template { static void Main(string[] args) { Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin(ref T num, T val) where T : IComparable { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax(ref T num, T val) where T : IComparable { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair PairMake() => new Pair(Next(), Next()); public Pair PairMake() => new Pair(Next(), Next(), Next()); private Queue q = new Queue(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make(out T1 v1) => v1 = Next(); public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); } public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); } public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); } public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); } public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); } } public class Pair : IComparable> { public T1 v1; public T2 v2; public Pair() { } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair p) { var c = Comparer.Default.Compare(v1, p.v1); if (c == 0) c = Comparer.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair : Pair, IComparable> { public T3 v3; public Pair() : base() { } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair p) { var c = base.CompareTo(p); if (c == 0) c = Comparer.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion