eolymp
bolt
Try our new interface for solving problems
Problems

Concatenation of two palindromes

Concatenation of two palindromes

Find the number of ways to construct a string of length $n$ using $k$ Latin letters (the size of the alphabet is $k$) as the concatenation of two nonempty palindromes. \InputFile Two positive integers $n$ and $k~(1 \le n \le 10^5, 1 \le k \le 26)$. \OutputFile Print the number of ways to construct the given string. Print the answer modulo $10^9 + 7$. \Examples In the first test case the string of length $4$ using one letter ($а$ for example) can be constructed in three ways: $a + aaa, aa + aa, aaa + a$.
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4 1
Output example #1
3
Input example #2
3 2
Output example #2
8