#include using namespace std; #define lli long long int #define REP(i,s,n) for(int i=s;i>n>>p; a[0]=0; sum[0]=0; a[1]=1; sum[1]=1; REP(i,2,1001000){ a[i]=(p*a[i-1]+a[i-2])%MOD; sum[i] = (sum[i-1]+a[i])%MOD; } lli ans=0; REP(i,0,n){ ans += (a[i]*sum[i])%MOD; ans%=MOD; } cout<