#include using namespace std; #define int long long #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)x.size()) template bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } /* */ using vi = vector; using vvi = vector; using P = pair; const int mod = 1e9+7; signed main() { int n, p; cin >> n >> p; vi a(n + 1); a[1] = 0; a[2] = 1; rep(i, 3, n + 1) { a[i] = (p*a[i-1]%mod + a[i-2])%mod; } int sum = 0, ans = 0; for(int i = n; i >= 1; i--){ sum = (sum + a[i])%mod; ans = (ans + a[i]*sum%mod)%mod; } cout << ans << endl; return 0; }