Problem:
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

Solution in C++14 (Clang 3.8.0) (judge verdict: Accepted)

#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}
LL modinv(LL a, LL mod){
	LL x,y;
	gcdex(a,mod,x,y);
	if(x<0){
		x+=mod;
	}
	return x;
}

const int N=1e6;
const int M=1e9+7;
template<int S>
struct Comb
{
	LL f[S+1];
	LL r[S+1];
	LL mod;
	Comb(int m)
	{
		mod=m;
		f[0]=1;
		r[0]=1;
		for(LL i=1;i<=S;i++){
			f[i]=i*f[i-1]%m;
			r[i]=modinv(i,m)*r[i-1]%m;
		}
	}
	LL c(int n,int i){
		if(i<0||n<i)
		{
			return 0;
		}
		return f[n]*r[i]%mod*r[n-i]%mod;
	}
};
Comb<N> comb(M);
int main() {
	LL N;
	cin >> N;
	LL pre=0;
	LL ret=0;
	for(LL K=1;K<=N-1;K++){
		LL v=0;
		if(2*K-N>=0){
			v=comb.c(K-1,2*K-N)*comb.f[K]%M*comb.f[N-1-K]%M;
		}
		//cerr << K << ", " << v << endl;
		ret+=(v+M-pre)%M*K%M;
		ret%=M;
		pre=v;
	}
	cout << ret << endl;

	return 0;
}