class ModInteger attr_reader :fac, :inv, :finv, :mod MOD = 10 ** 9 + 7 def initialize(n, mod: MOD) @mod = mod @fac = [1, 1] @inv = [1, 1] @finv = [1, 1] (2..n).each do |i| @fac[i] = fac[i - 1] * i % mod @inv[i] = mod - inv[mod % i] * (mod / i) % mod @finv[i] = finv[i - 1] * inv[i] % mod end end def combination(n, k) return 0 if n < k return 0 if n < 0 || k < 0 fac[n] * (finv[k] * finv[n - k] % mod) % mod end def permutation(n, k = n) return 1 if n == 0 return 0 if n < k return 0 if n < 0 || k < 0 fac[n] * (finv[n - k] % mod) % mod end end N = gets.to_i MOD = 10 ** 9 + 7 mi = ModInteger.new(N, mod: MOD) ans = 0 dp = Array.new(N + 1) { Array.new(N + 1) } def dfs(x, y, dp) return dp[x][y] = 1 if x == 0 && y == 0 return dp[x][y] = 0 if x < y || y <= 0 return dp[x][y] if dp[x][y] dp[x][y] = dfs(x - 1, y - 1, dp) + y * dfs(x - 1, y, dp) end 1.upto(N) do |y| 1.upto(N) do |x| dfs(x, y, dp) end end 1.upto(N) do |y| 1.upto(N) do |x| ans += mi.combination(N, x) * dp[x][y] * (y * (y - 1)).pow(N - x, MOD) ans %= MOD end end puts ans