MOD = 10**9+7 n,k = map(int,input().split()) K = k*(k+1)//2%MOD ans = pow(K+k,n,MOD) - pow(K,n,MOD) print(ans%MOD)