시간 제한메모리 제한제출정답맞힌 사람정답 비율
9 초 256 MB157327.273%

문제

The Stirling number of the first kind $\begin{bmatrix} n \\ k \end{bmatrix}$ is the number of permutations of $n$ elements with exactly $k$ disjoint cycles. The well-known recurrence relation is defined as follows: $$\begin{bmatrix} n+1 \\ k \end{bmatrix} = n \begin{bmatrix} n \\ k \end{bmatrix} + \begin{bmatrix} n \\ k-1 \end{bmatrix}$$ for $k>0$, with the initial conditions

$$\begin{bmatrix} 0 \\ 0 \end{bmatrix} = 1 \quad {\text{and}} \quad \begin{bmatrix} n \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ n \end{bmatrix} = 0$$ for $n > 0$.

Given four integers, $n$, $l$, $r$, and $p$, find the value of $$\left(\sum_{k=l}^{r}{\begin{bmatrix} n \\ k \end{bmatrix}} \right) \bmod p$$ where $p$ is prime.

입력

The first line contains four integers, $n$, $l$, $r$, and $p$ ($1 \le n \le 10^{18}$, $0 \le l \le r \le n$, $2 \le p \le 10^6$, $p$ is prime).

출력

 Output an integer denoting the answer.

예제 입력 1

4 1 4 5

예제 출력 1

4

예제 입력 2

6 5 5 29

예제 출력 2

15

예제 입력 3

1000 685 975 999983

예제 출력 3

482808