https://www.acmicpc.net/problem/1947
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static final int MAX = 1_000_000;
static final int DIVISOR = 1_000_000_000;
static int N;
static void input() {
Reader scanner = new Reader();
N = scanner.nextInt();
}
static void solution() {
if(N == 1) System.out.println(0);
else if(N == 2) System.out.println(1);
else {
int[] dp = new int[MAX + 1];
dp[1] = 0;
dp[2] = 1;
for(int idx = 3; idx <= N; idx++) {
long caseNum = ((long)(idx - 1) * (dp[idx - 1] + dp[idx - 2])) % DIVISOR;
dp[idx] = (int) caseNum;
}
System.out.println(dp[N]);
}
}
public static void main(String[] args) {
input();
solution();
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
}