#include #include using namespace std; using ll=long long; #define int ll #define FOR(i,a,b) for(int i=int(a);i CerrDummy& operator<<(CerrDummy&cd,const T&){ return cd; } using charTDummy=char; using traitsDummy=char_traits; CerrDummy& operator<<(CerrDummy&cd,basic_ostream&(basic_ostream&)){ return cd; } #define cerr cerrDummy #endif #define REACH cerr<<"reached"< using V=vector; template using VV=V>; using pi=pair; using vi=vector; using ld=long double; template ostream& operator<<(ostream& os,const pair& p){ os<<"("< ostream& operator <<(ostream& os,const vector& v){ os<<"{"; rep(i,(int)v.size()){ if(i)os<<","; os< void print_tuple(ostream&,const T&){ } template void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<(t); print_tuple(os,t); } template ostream& operator<<(ostream&os,const tuple&t){ os<<"("; print_tuple<0,tuple,Args...>(os,t); return os<<")"; } ll read(){ ll i; scanf("%lld",&i); return i; } void printSpace(){ printf(" "); } void printEoln(){ printf("\n"); } void print(ll x,int suc=1){ printf("%lld",x); if(suc==1) printEoln(); if(suc==2) printSpace(); } template void print(const vector&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ static char buf[3341000]; scanf("%s",buf); return string(buf); } char* readCharArray(){ static char buf[3341000]; static int bufUsed=0; char* ret=buf+bufUsed; scanf("%s",ret); bufUsed+=strlen(ret)+1; return ret; } template void chmax(T& a,U b){ if(a void chmin(T& a,U b){ if(b T Sq(const T& t){ return t*t; } #define CAPITAL void Yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"< vector Uniqued(const vector&vv){ auto v(vv); sort(all(v)); v.erase(unique(all(v)),v.end()); return v; } template void MakeUniqued(vector&v){ sort(all(v)); v.erase(unique(all(v)),v.end()); } template struct ModInt{ static constexpr int base=mod; int v; ModInt():v(0){} ModInt(ll vv){ v=vv%mod; if(v<0)v+=mod; } explicit operator bool()const{ return v; } explicit operator int()const{ return v; } bool operator==(const ModInt&rhs)const{ return v==rhs.v; } bool operator!=(const ModInt&rhs)const{ return v!=rhs.v; } ModInt operator-()const{ return ModInt(0)-*this; } ModInt& operator+=(const ModInt&rhs){ v+=rhs.v; if(v>=mod)v-=mod; return *this; } ModInt&operator-=(const ModInt&rhs){ v-=rhs.v; if(v<0)v+=mod; return *this; } ModInt&operator*=(const ModInt&rhs){ v=ll(v)*rhs.v%mod; return *this; } ModInt&operator/=(const ModInt&rhs){ operator*=(rhs.inv()); return *this; } ModInt operator+(const ModInt&rhs)const{ return ModInt(*this)+=rhs; } ModInt operator-(const ModInt&rhs)const{ return ModInt(*this)-=rhs; } ModInt operator*(const ModInt&rhs)const{ return ModInt(*this)*=rhs; } ModInt operator/(const ModInt&rhs)const{ return ModInt(*this)/=rhs; } friend ModInt operator+(int x,const ModInt&y){ return ModInt(x)+y; } friend ModInt operator-(int x,const ModInt&y){ return ModInt(x)-y; } friend ModInt operator*(int x,const ModInt&y){ return ModInt(x)*y; } friend ModInt operator/(int x,const ModInt&y){ return ModInt(x)/y; } ModInt pow(int n)const{ ModInt res(1),x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1; } return res; } ModInt inv()const{ return pow(mod-2); } }; template ostream& operator<<(ostream&os,const ModInt&m){ return os< void print(const ModInt&m,int suc=1){ print(m.v,suc); } using mint=ModInt<1000000007>; //using mint=ModInt<998244353>; const int Vmax=min(2000010,mint::base); mint fact[Vmax],factInv[Vmax],invs[Vmax]; void InitFact(){ fact[0]=1; FOR(i,1,Vmax){ fact[i]=fact[i-1]*i; } factInv[Vmax-1]=fact[Vmax-1].inv(); for(int i=Vmax-2;i>=0;i--){ factInv[i]=factInv[i+1]*(i+1); } for(int i=Vmax-1;i>=1;i--){ invs[i]=factInv[i]*fact[i-1]; } } struct InitFactDummy{ InitFactDummy(){ InitFact(); } } initFactDummy; mint Choose(int n,int k){ return fact[n]*factInv[n-k]*factInv[k]; } mint Binom(int a,int b){ return fact[a+b]*factInv[a]*factInv[b]; } mint Catalan(int n){ return Binom(n,n)-(n-1>=0?Binom(n-1,n+1):0); } const int Kmax=310; mint dp[2][Kmax][Kmax]; signed main(){ int n=read(),k=read(); if(n==1){ print(0); return 0; } int cur=0; FOR(i,1,n+1){ int j=min(n-i,Kmax-5); dp[cur][j][j+1]+=i; } const mint in=mint(n).inv(); rep(_,k){ int nx=cur^1; ZERO(dp[nx]); rep(i,Kmax)FOR(j,i+1,Kmax){ auto w=dp[cur][i][j]*in; dp[nx][i][j-1]+=w; if(i==0){ dp[nx][i][j]+=w*(n-1); }else{ dp[nx][i][j]+=w*(n-2); dp[nx][i-1][j]+=w; } } cur=nx; } mint ans=0; rep(i,Kmax)FOR(j,i+1,Kmax) ans+=dp[cur][i][j]; ans*=mint(n).pow(k); print(ans); }