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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define F first
#define S second
#define ld long double
int const M=1e6+10,inf=1e9+10,mod=1e9+7;
int fact[M],ans[M];
int pw(int x,int y)
{
	if(y==0)return 1;
	int tmp=pw(x,y/2);
	if(y%2==0)return (tmp*tmp)%mod;
	return ((tmp*tmp)%mod*x)%mod;
}
int C(int n,int r)
{
	int tmp=fact[r]*fact[n-r];
	tmp%=mod;
	tmp=pw(tmp,mod-2);
	tmp*=fact[n];
	tmp%=mod;
	return tmp;
}
int say(int n,int r)
{
	int tmp=n-r;
	if(tmp==0 && r==0)return 1;
	if(tmp<r || r==0)return 0;
	return C(tmp-1,r-1);
}
int32_t main()
{
	int n;
	cin>>n;
	fact[0]=1;
	//cout<<C(5,2)<<" "<<pw(2,4)<<endl;
	for(int i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
	}
	int all=0;
	for(int i=1;i<=n-1;i++)
	{
		if(n-i-1<0)continue;
		int res=n-i;
		if(n-2>=res)
			ans[i]=say(n-2,res);
		ans[i]*=(res*2)%mod;
		ans[i]%=mod;
		if(n-2>=res-1){
			ans[i]+=say(n-2,res-1)*res;
			ans[i]%=mod;
		}
		if(n-3>=res)
		{
			int hlp=say(n-3,res-1)*2;
			hlp*=res;
			hlp%=mod;
			ans[i]+=hlp;
			ans[i]%=mod;
		}
		int tmp=1;
		tmp%=mod;
		tmp*=fact[i-1];
		tmp%=mod;
		tmp*=fact[n-i-1];
		tmp%=mod;
		tmp*=i;
		tmp%=mod;
		tmp*=ans[i];
		tmp%=mod;
	//	cout<<i<<" "<<res<<" "<<tmp<<" "<<ans[i]<<endl;
		all+=tmp;
		all%=mod;
	}
	cout<<all;
}