import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) sys.setrecursionlimit(10**7) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n,m = na() p = 10 ** 9 + 7 N = 2*10 ** 6 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) def cmb(n, r): if (r < 0) or (n < r): return 0 r = min(r, n - r) return ((fact[n] * factinv[r])%p) * factinv[n-r] % p def pem(n,r): if (r < 0) or (n < r): return 0 return (fact[n] * factinv[r])%p ans = 0 for k in range(m,n+1): ans+=n*cmb(n,k)%p ans%=p #print(ans) for k in range(1,n+1): N = min((n+k)//2,n) #print(cmb(n,N-k),cmb(n,m-k-1)) ans+=k*(cmb(n,N-k)-cmb(n,m-k-1))%p ans%=p #print(ans) for k in range(1,n+1): N = min(n-m,(n+k)//2) #print(cmb(n,N-k),cmb(n,-k-1)) ans+=+k*(cmb(n,N-k)-cmb(n,-k-1))%p ans%=p print(ans)