#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

int dfs(vector<vector<int>> &t, vector<vector<int>> &is_parent, vector<int> &sub_size, int v, int parent){
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i] == parent){
			is_parent[v][i] = 1;
		}
		else{
			sub_size[v] += dfs(t, is_parent, sub_size, t[v][i], v);
		}
	}
	return sub_size[v];
}

signed main(){
	int N, x, y, i, j, k;
	scanf("%lld", &N);
	vector<vector<int>> t(N, vector<int>(0)), is_parent(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%lld%lld", &x, &y);
		x--;
		y--;
		t[x].push_back(y);
		t[y].push_back(x);
		is_parent[x].push_back(0);
		is_parent[y].push_back(0);
	}
	vector<int> sub_size(N, 1), rest_max(N, 0);
	int res = dfs(t, is_parent, sub_size, 0, -1);
/*	printf("sub_size:\n");
	for(i = 0; i < N; i++){
		printf("%lld ", sub_size[i]);
	}
	printf("\n");
*/	int cog, cnt = 0;
	for(i = 0; i < N; i++){
		rest_max[i] = N - sub_size[i];
		for(j = 0; j < t[i].size(); j++){
			if(is_parent[i][j] == 0){
				rest_max[i] = max(rest_max[i], sub_size[t[i][j]]);
			}
		}
//		printf("rest_max[%lld] = %lld\n", i, rest_max[i]);
		if(rest_max[i] <= N / 2){
			cog = i;
			cnt++;
		}
	}
//	printf("(cog, cnt) = (%lld, %lld)\n", cog, cnt);
	if(cnt == 2){
		printf("%lld\n", MOD(fact(N / 2) * fact(N / 2)));
		return 0;
	}
	vector<int> a(1);
	if(cog != 0){
		a.push_back(N - sub_size[cog]);
	}
	for(j = 0; j < t[cog].size(); j++){
		if(is_parent[cog][j] == 0){
			a.push_back(sub_size[t[cog][j]]);
		}
	}
/*	printf("a:\n");
	for(i = 0; i < a.size(); i++){
		printf("%lld ", a[i]);
	}
	printf("\n");
*/	vector<vector<int>> dp(a.size(), vector<int>(N + 1, 0));
	dp[0][0] = 1;
	for(i = 1; i < a.size(); i++){
		for(j = 0; j <= N; j++){
			for(k = 0; k <= a[i] && k <= j; k++){
				dp[i][j] = MOD(dp[i][j] + MOD(MOD(combination(a[i], k) * combination(a[i], k)) * fact(k)) * dp[i - 1][j - k]);
			}
		}
	}
/*	for(i = 0; i < a.size(); i++){
		printf("dp[%lld]:", i);
		for(j = 0; j <= N; j++){
			printf("%lld ", dp[i][j]);
		}
		printf("\n");
	}
*/	int ans = 0;
	for(j = 0; j <= N; j++){
		ans = MOD(ans + (j % 2 == 0 ? 1 : -1) * fact(N - j) * dp[a.size() - 1][j]);
	}
	printf("%lld\n", ans);
	return 0;
}
### Prompt

Create a solution in CPP for 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 <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

int dfs(vector<vector<int>> &t, vector<vector<int>> &is_parent, vector<int> &sub_size, int v, int parent){
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i] == parent){
			is_parent[v][i] = 1;
		}
		else{
			sub_size[v] += dfs(t, is_parent, sub_size, t[v][i], v);
		}
	}
	return sub_size[v];
}

signed main(){
	int N, x, y, i, j, k;
	scanf("%lld", &N);
	vector<vector<int>> t(N, vector<int>(0)), is_parent(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%lld%lld", &x, &y);
		x--;
		y--;
		t[x].push_back(y);
		t[y].push_back(x);
		is_parent[x].push_back(0);
		is_parent[y].push_back(0);
	}
	vector<int> sub_size(N, 1), rest_max(N, 0);
	int res = dfs(t, is_parent, sub_size, 0, -1);
/*	printf("sub_size:\n");
	for(i = 0; i < N; i++){
		printf("%lld ", sub_size[i]);
	}
	printf("\n");
*/	int cog, cnt = 0;
	for(i = 0; i < N; i++){
		rest_max[i] = N - sub_size[i];
		for(j = 0; j < t[i].size(); j++){
			if(is_parent[i][j] == 0){
				rest_max[i] = max(rest_max[i], sub_size[t[i][j]]);
			}
		}
//		printf("rest_max[%lld] = %lld\n", i, rest_max[i]);
		if(rest_max[i] <= N / 2){
			cog = i;
			cnt++;
		}
	}
//	printf("(cog, cnt) = (%lld, %lld)\n", cog, cnt);
	if(cnt == 2){
		printf("%lld\n", MOD(fact(N / 2) * fact(N / 2)));
		return 0;
	}
	vector<int> a(1);
	if(cog != 0){
		a.push_back(N - sub_size[cog]);
	}
	for(j = 0; j < t[cog].size(); j++){
		if(is_parent[cog][j] == 0){
			a.push_back(sub_size[t[cog][j]]);
		}
	}
/*	printf("a:\n");
	for(i = 0; i < a.size(); i++){
		printf("%lld ", a[i]);
	}
	printf("\n");
*/	vector<vector<int>> dp(a.size(), vector<int>(N + 1, 0));
	dp[0][0] = 1;
	for(i = 1; i < a.size(); i++){
		for(j = 0; j <= N; j++){
			for(k = 0; k <= a[i] && k <= j; k++){
				dp[i][j] = MOD(dp[i][j] + MOD(MOD(combination(a[i], k) * combination(a[i], k)) * fact(k)) * dp[i - 1][j - k]);
			}
		}
	}
/*	for(i = 0; i < a.size(); i++){
		printf("dp[%lld]:", i);
		for(j = 0; j <= N; j++){
			printf("%lld ", dp[i][j]);
		}
		printf("\n");
	}
*/	int ans = 0;
	for(j = 0; j <= N; j++){
		ans = MOD(ans + (j % 2 == 0 ? 1 : -1) * fact(N - j) * dp[a.size() - 1][j]);
	}
	printf("%lld\n", ans);
	return 0;
}
```