// // // Codeforces: ganariya // AtCoder: ganariya2525 // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;>>>>>;;?HMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<>>>>>ZMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM // MMMMMMMMMMMMMBrtwwtrw0dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM // MMMMMMMM9OdM#Ottd$;;;;;?WOw_WWOtttttttttOttI<;;;;;J(I~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM // MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM // MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM // MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM // MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM // MMMMNMMMM#lltwDzttllOXyW0X:..(OXk~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM // MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM // MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM // MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM // MMMMNMMMMNZllXtllldVyW3(Mf=.dVT7.dfppffppSXSMMMMMMMM // MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM // MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM // MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM // MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ... ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM // MMMMMMMMMMMMMRzZZZZZZZZb````````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM // MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM // MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM // MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM // MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM // MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM // MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM // MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM // MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM //include //------------------------------------------ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //~~~~~~~~~~~~~~~~~~~~~_(^~^ 」 ∠)_~~~~~~~~~~~~~~~~~~~~~ constexpr LL mod = 1e9 + 7; struct LazySegmentTree { private: LL n; vector node, lazy; public: LazySegmentTree(vector v) { LL sz = (LL) v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (LL i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (LL i = n - 2; i >= 0; i--) node[i] = (node[i * 2 + 1] + node[i * 2 + 2]) % mod; } void eval(LL k, LL l, LL r) { if (lazy[k] != 0) { node[k] += lazy[k]; node[k] %= mod; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(LL a, LL b, LL x, LL k = 0, LL l = 0, LL r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; node[k] %= mod; } } LL getsum(LL a, LL b, LL k = 0, LL l = 0, LL r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k] % mod; LL vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); LL vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return (vl + vr) % mod; } void reset() { int sz = node.size(); for (int i = 0; i < sz; i++) { node[i] = lazy[i] = 0; } } }; int main() { int N, M, K; cin >> N >> M >> K; vector L(M), R(M); for (int i = 0; i < M; i++) { cin >> L[i] >> R[i]; L[i]--, R[i]--; } vector> dp(K + 1, vector(N + 2, 0)); dp[0][0] = 1; for (int i = 0; i < K; i++) { vector pSum(N + 3, 0); for (int j = 0; j < N + 1; j++) pSum[j + 1] = (pSum[j] + dp[i][j]) % mod; for (int j = 0; j < M; j++) { int l = L[j]; int r = R[j]; r++; LL d = (pSum[r] - pSum[l] + mod) % mod; dp[i + 1][l] += d; dp[i + 1][l] %= mod; dp[i + 1][r] = (dp[i + 1][r] - d + mod) % mod; } for (int j = 0; j < N + 1; j++) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % mod; } cout << dp[K][N - 1] << endl; return 0; }