Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/kombinatorika-tartibsizliklar

Nobody in their place

Medium 1000 ms 128 MB 58%
Share

$n$ students handed in their notebooks. The teacher handed the notebooks back, one to each student, but no student got their own notebook. Find the number of ways this could happen.

Diagram of hand-outs in which nobody gets their own notebook

Input

One positive integer $n$.

Output

One integer — the number of ways modulo $10^{9} + 7$.

Note

$1 \le n \le 10^{6}$

Examples

Input #1
3
Output #1
2
Input #2
4
Output #2
9

Sign in to submit a solution

Signing up is free and takes a minute.