N, p = map(int, input().split()) mod = 1000000007 L = [0, 1] S = 0 SS = 0 for i in range(N): S += L[i] * SS % mod S %= mod L.append((L[i] + p * L[i+1]) % mod) SS += L[i+1] % mod SS %= mod print(S)