#pragma comment (linker, "/STACK:64000000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int N6 = 1e6 + 6; const int N9 = 1e9 + 7; typedef unsigned long long ull; typedef long long ll; typedef double ld; typedef pair PII; typedef pair PIl; typedef pair PlI; typedef pair Pll; #define y1 UKG_KTL #define F first #define S second #define pb push_back #define mp make_pair #define itn int #define forn(x, a, b) for (int x = a; x <= b; ++x) #define for1(x, a, b) for (int x = b; x >= a; --x) #define sz() size() #define skip continue #define gg exit(0) #define boost ios_base::sync_with_stdio(0),cin.tie(NULL) #define N 50 // const unsigned long long N = 2 * 1e5; const ll INFLL = (ll)1e18 + 100; const int INF = 1e9 + 100; const ll mod = 1e9 + 7; const ll P = 31; int n, k, x; inline ll Mult(ll x, ll y, ll md){ ll res = 0; while (y){ if (y & 1) res = (res + x) % md, y--; x = (x + x) % md, y >>= 1; } return res % md; } inline ll Pw(ll x, ll y, ll md){ ll res = 1; while (y){ if (y & 1) res = Mult(res, x, md), y--; y >>= 1, x = Mult(x, x, md); } return res % md; } void solve(){ cin >> n >> k >> x; if( n == 3 ){ if( x == 1 ){ cout << k - 1;gg; }else{ cout << k - 2;gg; } } ll ans = 1, ansik = 1; ans = Pw((k - 1), n - 2, mod); ans = ans - ((n-4)*2+1); ans %= mod; cout << ans; } int main(){ #define task "C" #ifdef UKG_KTL freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); #endif int tt = 1; // boost; // srand(time(NULL)); // scanf ("%d", &tt); while (tt--) { // cout<