import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 N, K = map(int, read().split()) # (0,1) に居たコマを重ならないように右に K 回動かしたときの、到達地点の組 dp = np.zeros((K+2, K+2), np.int64) dp[0,1] = 1 for _ in range(K): newdp = dp * (N - 2) newdp[1:] += dp[:-1] newdp[:,1:] += dp[:,:-1] dp = newdp dp %= MOD np.fill_diagonal(dp, 0) dp = dp.sum(axis=1) % MOD coef = np.zeros(N+2, np.int64) dp = dp[:N+1] for i, x in enumerate(dp): coef[0] += x coef[N+1-i] -= x coef %= MOD np.cumsum(coef, out=coef) coef %= MOD x = (coef[:N + 1] * np.arange(N + 1, dtype=np.int64) % MOD).sum() % MOD print(x)