N,K=map(int,input().split()) MOD=10**9+7 ans=1 for i in range(1,N+1): ans=(K+K*(K+1)//2)*ans%MOD ans=ans-pow(K*(K+1)//2,N,MOD) ans%=MOD print(ans)