n,k = map(int,input().split()) mod = 10**9+7 x = (k+1)*(k+2)//2 -1 x %= mod x_ = (k+1)*(k)//2 x_ %= mod ans = pow(x,n,mod) - pow(x_,n,mod) ans %= mod print(ans)