Mod=10**9+7 N,K=map(int,input().split()) alpha=((K*(K+1))//2)%Mod X=pow(K+alpha,N,Mod) Y=pow(alpha,N,Mod) print((X-Y)%Mod)