#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<int>g[5100];
int sz[5100];
int h[5100];
long long C[5100][5100];
long long fact[5100];
long long ret=1;
int N;
long long dp[5100][5100];
long long calc(vector<int>v,int K){
	int n=v.size();
	for(int i=0;i<=n;i++){
		for(int j=0;j<=K;j++){
			dp[i][j]=0;
		}
	}
	int tot=0;
	for(int i=0;i<v.size();i++)tot+=v[i];
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=K;j++){
			if(!dp[i][j])continue;
			for(int k=0;k<=v[i]&&j+k<=K;k++){
				dp[i+1][j+k]=(dp[i+1][j+k]+dp[i][j]*C[v[i]][k]%mod*C[v[i]][k]%mod*fact[k])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<=K;i++){
//		printf("%d: %lld\n",i,dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i]%mod);
		if(i%2==0){
			ret=(ret+dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i])%mod;
		}else{
			ret=(ret+mod-dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i]%mod%mod)%mod;
		}
	}
//	for(int i=0;i<n;i++)printf("%d ",v[i]);
//		printf("(%d) -> %lld\n",K,ret);
	return ret;
}
void dfs(int a,int b){
	sz[a]=1;
	int tot=0;
	vector<int>v;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		dfs(g[a][i],a);
		sz[a]+=sz[g[a][i]];
		v.push_back(h[g[a][i]]);
		tot+=h[g[a][i]];
	}
	tot++;
	int cap=min(sz[a],N-sz[a]);
	h[a]=cap;
//	printf("%d %d %d\n",a,cap,tot);
	if(cap>=tot)return;
	long long tmp=0;
	tmp=(tmp+calc(v,tot-cap-1))%mod;
	v.push_back(1);
	tmp=(tmp+calc(v,tot-cap))%mod;
	ret=ret*tmp%mod;
}
int main(){
	fact[0]=1;
	for(int i=1;i<5100;i++)fact[i]=fact[i-1]*i%mod;
	C[0][0]=1;
	for(int i=0;i<5050;i++){
		for(int j=0;j<=i;j++){
			C[i+1][j]=(C[i+1][j]+C[i][j])%mod;
			C[i+1][j+1]=(C[i+1][j+1]+C[i][j])%mod;
		}
	}
	int a;scanf("%d",&a);
	N=a;
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	dfs(0,-1);
	printf("%lld\n",ret);
}
### Prompt

Your challenge is to write a Cpp solution to the following problem:

There is a tree with N vertices. The vertices are numbered 1 through N. The i-th edge (1 \leq i \leq N - 1) connects Vertex x_i and y_i. For vertices v and w (1 \leq v, w \leq N), we will define the distance between v and w d(v, w) as "the number of edges contained in the path v-w".

A squirrel lives in each vertex of the tree. They are planning to move, as follows. First, they will freely choose a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Then, for each 1 \leq i \leq N, the squirrel that lived in Vertex i will move to Vertex p_i.

Since they like long travels, they have decided to maximize the total distance they traveled during the process. That is, they will choose p so that d(1, p_1) + d(2, p_2) + ... + d(N, p_N) will be maximized. How many such ways are there to choose p, modulo 10^9 + 7?

Constraints

* 2 \leq N \leq 5,000
* 1 \leq x_i, y_i \leq N
* The input graph is a tree.

Input

Input is given from Standard Input in the following format:


N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1}


Output

Print the number of the ways to choose p so that the condition is satisfied, modulo 10^9 + 7.

Examples

Input

3
1 2
2 3


Output

3


Input

4
1 2
1 3
1 4


Output

11


Input

6
1 2
1 3
1 4
2 5
2 6


Output

36


Input

7
1 2
6 3
4 5
1 7
1 5
2 3


Output

396

### Response

```cpp
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<int>g[5100];
int sz[5100];
int h[5100];
long long C[5100][5100];
long long fact[5100];
long long ret=1;
int N;
long long dp[5100][5100];
long long calc(vector<int>v,int K){
	int n=v.size();
	for(int i=0;i<=n;i++){
		for(int j=0;j<=K;j++){
			dp[i][j]=0;
		}
	}
	int tot=0;
	for(int i=0;i<v.size();i++)tot+=v[i];
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=K;j++){
			if(!dp[i][j])continue;
			for(int k=0;k<=v[i]&&j+k<=K;k++){
				dp[i+1][j+k]=(dp[i+1][j+k]+dp[i][j]*C[v[i]][k]%mod*C[v[i]][k]%mod*fact[k])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<=K;i++){
//		printf("%d: %lld\n",i,dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i]%mod);
		if(i%2==0){
			ret=(ret+dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i])%mod;
		}else{
			ret=(ret+mod-dp[n][i]*C[tot-i][K-i]%mod*C[tot-i][K-i]%mod*fact[K-i]%mod%mod)%mod;
		}
	}
//	for(int i=0;i<n;i++)printf("%d ",v[i]);
//		printf("(%d) -> %lld\n",K,ret);
	return ret;
}
void dfs(int a,int b){
	sz[a]=1;
	int tot=0;
	vector<int>v;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		dfs(g[a][i],a);
		sz[a]+=sz[g[a][i]];
		v.push_back(h[g[a][i]]);
		tot+=h[g[a][i]];
	}
	tot++;
	int cap=min(sz[a],N-sz[a]);
	h[a]=cap;
//	printf("%d %d %d\n",a,cap,tot);
	if(cap>=tot)return;
	long long tmp=0;
	tmp=(tmp+calc(v,tot-cap-1))%mod;
	v.push_back(1);
	tmp=(tmp+calc(v,tot-cap))%mod;
	ret=ret*tmp%mod;
}
int main(){
	fact[0]=1;
	for(int i=1;i<5100;i++)fact[i]=fact[i-1]*i%mod;
	C[0][0]=1;
	for(int i=0;i<5050;i++){
		for(int j=0;j<=i;j++){
			C[i+1][j]=(C[i+1][j]+C[i][j])%mod;
			C[i+1][j+1]=(C[i+1][j+1]+C[i][j])%mod;
		}
	}
	int a;scanf("%d",&a);
	N=a;
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	dfs(0,-1);
	printf("%lld\n",ret);
}
```