#define _GLIBCXX_DEBUG #include using namespace std; int main(){ int N, M, P; cin >> N >> M >> P; vector> dp(M + 1, vector(N + 1, 0)); dp[0][0] = 1; for (int i = 0; i < M; i++){ long long s = 0; for (int j = 1; j <= N; j++){ s += dp[i][j - 1]; s %= P; dp[i + 1][j] = s * j % P; } } vector inv(N + 1); inv[1] = 1; for (int i = 2; i <= N; i++){ inv[i] = P - inv[P % i] * (P / i) % P; } vector fact(N + 1); vector finv(N + 1); fact[0] = 1; finv[0] = 1; for (int i = 1; i <= N; i++){ fact[i] = fact[i - 1] * i % P; finv[i] = finv[i - 1] * inv[i] % P; } auto binom = [&](int n, int k){ return fact[n] * finv[k] % P * finv[n - k] % P; }; long long S = 0; for (int i = 1; i <= M; i++){ long long sum = 0; for (int j = 0; j <= N; j++){ sum += dp[i][j]; } sum %= P; S += sum * binom(M, i) % P * fact[N - i] % P * finv[N - M] % P; S %= P; } S *= fact[N - M] * finv[N] % P; S %= P; cout << S << endl; }