#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i,n) for(int i = 0;i < (int)(n);i++) #define RREP(i,n) for(int i = (int)n-1;i >= 0;i--) #define FOR(i,s,n) for(int i = s;i < (int)n;i++) #define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--) #define ALL(a) a.begin(),a.end() #define IN(a, x, b) (a<=x && xinline bool CHMAX(T&a,T b){if(ainline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;} constexpr long long INF = 1e9,MOD = 1e9 + 7; signed main(){ int N,P; cin >> N >> P; int sum = 0,ans = 0; vectordp(N); dp[0] = 0; dp[1] = 1; REP(i,N){ if(i >= 2)(dp[i] = P * dp[i-1] + dp[i-2])%=MOD; (sum += dp[i])%=MOD; (ans += dp[i]*sum%MOD)%=MOD; } cout << ans << endl; }