#include #include #include using namespace std; int main() { int n; cin >> n; long long p = 1000000009LL; vector fac(n+1), eus(n+1); // Precompute factorials. fac[0] = 1; for(long long i = 1; i <= n; i++) { fac[i] = (fac[i-1] * i) % p; } // eus[k] is the number of entirely unordered sequences of k distinct // elements. eus[0] = 1; for(int k = 1; k <= n; k++) { // A k element sequence which is not entirely unsorted has a first // sorted element, and we count them by the position of that first // element. The elements before that are entirely unsorted, and the // elements after are in any order. // // The number of entirely unsorted sequences of length k is k! minus // the number of not entirely unsorted sequences of length k. eus[k] = fac[k]; for(int i = 0; i < k; i++) { eus[k] -= (eus[i] * fac[k-i-1]) % p; if(eus[k] < 0) eus[k] += p; } } cout << eus[n] << endl; return 0; }