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