#include using namespace std; #define lli long long int #define phbk push_back #define mp make_pair #define F first #define S second #define mod 1000000007 lli modularexpo(lli base,lli exp) { lli res=1; while(exp>0) { if(exp%2==1) res=(res*base)%mod; base=(base*base)%mod; exp/=2; } return res%mod; } int main() { lli n,k,x,ans,t; cin>>n>>k>>x; t=modularexpo(k-1,n-1); if(n&1) { if(x==1) { ans=(t-1)*modularexpo(k,mod-2)+1; ans%=mod; } else { ans=(t-1)*modularexpo(k,mod-2); ans%=mod; } } else { if(x==1) { ans=(t+1)*modularexpo(k,mod-2)-1; ans%=mod; } else { ans=(t+1)*modularexpo(k,mod-2); ans%=mod; } } cout<