I've encountered some interesting problems but I couldn't solve them. I really need some help.

**First problem** is: Given 3 integers **N**, **M**, **X** (1 <= N, M <= 10^{5}, 1 <= X <= m). Calculate the number of ways to create **n** segments [L_{1}, R_{1}], [L_{2}, R_{2}], …, [L_{n}, R_{n}] (Li <= Hi) such that they satisfy two conditions:

- there is no
*i*and*k*(i != k) that L_{i}<= L_{k}<= H_{k}<= H_{i} - There is at least one segment which has L
_{i}= s