#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const unsigned MODVAL = 1000000007;
struct mint
{
unsigned val;
mint():val(0){}
mint(int x):val(x%MODVAL) {}
mint(unsigned x):val(x%MODVAL) {}
mint(LL x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator/(mint x, mint y) { return x/=y; }
vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*LL(FAC_.size()) ); return FAC_[size_t(n)]; }
template<typename T>
struct DP2
{
const int N1, N2;
vector<T> data;
DP2(){}
DP2(int N1, int N2, const T& t = T())
: N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<28)); }
T& operator()(int i1, int i2)
{ return data[ (i1*N2)+i2 ]; }
void swap(DP2& rhs)
{ data.swap(rhs.data); }
};
class LineMST { public:
int count(int N, int L)
{
DP2<int> dp(N, L+1, -1);
DP2<int> dp_sub(N, L+1, -1);
return (solve(N-1, L, L, dp, dp_sub)*FAC(N)/2).val;
}
// maximum <= L
mint solve(int N, int L, const int OL, DP2<int>& dp, DP2<int>& dp_sub)
{
if(N==0) return 1;
if(L==0) return 0;
if(dp(N,L) != -1)
return dp(N,L);
mint total = 0;
for(int XL=1; XL<=L; ++XL)
total += solve_sub(N, XL, OL, dp, dp_sub);
return dp(N,L) = total.val;
}
// L = exact maximum.
int solve_sub(int N, int L, const int OL, DP2<int>& dp, DP2<int>& dp_sub) {
if(N==0) return 1;
if(L==0) return 0;
if(dp_sub(N,L) != -1)
return dp_sub(N,L);
mint total = 0;
for(int maxP=1; maxP<=N; ++maxP) {
total +=
mint(solve(maxP-1, L-1, OL, dp, dp_sub))
* solve(N-maxP, L, OL, dp, dp_sub)
* POW(OL-L+1, maxP*(N-maxP+1)-1);
}
return dp_sub(N,L)=total.val;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, LineMST().count(N, L));}
int main(){
CASE(0)
int N = 3;
int L = 2;
int _ = 15;
END
CASE(1)
int N = 2;
int L = 10;
int _ = 10;
END
CASE(2)
int N = 3;
int L = 1;
int _ = 3;
END
CASE(3)
int N = 8;
int L = 41;
int _ = 655468587;
END
CASE(4)
int N = 50;
int L = 50;
int _ = 699887037;
END
CASE(4)
int N = 200;
int L = 200;
int _ = 152699064;
END
/*
CASE(5)
int N = ;
int L = ;
int _ = ;
END
CASE(6)
int N = ;
int L = ;
int _ = ;
END
*/
}
// END CUT HERE