N,K=map(int,input().split()) mod=10**9+7 A=(1+K)*K//2 now=1 for i in range(N): now=now*A%mod B=A+K now2=1 for i in range(N): now2=now2*B%mod print((now2-now)%mod)