Counting Palindromes


Bob works at the Cookie Factory, where cookies are baked in flavours numbered 11 to nn. Every evening, a conveyor belt carries a sequence of nn cookies past him.

Alice's birthday is coming, and so Bob wants to sneak her a gift, a palindromic cookie box.

A palindromic box of cookies is a subsequence (not necessarily continuous) of cookies chosen from the belt (in order) whose flavour sequence reads the same forwards and backwards.

Alice is picky though: she won't accept a box unless it contains at least xx cookies.

Bob doesn't want to get fired, so he'll pack the smallest valid palindromic box possible so he's less likely to get caught.

Formally, for a given conveyor belt arrangement aa, define f(a)f(a) as the length of the shortest palindromic subsequence of length at least xx. If no such subsequence exists, f(a)=0f(a) = 0.

Since the factory runs many different arrangements over many nights, Bob wants to know the sum of f(a)f(a) over all possible conveyor belt arrangements of nn cookies where each cookie can have a flavour from 11 to nn. That is, there are nnn^n possible conveyor belt arrangements.

Help Bob figure out the sum (modulo 109+710^9 + 7) before Alice's birthday.

Input

A single line containing two integers nn and xx.

Output

A single integer, the answer modulo 109+710^9 + 7.

Constraints

  • 1≤n≤1061 \leq n \leq 10^6
  • x∈{2,3}x \in \{2, 3\}

Example 1

Input 1
2 2
Output 1
4
Explanation

There are 44 possible conveyor belt arrangements.

  • [1,1]:f([1,1])=2[1, 1]: f([1, 1]) = 2
  • [1,2]:f([1,2])=0[1, 2]: f([1, 2]) = 0
  • [2,1]:f([2,1])=0[2, 1]: f([2, 1]) = 0
  • [2,2]:f([2,2])=2[2, 2]: f([2, 2]) = 2

So the sum is 2+0+0+2=42 + 0 + 0 + 2 = 4.

Example 2

Input 2
3 3
Output 2
27
Explanation

There are 2727 possible conveyor belts, 99 of which have f(a)=3f(a) = 3 and the rest have f(a)=0f(a) = 0.

Example 3

Input 3
2026 2
Output 3
937223623

Example 4

Input 4
2026 3
Output 4
979361356
Note
  • nn represents both the number of flavours and the number of cookies on the conveyor belt.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.