#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; constexpr ll mod = 1e9+7; int main(){ int n; ll p; cin >> n >> p; map dp; dp[1] = 0; dp[2] = 1; for (int i = 3; i <= n; i++) (dp[i] = p * dp[i-1] % mod + dp[i-2]) %= mod; ll res = 0; vector cum(n+1,0); rep(i,n) cum[i+1] = (cum[i] + dp[i+1]) % mod; for (int i = 1; i <= n; i++) (res += dp[i] * cum[i] % mod) %= mod; cout << res << endl; return 0; }