Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/kombinatorika-aylana-boyash

Coloring a circle

Medium 1000 ms 128 MB 62%
Share

A circle is divided into $n$ sectors numbered from $1$ to $n$ and arranged in order around the circle (sector $n$ is also adjacent to sector $1$). Each sector is painted in one of $k$ colors; adjacent sectors must have different colors. How many ways are there? Print the answer modulo $10^{9} + 7$.

A circle divided into sectors: adjacent sectors have different colors

Input

One line with two positive integers: $n$ and $k$.

Output

One integer — the number of ways modulo $10^{9} + 7$.

Note

$2 \le n \le 10^{18}$
$1 \le k \le 10^{9}$

Examples

Input #1
4 3
Output #1
18
Input #2
3 2
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.