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