Rohan and Palindromes

3.3

25 votes
Easy-Medium
Problem

Rohan loves Palindromes. Palindrome is a string that read same forward and backward. For example abba is a palindrome while abca is not.

Rohan is forming a palindrome of length lesser than or equal to n, with first k characters of lowercase English letters. He needs your help to find out the number of possible palindromes.

Output the result modulo 109 + 7

Input Format

First line contains 2 space separated integers, n and k

Output Format

Output a single integer, which is answer to the problem

Constraints

  • 1 ≤ n ≤ 109
  • 1 ≤ k ≤ 26
Sample Input
3 2
Sample Output
8
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The palindromes possible are -

  • a
  • b
  • aa
  • bb
  • aaa
  • aba
  • bab
  • bbb
Contributers:
Editor Image

?