classCountTables { private: int f[N]; voidinit() { for (int i = s[0][0] = 1; i < N; ++ i) for (int j = 1; j <= i; ++ j) s[i][j] = (s[i - 1][j - 1] + (LL) j * s[i - 1][j]) % Mod; } intA(int n, int m) { if (n < m) return0; int cur = 1; for (int i = n; i > n - m; -- i) cur = (LL) cur * i % Mod; return cur; } public: inthowMany(int n, int m, int c){ init(); for (int i = 1; i <= n; ++ i) { f[i] = A(qpow(c, i), m); for (int j = 1; j < i; ++ j) f[i] = (f[i] + (LL) (Mod - f[j]) * s[i][j]) % Mod; } return f[n]; } };