#include #include #include #include using namespace std; using ll = long long; constexpr ll MOD = 1000000007; int main() { ll N, p; cin >> N >> p; vector a(N + 1); a[1] = 0; a[2] = 1; for (int n = 3; n <= N; n++) { a[n] = p * a[n - 1] + a[n - 2]; a[n] %= MOD; } ll ans = 0; ll tmp = 0; for (int i = 1; i <= N; i++) { tmp += a[i]; tmp %= MOD; ans += a[i] * tmp; ans %= MOD; } cout << ans << endl; }