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

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MN = 1000001;
constexpr int MOD = 1e9+7;

ll fact[MN] = { 1 }, ifact[MN] = { 1 };

inline ll pw(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) (res *= base) %= MOD;
		exp >>= 1, (base *= base) %= MOD;
	}
	return res;
}

inline ll inv(ll x) { return pw(x, MOD - 2); }

inline ll nCr(int n, int k) { return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD; }

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    int N; cin >> N;

    for (int i = 0; i < N; ++i) fact[i + 1] = (i + 1ll) * fact[i] % MOD, ifact[i + 1] = inv(fact[i + 1]);
    
    ll sum = 0, ans = 0;
    for (int i = N/2; i < N; ++i) {
        ll tmp = nCr(i-1, N-i-1)*fact[i]%MOD*fact[N-i-1]%MOD;
        (ans += i*(tmp-sum)+MOD) %= MOD;
        sum = tmp;
    }
    cout << ans;

    /*for (int N = 2; N <= 10; ++N) {
        //int N = 7;
        vector<int> P(N-1);
        iota(begin(P), end(P), 0);
        vector<int> ans(N-1);
        do {
            vector<bool> A(N, 0);
            ll cnt = 0;
            for (int i = 0; i < N-1; ++i) {
                A[P[i]] = A[P[i]+1] = 1;
                if (count(begin(A), end(A), 1) == N) {
                    ++ans[i];
                    if (i == 3) {
                        for (int x : P) cout << x << ' ';
                        cout << '\n';
                    }
                    break;
                }
            }
        } while (next_permutation(begin(P), end(P)));
        for (int x : ans) cout << setw(6) << x << ' ';
        cout << '\n';
    }*/
}