LearnPy Hub
← Arena
AdvancedRating 1500

Painting the Fence

Paint n posts with k colours so that no three posts in a row share a colour. Count the ways modulo 1 000 000 007.

Input

Two integers n and k (≤ 10⁵).

Output

One integer.

Sample 1

Input
3 2
Output
6

Sample 2

Input
1 1
Output
1
solution.py
Output appears here
Painting the Fence · Python Arena problem · LearnPy Hub