MOD = 10**9 + 7 def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]); idx += 1 M = int(data[idx]); idx += 1 K = int(data[idx]); idx += 1 elevators = [] for _ in range(M): L = int(data[idx]); idx += 1 R = int(data[idx]); idx += 1 elevators.append((L, R)) # DP state: dp_prev[x] is the number of ways to be at floor x after k moves dp_prev = [0] * (N + 2) # 1-based indexing, ignoring 0, N+1 is buffer dp_prev[1] = 1 for _ in range(K): # Compute prefix sum for dp_prev prefix = [0] * (N + 2) for x in range(1, N + 1): prefix[x] = (prefix[x-1] + dp_prev[x]) % MOD # Initialize difference array diff = [0] * (N + 2) for L, R in elevators: # Calculate sum S of dp_prev[x] for x in [L, R] S = (prefix[R] - prefix[L-1]) % MOD # Apply range [L, R] addition of S diff[L] = (diff[L] + S) % MOD if R + 1 <= N: diff[R+1] = (diff[R+1] - S) % MOD # Compute dp_next from the difference array current = 0 dp_next = [0] * (N + 2) for y in range(1, N + 1): current = (current + diff[y]) % MOD dp_next[y] = current % MOD # Update for next iteration dp_prev = dp_next print(dp_prev[N] % MOD) if __name__ == "__main__": main()