C - Painting Machines Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 800

問題文

N 個のマスが横一列に並んでおり、左から右へ 1 から N までの番号がついています。 最初、すべてのマス目は白いです。 また、N-1 台のペイントマシンがあり、1 から N-1 までの番号が付けられています。 ペイントマシン i は、稼働すると、マス i とマス i+1 を黒く塗ります。

すぬけ君は、これらのペイントマシンを、1 台ずつ順番に稼働させます。 すぬけくんがマシンを稼働させる順番は、(1, 2, ..., N-1) の順列 P によって表されます。 これは、i 番目に稼働させるマシンの番号が P_i であることを意味します。

ここで、ある順列 P のスコアは、その順列に従ってマシンを稼働させたとき、 すべてのマスが黒く塗られた状態に初めてなるまでに稼働させたマシンの台数と定義されます。 すぬけ君はまだ順列 P を決めていませんが、スコアに興味があります。 すぬけ君のために、すべての順列についてそのスコアを求め、その総和を求めてください。 ただし、答えは非常に大きくなることがあるので、10^9 +7 で割った余りを求めてください。

制約

  • 2 \leq N \leq 10^6

入力

入力は以下の形式で標準入力から与えられる。

N

出力

すべての順列 P のスコアの総和を 10^9 + 7 で割った余りを出力せよ。


入力例 1

4

出力例 1

16

順列 P としてありうるものは 6 つあります。 この中で、P = (1, 3, 2) または P = (3, 1, 2) のときだけスコアは 2 になり、 それ以外のときはスコアは 3 になります。 よって、求める答えは 2 \times 2 + 3 \times 4 = 16 となります。


入力例 2

2

出力例 2

1

ありうる唯一つの順列は P = (1) で、スコアは 1 です。


入力例 3

5

出力例 3

84

入力例 4

100000

出力例 4

341429644

Score : 800 points

Problem Statement

There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black.

Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of (1, 2, ..., N-1), P, which means that the i-th operated machine is Machine P_i.

Here, the score of a permutation P is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by P. Snuke has not decided what permutation P to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo 10^9+7.

Constraints

  • 2 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of the scores over all possible permutations, modulo 10^9+7.


Sample Input 1

4

Sample Output 1

16

There are six possible permutations as P. Among them, P = (1, 3, 2) and P = (3, 1, 2) have a score of 2, and the others have a score of 3. Thus, the answer is 2 \times 2 + 3 \times 4 = 16.


Sample Input 2

2

Sample Output 2

1

There is only one possible permutation: P = (1), which has a score of 1.


Sample Input 3

5

Sample Output 3

84

Sample Input 4

100000

Sample Output 4

341429644