#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } #define M (1000000007) int main(int argc, char** argv) { int n, p; cin >> n >> p; vector a(n + 1); vector cum(n + 1); a[1] = 0; a[2] = 1; cum[1] = a[1]; cum[2] = a[1] + a[2]; for (int i = 3; i <= n; i++) { a[i] = (a[i - 2] + ((p * a[i - 1]) % M)) % M; cum[i] = (cum[i - 1] + a[i]) % M; } ll sigma = 0; for (int i = 1; i <= n; i++) { sigma += ((a[i] * cum[i]) % M) % M; } cout << sigma % M << endl; return 0; };