package main import ( "fmt" "bufio" "os" "strconv" ) //•*¨*•.¸¸♪I/O•*¨*•.¸¸♪ var ( sc = bufio.NewScanner(os.Stdin) wr = bufio.NewWriter(os.Stdout) ) func scanInt() int { sc.Scan() a,_ := strconv.Atoi(sc.Text()) return a } func scanInt64() int64 { sc.Scan() a,_ := strconv.ParseInt(sc.Text(),10,64) return a } func scanFloat64() float64 { sc.Scan() a,_ := strconv.Atoi(sc.Text()) return float64(a) } func scanInts(n int) []int { res := make([]int, n) for i := 0; i < n; i++ { res[i] = scanInt() } return res } func scanText() string { sc.Scan() return sc.Text() } func printInts(a ...int) { for i, e := range a { fmt.Fprint(wr, e) if i != len(a)-1 { fmt.Fprint(wr, " ") } } fmt.Fprintln(wr) wr.Flush() } //•*¨*•.¸¸♪Main•*¨*•.¸¸♪( -ω-)ノ ( ・ω・) func main() { sc.Split(bufio.ScanWords) // sc.Buffer(make([]byte, 10000), 100000000) n := scanInt() p := scanInt() if n == 1 { fmt.Println(0) return } a := make([]int, n) a[0] = 0 a[1] = 1 for i := 2; i < n; i++ { a[i] = (p*a[i-1]%mod+a[i-2])%mod } sum := make([]int, n) sum[0] = a[0] for i := 1; i < n; i++ { sum[i] = (sum[i-1]+a[i])%mod } ans := 0 for i := 0; i < n; i++ { ans = (ans + a[i]*sum[i]%mod)%mod } fmt.Println(ans) } const mod = 1000000007