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 Kotlin (1.0.0) (judge verdict: Accepted)

const val P = 1000000007L

// Find (x, y, r) such that r = gcd(a,b) and ax + by = r.
fun extendedGCD(a: Long, b: Long): Triple<Long, Long, Long> {
  var x0 = 1L
  var y0 = 0L
  var z0 = a
  var x1 = 0L
  var y1 = 1L
  var z1 = b
  while (true) {
    if (z1 == 0L) return Triple(x0, y0, z0)
    val q = z0 / z1
    val x2 = x0 - q * x1
    val y2 = y0 - q * y1
    val z2 = z0 - q * z1
    x0 = x1
    x1 = x2
    y0 = y1
    y1 = y2
    z0 = z1
    z1 = z2
  }
}

fun inverseMod(a: Long, m: Long): Long {
  val (x, y, r) = extendedGCD(a, m)
  if (r != 1L) return 0  // No inverse.

  return (x + m) % m
}

class FiniteField(xRaw: Long) {
  private var x = if (xRaw >= 0) xRaw % P else (P - ((-xRaw) % P)) % P
  constructor(xi: Int): this(xi.toLong())
  operator fun plusAssign(o: Long) {
    x += o
    x %= P
  }
  operator fun plusAssign(o: FiniteField) {
    this += o.x
  }
  operator fun minusAssign(o: Long) {
    x += P - o
    x %= P
  }
  operator fun minusAssign(o: FiniteField) {
    this -= o.x
  }
  operator fun timesAssign(o: Long) {
    x *= o
    x %= P
  }
  operator fun timesAssign(o: FiniteField) {
    this *= o.x
  }
  operator fun divAssign(o: Long) {
    x *= inverseMod(o, P)
    x %= P
  }
  operator fun divAssign(o: FiniteField) {
    this /= o.x
  }
  override fun toString() = x.toString()
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val factorialTable = Array(n, { FiniteField(0L) })
  factorialTable[0] = FiniteField(1)
  for (k in 1..(n - 1)) {
    factorialTable[k] = FiniteField(1)
    factorialTable[k] *= factorialTable[k - 1]
    factorialTable[k] *= k.toLong()
  }

  val fTable = Array(n, { k ->
    if (2 * k < n) FiniteField(0)
    else {
      val f = FiniteField(1)
      f *= factorialTable[k]
      f *= factorialTable[k - 1]
      f /= factorialTable[2 * k - n]
      f
    }
  })

  var ans = FiniteField(0)
  for (k in 1..(n - 1)) {
    val count = FiniteField(0)
    count += fTable[k]
    count -= fTable[k - 1]
    count *= k.toLong()
    ans += count
  }
  println(ans)
}